Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5
fix(mcp): annotate tools with readOnlyHint so reads aren't treated as edit tools#280
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
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,99 @@ | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
| import { createTerminal49McpServer } from './server.js'; | ||
| vi.mock('@sentry/node', () => ({ | ||
| captureException: vi.fn(), | ||
| flush: vi.fn().mockResolvedValue(true), | ||
| isInitialized: vi.fn(() => false), | ||
| wrapMcpServerWithSentry: vi.fn((server) => server), | ||
| })); | ||
| type ToolAnnotations = { | ||
| readOnlyHint?: boolean; | ||
| destructiveHint?: boolean; | ||
| idempotentHint?: boolean; | ||
| openWorldHint?: boolean; | ||
| }; | ||
| function getRegisteredTools(): Record< | ||
| string, | ||
| { annotations?: ToolAnnotations } | ||
| > { | ||
| const server = createTerminal49McpServer('token'); | ||
| return (server as any)._registeredTools as Record< | ||
| string, | ||
| { annotations?: ToolAnnotations } | ||
| >; | ||
| } | ||
| describe('MCP tool annotations', () => { | ||
| const readOnlyTools = [ | ||
| 'search_container', | ||
| 'get_container', | ||
| 'get_container_route', | ||
| 'get_container_transport_events', | ||
| 'get_shipment_details', | ||
| 'get_supported_shipping_lines', | ||
| 'list_containers', | ||
| 'list_shipments', | ||
| 'list_tracking_requests', | ||
| ]; | ||
| // get_supported_shipping_lines is a closed-world catalog; the other read | ||
| // tools query live shipment data and should be open-world. | ||
| const closedWorldReadTools = ['get_supported_shipping_lines']; | ||
| it('marks the nine read tools as read-only', () => { | ||
| const tools = getRegisteredTools(); | ||
| for (const name of readOnlyTools) { | ||
| const annotations = tools[name]?.annotations; | ||
| expect(annotations, name).toBeDefined(); | ||
| expect(annotations?.readOnlyHint, name).toBe(true); | ||
| if (!closedWorldReadTools.includes(name)) { | ||
| expect(annotations?.openWorldHint, name).toBe(true); | ||
| } | ||
| } | ||
| }); | ||
dodeja marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| it('marks track_container as a non-destructive non-idempotent write', () => { | ||
| const tools = getRegisteredTools(); | ||
| const annotations = tools.track_container?.annotations; | ||
| expect(annotations).toBeDefined(); | ||
| expect(annotations?.readOnlyHint).toBe(false); | ||
| expect(annotations?.destructiveHint).toBe(false); | ||
| expect(annotations?.idempotentHint).toBe(false); | ||
| expect(annotations?.openWorldHint).toBe(true); | ||
| }); | ||
| it('marks get_supported_shipping_lines as a closed-world catalog', () => { | ||
| const tools = getRegisteredTools(); | ||
| const annotations = tools.get_supported_shipping_lines?.annotations; | ||
| expect(annotations).toBeDefined(); | ||
| expect(annotations?.readOnlyHint).toBe(true); | ||
| expect(annotations?.openWorldHint).toBe(false); | ||
| }); | ||
| it('annotates every registered tool', () => { | ||
| const tools = getRegisteredTools(); | ||
| // Guard against the SDK renaming/restructuring `_registeredTools`: if the | ||
| // map ever resolves to undefined or empty, the per-tool loop below would | ||
| // pass vacuously. Assert it actually contains the tools we expect first. | ||
| expect( | ||
| tools, | ||
| '_registeredTools is empty - SDK internals may have changed', | ||
| ).toBeTruthy(); | ||
| expect( | ||
| Object.keys(tools).length, | ||
| '_registeredTools is empty - SDK internals may have changed', | ||
| ).toBeGreaterThanOrEqual(readOnlyTools.length + 1); | ||
| for (const [name, tool] of Object.entries(tools)) { | ||
| expect(tool.annotations, name).toBeDefined(); | ||
| } | ||
| }); | ||
| }); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.