feat!: add MRTR behavior support (SEP-2322)#929
Conversation
2b7c5cf to
ceb6d1f
Compare
5a219be to
82699fd
Compare
ceb6d1f to
1fc8f7f
Compare
82699fd to
cc0a9a1
Compare
| request: CallToolRequestParams, | ||
| context: RequestContext<RoleServer>, | ||
| ) -> impl Future<Output = Result<CallToolResult, McpError>> + MaybeSendFuture + '_ { | ||
| ) -> impl Future<Output = Result<CallToolResponse, McpError>> + MaybeSendFuture + '_ { |
There was a problem hiding this comment.
Thoughts on all these renames? Just wondering why the move from Result to Response
There was a problem hiding this comment.
@alexhancock Not a rename. CallToolResult, GetPromptResult, ReadResourceResult are unchanged. CallToolResponse is a new outcome enum mirroring what the spec's draft schema reference already models. Each method's response result is a union InputRequiredResult | CallToolResult. Rust has no anonymous unions, so I introduced one named enum per method to express that union at the handler return type.
Existing handlers don't need to change because the IntoCallToolResult conversions still accept a plain CallToolResult, Json<T>, Content, Result<T, E>, etc., and there are From<CallToolResult> / From<InputRequiredResult> impls, so .into() covers both arms. Only the trait-level return type widened.
1e7084f to
f1ea4e1
Compare
Add a request-state integrity codec, expand MRTR edge-case coverage, and document the end-to-end flow on top of the behavior support in #929. - Add opt-in `request-state` feature with `RequestStateCodec`, an HMAC-SHA256 seal/open helper for the untrusted `requestState` echoed by clients. Servers can still build the string by hand via `InputRequiredResult::from_request_state`. - Expand `test_mrtr_behavior` to cover multi-round, multiple concurrent input requests, state-only backoff, max-rounds, handler errors, byte-exact requestState echo, prompts/get and resources/read, and pre-2026 version gating. - Add the `servers_mrtr` example and MRTR usage docs.
f1ea4e1 to
b313f14
Compare
Add a request-state integrity codec, expand MRTR edge-case coverage, and document the end-to-end flow on top of the behavior support in #929. - Add opt-in `request-state` feature with `RequestStateCodec`, an HMAC-SHA256 seal/open helper for the untrusted `requestState` echoed by clients. Servers can still build the string by hand via `InputRequiredResult::from_request_state`. - Expand `test_mrtr_behavior` to cover multi-round, multiple concurrent input requests, state-only backoff, max-rounds, handler errors, byte-exact requestState echo, prompts/get and resources/read, and pre-2026 version gating. - Add the `servers_mrtr` example and MRTR usage docs.
b313f14 to
309ce0b
Compare
5f57322 to
4c5b319
Compare
309ce0b to
c698ab2
Compare
Motivation and Context
On top of PR #915 that adds model types for SEP-2322, this PR wires up the behavior so servers can request input and clients can satisfy it without changing their call sites. Server tool/prompt/resource handlers can now return an
InputRequiredResult, and the high-level client automatically fulfills theinput_requiredrounds through the already-registered sampling, elicitation, and roots handlers before retrying the original call. The*_oncemethods remain as a manual escape hatch for callers that want to drive the rounds themselves. NativeInputRequiredResultemission is gated on a negotiated protocol version of2026-07-28or newer so older peers never receive a result shape they cannot understand.It also adds an opt-in
request-statefeature (RequestStateCodec, HMAC-SHA256) to safely round-trip the untrustedrequestState, plus aservers_mrtrexample and MRTR usage docs.How Has This Been Tested?
Add tests
Breaking Changes
Server handler return types for
tools/call,prompts/get, andresources/readare widened to MRTR-aware response enums (CallToolResponse/GetPromptResponse/ReadResourceResponse) so a handler can return either a final result or anInputRequiredResult. The#[tool_handler]/#[prompt_handler]proc macros, routers, conformance server, and existing tests are updated accordingly.Types of changes
Checklist
Additional context