Commit Graph

142 Commits

Author SHA1 Message Date
Max Isbey c54fe3b36a feat(mrtr): linear continuation-based handler — Option H
The Option B footgun was: await elicit() looks like a suspension point but
is actually a re-entry point, so everything above it runs twice. Option H
fixes that by making it a REAL suspension point — the coroutine frame is
held in a ContinuationStore across MRTR rounds, keyed by request_state.

Handler code stays exactly as it was in the SSE era:

    async def my_tool(ctx: LinearCtx, location: str) -> str:
        audit_log(location)      # runs exactly once
        units = await ctx.elicit("Which units?", UnitsSchema)
        return f"{location}: 22°{units.u}"

The wrapper linear_mrtr(my_tool, store=...) translates this into a standard
MRTR on_call_tool handler. Round 1 starts the coroutine; elicit() sends
IncompleteResult back through the wrapper and parks on a stream. Round 2's
retry wakes it with the answer. The coroutine continues from where it
stopped — no re-entry, no double-execution.

Trade-off: server holds the frame in memory between rounds. Client sees
pure MRTR (no SSE, independent requests), but server is stateful within
a single tool call. Horizontally-scaled deployments need sticky routing on
the request_state token. Same operational shape as Option A's SSE hold,
without the long-lived connection.

SDK pieces (src/mcp/server/experimental/mrtr/linear.py):
- LinearCtx with async elicit(message, PydanticSchema) -> instance
- ContinuationStore — owns the task group, TTL-based frame expiry
- linear_mrtr(handler, store=...) — the wrapper
- ElicitDeclined raised when user declines/cancels

7 E2E tests including the key assertion: side-effects above await fire
exactly once (the test measures audit_log count).
2026-03-20 17:06:58 +00:00
Max Isbey 4facab7115 examples(mrtr): add basic and multi-round lowlevel reference examples
Two standalone reference examples before the comparison deck:

- basic.py: the simple-tool equivalent for MRTR. One IncompleteResult,
  one retry. Comments walk through the two moves every MRTR handler
  makes: check input_responses, return IncompleteResult if missing.
  Runnable end-to-end against the in-memory Client.

- basic_multiround.py: the ADO-rules SEP example translated. Two
  cascading elicitation rounds with request_state carrying accumulated
  context so any server instance can handle any round. Shows the key
  gotcha: input_responses carries only the latest round's answers, not
  accumulated — anything that must survive goes in request_state.
2026-03-20 16:19:18 +00:00
Max Isbey 29cb1ba837 examples(mrtr): handler-shape comparison deck (SEP-2322)
Python-SDK counterpart to typescript-sdk#1701. Seven ways to write the
same weather-lookup tool so the diff between files is the argument.

SDK primitives (src/mcp/server/experimental/mrtr.py):
- MrtrCtx.once() — idempotency guard tracked in request_state (Option F)
- ToolBuilder — structural step decomposition; end_step runs exactly once
  regardless of round count (Option G)
- input_response() — sugar for the guard-first pattern
- sse_retry_shim() — Option A comparison artifact (pragma no-cover until
  LATEST_PROTOCOL_VERSION bumps past the MRTR gate)
- dispatch_by_version() — Option D comparison artifact

Option examples (examples/servers/mrtr-options/):
- E (degrade-only): the SDK default. MRTR-native; pre-MRTR gets a default
  or error. Both quadrant rows collapse here.
- A (SSE shim): SDK emulates retry over SSE. Safe re-entry, hidden loop.
- B (await shim): exception-based. UNSAFE — hidden double-execution above
  await. Not a ship target; for contrast.
- C (version branch): explicit if/else in handler body.
- D (dual handler): two functions, SDK picks by version.
- F (ctx.once): idempotency guard, opt-in per side-effect.
- G (ToolBuilder): no above-the-guard zone; end_step structurally
  unreachable until all elicitations complete.

The invariant test (tests/experimental/test_mrtr.py) parametrises E/F/G
against the same Client + callback to prove identical wire behaviour —
the server's internal choice doesn't leak. The footgun test measures
audit_log count to prove F and G actually hold the guard (naive handler
fires twice; F and G fire once).

Both F and G depend on request_state integrity. The demos use plain
base64-JSON; a production SDK MUST HMAC-sign the blob.
2026-03-20 16:09:46 +00:00
Max Isbey abfb482246 refactor(examples): migrate all HTTP examples to streamable_http_app() (#2291) 2026-03-16 11:37:01 +00:00
Max Isbey 31a38b5078 fix: correct Context type parameters across examples and tests (#2256) 2026-03-09 16:52:56 +00:00
Max Isbey b9431d483f fix: prevent command injection in example URL opening (#2082) 2026-02-18 15:16:44 +00:00
Max Isbey 0a22a9dc33 refactor: replace lowlevel Server decorators with on_* constructor kwargs (#1985) 2026-02-12 15:55:54 +00:00
Max Isbey d3133ae6ce chore: update author metadata to LF Projects (#1992) 2026-02-04 11:01:33 +00:00
Marcelo Trylesinski 1a8c14a5b8 refactor: replace mcp.types as types to from mcp import types (#1986) 2026-02-03 16:42:29 +00:00
Marcelo Trylesinski 4fc49c62bd feat: add ClientRequestContext type alias for client-side handlers (#1989) 2026-02-03 17:37:38 +01:00
Marcelo Trylesinski b1f7eec3cd refactor: split RequestContext between server and client (#1987) 2026-02-03 14:35:07 +01:00
Marcelo Trylesinski 21822053df Support different transports in Client (#1972) 2026-01-30 12:11:27 +00:00
Max Isbey 1b5287c727 fix: remove unused requests dependency from simple-chatbot example (#1958) 2026-01-26 14:02:11 +00:00
Marcelo Trylesinski acba5478a9 refactor: McpError renamed to MCPError and flatten parameters (#1956)
Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
2026-01-26 14:37:44 +01:00
Marcelo Trylesinski 65c614e48e Rename FastMCP to MCPServer (#1951) 2026-01-25 14:45:52 +01:00
Marcelo Trylesinski f0ab53e194 Add meta to Client methods (#1923) 2026-01-22 14:50:39 +01:00
Marcelo Trylesinski 7b728a243e refactor: drop unused logger/logging (#1926) 2026-01-22 11:56:41 +01:00
Max Isbey 213cf993ca Add conformance testing CI pipeline (#1915) 2026-01-21 16:04:35 +00:00
Felix Weinberger d41d0c0128 chore: add D212 lint rule to enforce Google-style docstrings (#1892) 2026-01-16 16:10:52 +00:00
Felix Weinberger df039bf97c Add ergonomic Client class for testing MCP servers (#1870) 2026-01-16 15:49:26 +00:00
Marcelo Trylesinski 8adb5bdce8 refactor: move transport-specific parameters from FastMCP constructor to run() (#1898)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 15:16:20 +00:00
Marcelo Trylesinski e94b386a13 refactor: use snake case instead of camel case in types (#1894) 2026-01-16 15:51:27 +01:00
Marcelo Trylesinski 2ce41a8347 Drop dependencies parameter from FastMCP (#1877) 2026-01-16 08:59:44 +00:00
Felix Weinberger cfb2909631 fix: change Resource URI fields from AnyUrl to str (#1863) 2026-01-16 09:58:57 +01:00
Max Isbey 6b69f6354a docs: fix simple-auth README references to non-existent scripts (#1829) 2026-01-08 14:45:31 +00:00
Marcelo Trylesinski 1fd557afdc Add type checker to examples/client (#1837) 2026-01-07 17:08:18 +01:00
Marcelo Trylesinski adcc17b968 types: add missing py.typed from examples package (#1833) 2026-01-06 18:54:58 +00:00
Yugan 2aa1ad2a69 feat: standardize timeout values to floats in seconds (#1766) 2025-12-19 12:22:56 +00:00
Marcelo Trylesinski a3a4b8d11a Add streamable_http_client which accepts httpx.AsyncClient instead of httpx_client_factory (#1177)
Co-authored-by: Felix Weinberger <fweinberger@anthropic.com>
2025-12-10 16:39:00 +00:00
Tyler Mailman 72a34002aa fix: add lifespan context manager to StreamableHTTP mounting examples (#1669)
Co-authored-by: TheMailmans <tyler@example.com>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2025-12-03 22:08:21 +00:00
Felix Weinberger fa851d93a2 feat: backwards-compatible create_message overloads for SEP-1577 (#1713) 2025-12-02 13:17:45 +00:00
Paul Carleton f82b0c9371 Support client_credentials flow with JWT and Basic auth (#1663)
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
2025-12-02 12:53:55 +00:00
Felix Weinberger 281fd4765e Add SSE polling support (SEP-1699) (#1654) 2025-12-02 11:44:49 +00:00
Max Isbey c92bb2f7ff SEP-1686: Tasks (#1645) 2025-11-28 18:51:58 +00:00
Chris Coutinho 02b7889929 Implement SEP-1036: URL mode elicitation for secure out-of-band interactions (#1580)
Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
Co-authored-by: Felix Weinberger <fweinberger@anthropic.com>
2025-11-25 11:00:21 +00:00
Paul Carleton f22501315e feat: implement SEP-991 URL-based client ID (CIMD) support (#1652)
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
2025-11-24 17:21:03 +00:00
Paul Carleton 998f0ee4db [auth][conformance] add conformance auth client (#1640)
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
2025-11-24 13:52:04 +00:00
Tapan Chugh b19fa6f279 SEP-1330: Elicitation Enum Schema Improvements and Standards Compliance (#1246)
Co-authored-by: Tapan Chugh <tapanc@cs.washington.edu>
Co-authored-by: Felix Weinberger <fweinberger@anthropic.com>
Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
2025-11-23 23:32:08 +00:00
Olivier Chafik 71c475588f Implement SEP-1577 - Sampling With Tools (#1594)
Co-authored-by: Felix Weinberger <fweinberger@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com>
2025-11-22 23:58:14 -05:00
Jon Shea c51936f61f Add client_secret_basic authentication support (#1334)
Co-authored-by: Paul Carleton <paulc@anthropic.com>
2025-11-20 20:53:37 +00:00
adam jones fcffa14b5b docs: Update examples to use stateless HTTP with JSON responses (#1499)
Main branch checks / checks (push) Failing after 0s
2025-11-20 15:06:37 +00:00
Felix Weinberger be730674ad Add SEP-1034 conformance test support to everything-server (#1604)
Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
2025-11-11 17:44:23 +00:00
Max Isbey a864840825 Add end-of-file-fixer pre-commit hook (#1610) 2025-11-11 13:23:08 +00:00
Felix Weinberger da4fce2195 Add everything-server for comprehensive MCP conformance testing (#1587) 2025-11-09 13:45:37 +00:00
Paul Carleton 6f2cd0cef0 Fix auth client example URL handling for oauth provider (#1549)
Main branch checks / checks (push) Failing after 0s
2025-10-30 15:35:44 +00:00
Luca Chang f161149680 Implement RFC 7523 JWT flows (#1247)
Co-authored-by: Yann Jouanin <yann.jouanin@valueandco.com>
2025-10-29 16:48:08 +00:00
Yukuan Jia 673423da0d fix: replace deprecated dev-dependencies in examples/clients (#1518) 2025-10-28 14:09:14 +00:00
Yukuan Jia 340af403bd Replace deprecated dev-dependencies with dependency-groups (#1488)
Co-authored-by: Felix Weinberger <fweinberger@anthropic.com>
Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
2025-10-23 17:22:16 -07:00
Brandon Shar 1200ba0082 Allow CallToolResult to be returned directly to support _meta field for OpenAI Apps (#1459)
Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
2025-10-21 18:52:08 +00:00
Luca Chang c733eec5d9 Make client examples workspaces to reflect package code (#1466) 2025-10-17 17:13:39 +01:00