Skip to content

Commit 89b3ebb

Browse files
authored
fix(mcp): support MCP SDK v2 handler signature and removed request_ctx (#6583)
MCP SDK v2 changed handler signatures from (name, arguments) to (ctx, params) and removed the request_ctx ContextVar. Add version detection to patch the correct entry-points (Server.__init__ and add_request_handler for v2, decorator methods for v1), extract request context from the ServerRequestContext argument directly, and update tests to work with both SDK versions. Migration notes for MCP SDK v2 can be found here: - https://github.com/modelcontextprotocol/python-sdk/releases/tag/v2.0.0a1 - https://github.com/modelcontextprotocol/python-sdk/blob/main/docs/migration.md What this PR does not do: - address all breaking changes outlined in the migration guide. This is meant to fix the test failures on #6567 while still being comprehensive enough to make sense for the next developer who continues the migration. This was tested on the branch in #6567 to confirm it doesn't introduce regressions while addressing the v2 breaking change. Fixes PY-2532 Fixes #6574
1 parent 7882ff8 commit 89b3ebb

3 files changed

Lines changed: 1035 additions & 227 deletions

File tree

0 commit comments

Comments
 (0)