Migrate to the mcp 2.0 server API (closes #20) - #21
Open
linsamtw wants to merge 1 commit into
Open
Conversation
mcp 2.0 replaced the 1.x `@app.list_tools()` decorators with constructor kwargs (`on_list_tools=`, `on_call_tool=`, ...), where handlers take (ctx, params) and return full result models. It also renamed every type field to snake_case, keeping camelCase as the JSON wire alias — so `inputSchema`/`isError`/`mimeType` become `input_schema`/`is_error`/ `mime_type` in Python while the on-the-wire JSON is unchanged. One behaviour needed restoring by hand: mcp 1.x wrapped call_tool handlers and turned exceptions into CallToolResult(isError=True), which the model sees and can act on. mcp 2.0 lets them escape and become JSON-RPC protocol errors, which hosts report as a server failure. on_call_tool now catches and reports isError itself; tests/test_server.py guards it. Drops the mcp<2.0.0 ceiling added in 0.0.6 (#18). Python floor stays 3.10 — mcp 2.0 requires >=3.10 too. Closes #20 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Ports
server.pyoff the mcp 1.x decorator API and drops themcp<2.0.0ceiling that 0.0.6 added as a stopgap (#18 / #16).mcp>=2.0.0from here.Everything below was verified against a real
mcp==2.0.0install, not from memory.What mcp 2.0 actually changed
Serverstill exists;@app.list_tools()is replaced byServer("finmind", on_list_tools=..., on_call_tool=..., on_list_resources=..., on_read_resource=...). Handlers take(ctx, params)and return full result models (ListToolsResult,CallToolResult, …) instead of bare lists.inputSchema→input_schema,isError→is_error,mimeType→mime_type. This reachestools.pyandknowledge.py, not justserver.py. The wire format is unchanged — verified below.The one behaviour that needed restoring by hand
call_toolhandlerCallToolResult(isError=true)— the model sees the message and can retryerror— the host reports a server failuretools.dispatchraises only on an unknown tool name (everything else is already rendered as a 繁中 message), so the blast radius is narrow — but a purely mechanical port would have silently downgraded that path.on_call_toolnow catches and returnsis_error=Trueitself, andtests/test_server.pyhas a test whose only job is to keep it that way.Verification
Unit tests —
tests/test_server.pyis new;server.pypreviously had zero unit coverage, and the handlers are now plain async functions that need no subprocess:End-to-end over real stdio JSON-RPC, checking the raw frames rather than the SDK's own view:
mcp 2.0 accepts handshakes from
2024-11-05through the new2026-07-28, so existing Claude Desktop / Cursor / Gemini CLI configs keep working.Not done here
smoke.pyandregression/runner.pyneeded no changes — they speak raw JSON-RPC and are version-agnostic. Worth one manual run in a real host before tagging.Release: the dependency floor crosses a major version, so
0.1.0reads better than0.0.7— tag is yours to push.🤖 Generated with Claude Code