Skip to content

Support mcp 2.x - #43

Merged
ChrisPC-39 merged 3 commits into
IBM:mainfrom
Azelis:feat/mcp-2-support
Oct 20, 2026
Merged

ChrisPC-39 merged 3 commits into
IBM:mainfrom
Azelis:feat/mcp-2-support

Conversation

@Azelis

@Azelis Azelis commented Oct 15, 2026

Copy link
Copy Markdown

The runtime fails to start on mcp 2.x ('Server' object has no attribute 'list_tools') because mcp 2 removed the low-level decorator API. This PR moves the server to mcp 2 (>=2.3.0,<3); mcp 1.x is no longer supported as a dependency. mcp 1.x clients keep working as before.

Changes

  • Handlers are now passed to Server(on_list_tools=..., on_call_tool=..., ...) instead of registered with decorators. The request context and progress token come from the handler's ctx.
  • Kept from mcp 1.x:
    • Tool arguments are validated against the tool's input schema (Input validation error: ...); mcp 2's low-level server no longer does this.
    • A tool schema that can't be used returns an error result, not a protocol error.
    • resources/read keeps its error messages on every protocol version.
  • tools/list skips and logs a tool whose schema the client's protocol rejects, instead of failing the whole list.
  • SSE: request headers and user are taken from each POST, because mcp 2 runs handlers in the POST's context.
  • Progress: on protocol 2026-07-28, progress is sent with the response. Older protocol versions are unchanged.
  • New config options: max_request_body_size (sse, streamable-http), plus session_idle_timeout and max_sessions (streamable-http). They default to None, which keeps mcp 1.x behaviour instead of mcp 2's limits (4 MiB, 30 min, 10,000 sessions). The README documents them.
  • openai_compatibility: an object schema with no properties now gets "properties": {}, and a bare property map no longer treats required as a property.
  • serverInfo.version now reports the runtime's version.
  • Updated for mcp 2's snake_case type attributes (input_schema, mime_type); jsonschema is now a declared dependency.

Testing

  • Existing tests are updated for the new handler API.
  • New tests run the real mcp server and client on both protocol generations. 250 tests pass on Python 3.11–3.13.
  • Tested manually over stdio, SSE and streamable HTTP with mcp 1.28.1 and 2.3.0 clients, and behind Context Forge 1.0.5, 1.0.10 and 1.0.11. Tools, validation, errors, resources, artifacts, bearer auth and progress behave the same as on main, except for the progress limitation below.

Notes for servers built on the runtime

  • This is a breaking change: servers that pin mcp<2 must lift the pin, code that reads camelCase attributes on mcp.types objects needs the snake_case names, and get_request_context().meta is now a dict.
  • With stateless: false and json_response: true, clients on protocol 2026-07-28 get no progress notifications, because a JSON response can't carry them. Use json_response: false if that matters.

Justinas Aželis and others added 2 commits October 15, 2026 09:55
The runtime declares mcp>=1.26.0 but fails to start on mcp 2.x
("'Server' object has no attribute 'list_tools'"), because mcp 2 replaced
the low-level decorator API. This ports the server to mcp 2 (>=2.3.0,<3)
and keeps the mcp 1.x behaviour where mcp 2 changed it.

Handlers
- Passed to Server(on_list_tools=..., on_call_tool=..., on_list_resources=...,
  on_read_resource=...); the request context comes from the handler's ctx
  (progress token: ctx.meta["progress_token"])
- Tool arguments are validated against the listed schema as before; a schema
  that cannot be used is an error result, not a protocol error
- tools/list leaves out (and logs) a tool whose schema the negotiated
  protocol rejects, instead of failing the whole list
- resources/read errors keep their message on every protocol version
- serverInfo.version is the runtime's version

Transports
- SSE: each POST sets its own request headers and user for the tool call
  (mcp 2 runs the handler in the POST's context; mcp 1 used the GET stream's)
- Progress on protocol 2026-07-28 is sent with the request's response
  (report_progress); earlier protocol versions are unchanged
- New config: max_request_body_size (sse, streamable-http), plus
  session_idle_timeout and max_sessions (streamable-http). The defaults (None)
  keep mcp 1.x behaviour instead of mcp 2's 4 MiB / 30 min / 10,000.

Other
- openai_compatibility: an object schema without properties gets
  "properties": {}, and a bare property map no longer lists "required" as a
  property
- mcp 2 types use snake_case attributes (input_schema, mime_type) and plain
  string resource URIs
- Tests: FakeServer captures the on_* handlers; new tests run the real mcp
  Server with the mcp client on both protocol generations
- README: the new options in the Configuration Reference

Verified stdio, SSE and streamable HTTP (stateless and stateful, JSON and SSE
responses) with mcp 1.28.1 and mcp 2.3.0 clients: tools, validation, errors,
resources, artifacts, bearer auth and progress behave as on main with mcp 1.28.1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Justinas Aželis <Justinas.Azelis@ibm.com>
Review follow-up:
- max_request_body_size now defaults to 50 MiB (sse, streamable-http),
  enough for tool arguments that carry base64 files or images. An explicit
  null still disables the limit. mcp 2's own default is 4 MiB.
- README: "What's New in v0.12.0" with upgrade notes for servers built on
  the runtime (mcp pin, httpx no longer installed by mcp, McpError ->
  MCPError, snake_case type attributes, request context meta) and the
  transport limit defaults, including that mcp 2's 30 min / 10,000 session
  defaults are not used
- Version 0.12.0, since this release requires mcp 2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Justinas Aželis <Justinas.Azelis@ibm.com>
@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

Release the mcp 2.x migration as an alpha first (tag v0.12.0-alpha).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Justinas Aželis <Justinas.Azelis@ibm.com>
@ChrisPC-39
ChrisPC-39 merged commit 20a1327 into IBM:main Oct 20, 2026
12 checks passed
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