Skip to content

feat!: add MRTR behavior support (SEP-2322)#929

Open
DaleSeo wants to merge 2 commits into
sep-2322-mrtr-typesfrom
sep-2322-mrtr-behavior
Open

feat!: add MRTR behavior support (SEP-2322)#929
DaleSeo wants to merge 2 commits into
sep-2322-mrtr-typesfrom
sep-2322-mrtr-behavior

Conversation

@DaleSeo

@DaleSeo DaleSeo commented Jun 26, 2026

Copy link
Copy Markdown
Member

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 the input_required rounds through the already-registered sampling, elicitation, and roots handlers before retrying the original call. The *_once methods remain as a manual escape hatch for callers that want to drive the rounds themselves. Native InputRequiredResult emission is gated on a negotiated protocol version of 2026-07-28 or newer so older peers never receive a result shape they cannot understand.

It also adds an opt-in request-state feature (RequestStateCodec, HMAC-SHA256) to safely round-trip the untrusted requestState, plus a servers_mrtr example and MRTR usage docs.

How Has This Been Tested?

Add tests

Breaking Changes

Server handler return types for tools/call, prompts/get, and resources/read are widened to MRTR-aware response enums (CallToolResponse / GetPromptResponse / ReadResourceResponse) so a handler can return either a final result or an InputRequiredResult. The #[tool_handler] / #[prompt_handler] proc macros, routers, conformance server, and existing tests are updated accordingly.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@DaleSeo DaleSeo self-assigned this Jun 26, 2026
@github-actions github-actions Bot added T-test Testing related changes T-core Core library changes T-handler Handler implementation changes T-macros Macro changes T-model Model/data structure changes T-service Service layer changes labels Jun 26, 2026
@DaleSeo DaleSeo changed the title feat!: add MRTR behavior support feat!: add MRTR behavior support (SEP-2322) Jun 26, 2026
@DaleSeo DaleSeo linked an issue Jun 26, 2026 that may be closed by this pull request
6 tasks
@DaleSeo DaleSeo force-pushed the sep-2322-mrtr-types branch from 2b7c5cf to ceb6d1f Compare June 26, 2026 20:52
@DaleSeo DaleSeo force-pushed the sep-2322-mrtr-behavior branch from 5a219be to 82699fd Compare June 26, 2026 20:58
@DaleSeo DaleSeo marked this pull request as ready for review July 1, 2026 18:51
@DaleSeo DaleSeo requested a review from a team as a code owner July 1, 2026 18:51
@DaleSeo DaleSeo force-pushed the sep-2322-mrtr-types branch from ceb6d1f to 1fc8f7f Compare July 1, 2026 20:16
@DaleSeo DaleSeo force-pushed the sep-2322-mrtr-behavior branch from 82699fd to cc0a9a1 Compare July 1, 2026 20:24
request: CallToolRequestParams,
context: RequestContext<RoleServer>,
) -> impl Future<Output = Result<CallToolResult, McpError>> + MaybeSendFuture + '_ {
) -> impl Future<Output = Result<CallToolResponse, McpError>> + MaybeSendFuture + '_ {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on all these renames? Just wondering why the move from Result to Response

@DaleSeo DaleSeo Jul 1, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

@DaleSeo DaleSeo force-pushed the sep-2322-mrtr-behavior branch 3 times, most recently from 1e7084f to f1ea4e1 Compare July 2, 2026 01:48
DaleSeo added a commit that referenced this pull request Jul 2, 2026
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.
@DaleSeo DaleSeo force-pushed the sep-2322-mrtr-behavior branch from f1ea4e1 to b313f14 Compare July 2, 2026 02:16
@github-actions github-actions Bot added T-documentation Documentation improvements T-dependencies Dependencies related changes T-config Configuration file changes T-examples Example code changes labels Jul 2, 2026
DaleSeo added a commit that referenced this pull request Jul 2, 2026
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.
@DaleSeo DaleSeo force-pushed the sep-2322-mrtr-behavior branch from b313f14 to 309ce0b Compare July 2, 2026 13:09
@DaleSeo DaleSeo force-pushed the sep-2322-mrtr-types branch from 5f57322 to 4c5b319 Compare July 2, 2026 13:22
@DaleSeo DaleSeo force-pushed the sep-2322-mrtr-behavior branch from 309ce0b to c698ab2 Compare July 2, 2026 13:23
@alexhancock alexhancock self-requested a review July 3, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2026-07-28 T-config Configuration file changes T-core Core library changes T-dependencies Dependencies related changes T-documentation Documentation improvements T-examples Example code changes T-handler Handler implementation changes T-macros Macro changes T-model Model/data structure changes T-service Service layer changes T-test Testing related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement SEP-2322: Multi Round-Trip Requests

2 participants