Repository navigation
fix(mcp): get_more_tools follows the conversation handle like any tool #391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lucasheriques
wants to merge
3
commits into
lucas/mcp-person-identity
from
lucas/mcp-virtual-tool-handle
+130
−44
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "posthog-ruby": minor | ||
| --- | ||
|
|
||
| `PostHog::MCP`'s `get_more_tools` virtual tool now follows the conversation handle like any tool: it advertises `conversation_id`, files a report under a handle the agent echoes, and mints and returns one when nothing else groups the call. `$mcp_missing_capability` no longer carries `$mcp_parameters`; the report is already its `$mcp_intent`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative 'spec_helper' | ||
|
|
||
| RSpec.describe 'PostHog::MCP get_more_tools sessions' do | ||
| let(:client) { new_test_client } | ||
| let(:server) { MCP::Server.new(name: 'docs-server', version: '1.0.0', tools: []) } | ||
| let(:handle) { '0190f0e8-7a6b-7c3d-9e4f-5a6b7c8d9e0f' } | ||
|
|
||
| before { allow(Kernel).to receive(:warn) } | ||
|
|
||
| def report(arguments) | ||
| server.handle(rpc(2, 'tools/call', | ||
| { name: 'get_more_tools', arguments: { context: 'need csv export' }.merge(arguments) })) | ||
| end | ||
|
|
||
| def listed_arguments | ||
| server.handle(rpc(1, 'tools/list'))[:result][:tools].find do |tool| | ||
| tool[:name] == 'get_more_tools' | ||
| end[:inputSchema][:properties].keys | ||
| end | ||
|
|
||
| def missing_capability | ||
| events_named(drain_events(client), '$mcp_missing_capability').first[:properties] | ||
| end | ||
|
|
||
| { | ||
| 'on' => [true, true], | ||
| 'off' => [false, false] | ||
| }.each do |anchoring, (enabled, advertised)| | ||
| it "advertises conversation_id on get_more_tools with anchoring #{anchoring}" do | ||
| PostHog::MCP.instrument(server, client, report_missing: true, capture_model: false, | ||
| enable_conversation_id: enabled) | ||
|
|
||
| expect(listed_arguments.include?(:conversation_id)).to eq(advertised) | ||
| end | ||
| end | ||
|
|
||
| it 'mints a handle for a report that carries none, and files the report under it' do | ||
| PostHog::MCP.instrument(server, client, report_missing: true) | ||
| texts = report({})[:result][:content].map { |block| block[:text] } | ||
|
|
||
| minted = JSON.parse(texts.last)['conversation_id'] | ||
| expect(minted).to match(/\A\h{8}-\h{4}-7\h{3}-/) | ||
| expect(missing_capability.values_at('$mcp_conversation_id', '$session_id', '$mcp_session_source')) | ||
| .to eq([minted, PostHog::MCP.derive_session_id_from_conversation(minted), 'conversation']) | ||
| end | ||
|
|
||
| it 'sends the report without $mcp_parameters' do | ||
| PostHog::MCP.instrument(server, client, report_missing: true) | ||
| report({ conversation_id: handle }) | ||
|
|
||
| expect(missing_capability).not_to have_key('$mcp_parameters') | ||
| end | ||
|
|
||
| it 'files a report under the handle the agent echoes, and mints none' do | ||
| PostHog::MCP.instrument(server, client, report_missing: true) | ||
| texts = report({ conversation_id: handle })[:result][:content].map { |block| block[:text] } | ||
|
|
||
| expect(texts.size).to eq(1) | ||
| expect(missing_capability.values_at('$mcp_conversation_id', '$session_id')) | ||
| .to eq([handle, PostHog::MCP.derive_session_id_from_conversation(handle)]) | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.