Title: Client auto-resolves InputRequiredResult via existing callbacks (SEP-2322) by maxisbey · Pull Request #2998 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Client auto-resolves InputRequiredResult via existing callbacks (SEP-2322) by maxisbey · Pull Request #2998 · modelcontextprotocol/python-sdk
X Title: Client auto-resolves InputRequiredResult via existing callbacks (SEP-2322) by maxisbey · Pull Request #2998 · modelcontextprotocol/python-sdk
Description: Client.call_tool / get_prompt / read_resource now resolve InputRequiredResult automatically: each entry in input_requests is dispatched to the same sampling_callback / elicitation_callback / list_roots_callback that already serve legacy server-to-client RPCs, the responses are collected, and the call is retried with input_responses + the echoed request_state until a terminal result arrives. allow_input_required is removed from Client; for manual control (inspecting rounds, persisting request_state across processes) use client.session.call_tool(..., allow_input_required=True) which still returns the raw union.
Motivation and Context
Client half of SEP-2322 / #2898. The server side and the manual ClientSession surface landed in #2974; this adds the policy-layer driver so a high-level Client user never sees InputRequiredResult directly.
Shape
client/_input_required.py (new): pure, method-agnostic driver. run_input_required_driver(first, *, dispatch, retry, max_rounds) loops until non-IIR. Concurrent dispatch via anyio.create_task_group(). State-only legs (server returned request_state with no input_requests) back off exponentially: 50ms doubling to a 250ms cap, counter reset by any leg with input requests. request_state is a byte-exact str | None pass-through, never inspected. max_rounds default 10 (matches typescript-sdk; csharp/go use the same constant). InputRequiredRoundsExceededError on cap; MCPError when a callback returns ErrorData.
ClientSession._dispatch_input_request: extracted from the existing _on_request match-case so the legacy RPC path and the driver share one dispatch table. ClientRequestContext.request_id carries the input_requests key (a str, fits the existing RequestId = str | int).
ClientSession.get_prompt / read_resource: gain the same input_responses / request_state / allow_input_required overload set that call_tool already has, with union TypeAdapters alongside _CallToolResultAdapter.
Client: input_required_max_rounds: int = 10 dataclass field; shared _drive_input_required helper; call_tool / get_prompt / read_resource collapse to one signature returning the bare result type.
Also: examples/stories/mrtr/ promoted from deferred stub; docs/advanced/multi-round-trip.md + docs_src/mrtr/tutorial003.py rewritten; conformance fixture sep-2322-client-request-state rewritten to drive the same five wire-shape checks via the auto-loop with a registered elicitation_callback.
How Has This Been Tested?
9 driver unit tests in tests/client/test_input_required.py (single/multi-round, max-rounds cap, ErrorData raises, byte-exact request_state, backoff sequence, concurrent dispatch with event-gate, state-only counter reset).
7 integration tests in tests/client/test_client.py against in-memory MCPServer (all three callback types, multi-round with evolving state, no-callback-registered raises, get_prompt/read_resource happy path).
tests/client/test_session.py covers the widened get_prompt/read_resource.
tests/docs_src/test_mrtr.py exercises the new tutorial.
Conformance sep-2322-client-request-state (CI).
Breaking Changes
Alpha-only API removal: Client.call_tool / get_prompt / read_resource no longer accept allow_input_required. Use client.session.
Open Graph Description: Client.call_tool / get_prompt / read_resource now resolve InputRequiredResult automatically: each entry in input_requests is dispatched to the same sampling_callback / elicitation_callback / list_r...
X Description: Client.call_tool / get_prompt / read_resource now resolve InputRequiredResult automatically: each entry in input_requests is dispatched to the same sampling_callback / elicitation_callback / list_r...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/2998
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:8523bb2a-0fd5-7c79-0068-a6d84ad4fffd |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D314:3EE07D:A9ABD5:E413A7:6A5A85BE |
| html-safe-nonce | 5650a03660e64390166fcf28acfc3e5f046b950be9a05b7b25073c8bedf78710 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMzE0OjNFRTA3RDpBOUFCRDU6RTQxM0E3OjZBNUE4NUJFIiwidmlzaXRvcl9pZCI6IjI5ODMwNzcyNjgxNjIyNTAxNzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 6f42b5817ade41366c02d353b8c335a34e743b2a855750d207815a0489e6c510 |
| hovercard-subject-tag | pull_request:3942802776 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/modelcontextprotocol/python-sdk/pull/2998/files |
| twitter:image | https://avatars.githubusercontent.com/u/224885523?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/224885523?s=400&v=4 |
| og:image:alt | Client.call_tool / get_prompt / read_resource now resolve InputRequiredResult automatically: each entry in input_requests is dispatched to the same sampling_callback / elicitation_callback / list_r... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 922bdba685ea48400234d557977f0e32d9adbae6f5125725b4f48cacc6801106 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7c8a44665d760d73ead7e85d8f88b299152aa681 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width