lowlevel Server: widen on_* return types for InputRequiredResult; add subscriptions/listen slot

Merged
MA
5mo ago
+29-6

Type-only changes to the lowlevel Server constructor for the 2026-07-28 protocol revision.

Changes

Return-type widening — three on_* handlers can now return InputRequiredResult in addition to their concrete result type, matching MONOLITH_RESULTS in src/mcp/types/methods.py:

  • on_call_tool → CallToolResult | InputRequiredResult
  • on_get_prompt → GetPromptResult | InputRequiredResult
  • on_read_resource → ReadResourceResult | InputRequiredResult

These are the three methods whose request params extend InputResponseRequestParams. Widening is covariant, so existing handlers typed -> CallToolResult etc. still type-check unchanged.

New dispatch slot — on_subscriptions_listen kwarg + _spec_requests row, so subscriptions/listen (the one new-in-2026 client→server request method) reaches a registered handler instead of METHOD_NOT_FOUND.

InputRequiredResult validator — model_validator(mode="after") enforcing the spec's at-least-one-of input_requests / request_state requirement (matches the typescript-sdk and csharp-sdk behaviour).

Not in this PR

  • tasks/* — moved to the io.modelcontextprotocol/tasks extension; not core 2026-07-28.
  • on_discover override — server/discover stays the auto-derived built-in.
  • get_capabilities() — ServerCapabilities has no subscriptions field; nothing to set.

Part of #2891.

AI Disclaimer