Repository navigation
feat(mcp): declare all four behavior hints on every tool #3395
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f4a7a65
feat(mcp): declare all four behavior hints on every tool
brandon-pereira 508b762
test(mcp): avoid object-injection lint warning in annotations test
brandon-pereira 9143c9e
Merge branch 'main' into agent/mcp-tool-annotations
kodiakhq[bot] dc4bc54
Merge branch 'main' into agent/mcp-tool-annotations
kodiakhq[bot] 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 @@ | ||
| --- | ||
| '@hyperdx/api': patch | ||
| --- | ||
|
|
||
| feat(mcp): declare readOnlyHint, destructiveHint, idempotentHint, and openWorldHint on every MCP tool |
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,26 @@ | ||
| import { McpContext } from '@/mcp/tools/types'; | ||
|
|
||
| import { createTestClient } from './mcpTestUtils'; | ||
|
|
||
| describe('MCP tool annotations', () => { | ||
| const context: McpContext = { teamId: 'team-id', userId: 'user-id' }; | ||
|
|
||
| it('declares every behavior hint as a boolean on every tool', async () => { | ||
| const client = await createTestClient(context); | ||
| const { tools } = await client.listTools(); | ||
| expect(tools.length).toBeGreaterThan(0); | ||
|
|
||
| const missing = tools.flatMap(tool => | ||
| Object.entries({ | ||
| readOnlyHint: tool.annotations?.readOnlyHint, | ||
| destructiveHint: tool.annotations?.destructiveHint, | ||
| idempotentHint: tool.annotations?.idempotentHint, | ||
| openWorldHint: tool.annotations?.openWorldHint, | ||
| }) | ||
| .filter(([, value]) => typeof value !== 'boolean') | ||
| .map(([hint]) => `${tool.name}.annotations.${hint}`), | ||
| ); | ||
|
|
||
| expect(missing).toEqual([]); | ||
| }); | ||
| }); |
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,44 @@ | ||
| import type { ToolAnnotations } from '@modelcontextprotocol/sdk/types.js'; | ||
|
|
||
| /** | ||
| * The four behavior hints every tool must declare. Platform compatibility | ||
| * checks reject tools that leave any of them unset. | ||
| */ | ||
| export type ToolBehaviorAnnotations = Required< | ||
| Pick< | ||
| ToolAnnotations, | ||
| 'readOnlyHint' | 'destructiveHint' | 'idempotentHint' | 'openWorldHint' | ||
| > | ||
| >; | ||
|
|
||
| // Every tool reads or writes only the calling team's own ClickStack metadata | ||
| // (MongoDB) and telemetry (ClickHouse), so none of them is open-world. | ||
|
|
||
| export const READ_ONLY_TOOL: ToolBehaviorAnnotations = { | ||
| readOnlyHint: true, | ||
| destructiveHint: false, | ||
| idempotentHint: true, | ||
| openWorldHint: false, | ||
| }; | ||
|
|
||
| /** | ||
| * Create-or-update tools: omitting `id` creates a new object on every call | ||
| * (not idempotent), and providing `id` overwrites the stored object. | ||
| */ | ||
| export const UPSERT_TOOL: ToolBehaviorAnnotations = { | ||
| readOnlyHint: false, | ||
| destructiveHint: true, | ||
| idempotentHint: false, | ||
| openWorldHint: false, | ||
| }; | ||
|
|
||
| /** | ||
| * Updates or deletes an existing object by ID. Repeating the call with the | ||
| * same arguments leaves the same end state. | ||
| */ | ||
| export const IDEMPOTENT_DESTRUCTIVE_TOOL: ToolBehaviorAnnotations = { | ||
| readOnlyHint: false, | ||
| destructiveHint: true, | ||
| idempotentHint: true, | ||
| openWorldHint: false, | ||
| }; | ||
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OOC could we also add a preset for writes that aren't destructive?
Stuff like
add_investigation_noteonly appends, so it isn't destructive or idempotent, andshare_notebookis idempotent but not destructive. Without a matching preset, EE would either hand-write the objects or pickUPSERT_TOOL. Would something like this cover both?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, will handle this in EE for now