Commit Graph

83 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 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 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
Felix Weinberger d41d0c0128 chore: add D212 lint rule to enforce Google-style docstrings (#1892) 2026-01-16 16:10:52 +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
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 adcc17b968 types: add missing py.typed from examples package (#1833) 2026-01-06 18:54:58 +00:00
Felix Weinberger fa851d93a2 feat: backwards-compatible create_message overloads for SEP-1577 (#1713) 2025-12-02 13:17:45 +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
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
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
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 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
Rocky Haotian Du eb34ab7c72 fix: Remove unnecessary constructor from ResourceServerSettings (#1424)
Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
2025-10-14 09:21:15 +02:00
Felix Weinberger 7a933fe5da Fix workspace configuration error with structured_output_lowlevel.py (#1471)
Co-authored-by: lorenss-m <saeclmusic@gmail.com>
2025-10-13 15:53:46 +01:00
Marcus Shu df3e428ee8 Improve OAuth protected resource metadata URL construction per RFC 9728 (#1407) 2025-10-06 13:52:44 +01:00
Max Isbey c0f165776d Use streamable-http consistently in examples (#1389) 2025-09-23 20:19:14 +01:00
Max Isbey 4fb975c6dc feat: add paginated list decorators for prompts, resources, and tools (#1286)
Co-authored-by: Claude <noreply@anthropic.com>
2025-09-23 14:58:06 +01:00
Peter Alexander 356dfa692b Update simple-resource example to use non-deprecated read_resource return type (#1331)
Co-authored-by: Claude <noreply@anthropic.com>
2025-09-01 17:58:01 +01:00
Jerome 09e3a05e13 feat: Add CORS configuration for browser-based MCP clients (#1059)
Main branch checks / checks (push) Failing after 1s
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Co-authored-by: Felix Weinberger <fweinberger@anthropic.com>
2025-08-21 14:34:45 +01:00
David Soria Parra 0926613714 Update dependencies and fix type issues (#1268)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2025-08-14 10:40:47 +01:00
Marcelo Trylesinski c7671e470c Add pyright strict mode on the whole project (#1254) 2025-08-11 18:56:37 +01:00
Stanley Law 6d092af6fd chore: add markdownlint on pre-commit hook and lint md files (#996)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2025-07-10 09:43:49 +01:00
Inna Harper 4fee123e72 clean up log.error (#1109) 2025-07-09 11:15:14 +01:00
Marcelo Trylesinski 9301924f44 chore: bump ruff (#1085) 2025-07-04 09:01:17 +01:00
bhosmer-ant c8bbfc034d Add schema validation to lowlevel server (#1005) 2025-06-25 09:23:49 -04:00
Inna Harper ce007de66d Remove github from auth examples (#1011) 2025-06-24 15:43:08 +01:00
Inna Harper 679b22970e RFC 8707 Resource Indicators Implementation (#991) 2025-06-23 17:10:20 +01:00
Inna Harper 17f9c00c53 MCP server separation into Authorization Server (AS) and Resource Server (RS) roles per spec PR #338 (#982)
Co-authored-by: Paul Carleton <paulc@anthropic.com>
2025-06-23 14:19:03 +01:00
Inna Harper d0443a1832 Add resource Link (#974) 2025-06-17 20:23:07 +01:00
Felix Weinberger a2f8766a8a Add title to tools, resources, prompts (#972)
Co-authored-by: Claude <noreply@anthropic.com>
2025-06-17 15:53:14 +01:00
Luca Chang d69b290b65 chore: create union for working with message content (#939) 2025-06-12 09:01:33 +02:00
Marcelo Trylesinski 543961968c Use 120 characters instead of 88 (#856) 2025-06-11 11:45:50 +02:00
Nandha Reddy f7265f7b91 Use FileUrl on the resources/list call in the simple-resource example (#907) 2025-06-11 10:48:42 +02:00
dr3s 1a9ead07f5 relax validation (#879) 2025-06-09 19:21:01 +01:00
Luca Chang 7123556a34 feat: support audio content (#725)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2025-06-07 14:32:11 +00:00