Skip to content

fix: annotate fetch as read-only and support MCP 2026-07-28 - #184

Merged
rdimitrov merged 1 commit into
mainfrom
fix/tool-annotations-spec-update
Nov 19, 2026
Merged

rdimitrov merged 1 commit into
mainfrom
fix/tool-annotations-spec-update

Conversation

@danbarr

@danbarr danbarr commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Summary

The fetch tool shipped without tool annotations, so MCP clients fell back to the spec defaults (readOnlyHint: false, destructiveHint: true) and showed it as a write tool. This PR annotates it correctly. It also brings the server up to date with MCP spec 2026-07-28, which it couldn't serve before.

Changes

  • Tool annotations: fetch now sets readOnlyHint, idempotentHint, and openWorldHint, plus a title.
  • Stateless Streamable HTTP: go-sdk v1.8.0 only serves protocol 2026-07-28 when the handler is stateless, so 2026-07-28 requests used to fail with UnsupportedProtocolVersion (-32022). Gofetch keeps no state between calls, so it now runs statelessly. Clients on 2025-11-25 and earlier still work; they just don't receive an Mcp-Session-Id, which those spec versions treat as optional. GET and DELETE on /mcp now return 405.
  • Parameter descriptions: FetchParams used mcp:"..." struct tags, which the SDK ignores, so clients never saw any parameter descriptions. They now use jsonschema:"...".
  • Input bounds: A negative start_index or max_length caused a slice-bounds panic in FormatContent. The schema now sets minimum values, so the SDK rejects bad input with a tool error, and the processor also clamps negative values.
  • SSE deprecation: The server logs a warning when started with --transport sse. The SDK doesn't serve 2026-07-28 over that transport.
  • Removed InitializedHandler: It never fires in stateless mode, and the endpoint it logged is already printed at startup.
  • Docs: USAGE.md now covers the 2026-07-28 request flow as well as earlier versions. README.md and CLAUDE.md had a max_length default of 5000 and max of 1,000,000 that the code never enforced; those are corrected.

Testing

  • New TestFetchToolDefinition checks the annotations and input schema returned by tools/list, using an in-memory client.
  • New TestFormatContentNegativeBounds.
  • task test and task lint pass.
  • Manually tested against a running server:
    • Streamable HTTP, 2026-07-28: server/discover, tools/list, and tools/call.
    • Streamable HTTP, 2025-11-25: initialize, tools/list, and tools/call.
    • SSE: tools/list.
  • Integration tests (task test-integration) have not been run locally.

Behavior change

Deployments or clients that rely on Mcp-Session-Id or on GET /mcp for streaming will notice the switch to stateless mode. Gofetch never sent server-initiated messages, so nothing is lost functionally.

🤖 Generated with Claude Code

The fetch tool had no annotations, so clients applied the spec
defaults (readOnlyHint=false, destructiveHint=true) and treated it as
a destructive write tool. Mark it read-only, idempotent, and
open-world, and give it a title.

Bring the server up to date with spec 2026-07-28:

- Run Streamable HTTP in stateless mode. The SDK only serves
  2026-07-28 to stateless handlers; before this, 2026-07-28 requests
  were rejected with UnsupportedProtocolVersion. Older clients still
  work without an Mcp-Session-Id.
- Switch FetchParams struct tags from `mcp` to `jsonschema`. The SDK
  ignores `mcp` tags, so parameter descriptions never reached
  clients.
- Add minimum bounds for max_length and start_index, and clamp
  negative values in FormatContent, which previously panicked on a
  negative slice index.
- Log a deprecation warning when starting with the SSE transport,
  which the SDK doesn't serve 2026-07-28 over.
- Drop the InitializedHandler, which never fires in stateless mode
  and only repeated the endpoint already logged at startup.

Update USAGE.md, README.md, and CLAUDE.md for the stateless flow and
correct the documented max_length default and maximum, which the
code never enforced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rdimitrov
rdimitrov merged commit a0e6a2a into main Nov 19, 2026
2 checks passed
@danbarr
danbarr deleted the fix/tool-annotations-spec-update branch November 19, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants