fastmcp/tests
Jeremiah Lowin 8363ec4d26
Add stateless session state (UserSession / SessionId) (#4604)
* Design doc: stateless session state

* Add stateless session-state primitives: Scope, SessionCodec, scoped state

* Add SessionProvider and Session() annotation for stateless session state

* Rewrite session-state design to final shape (Session object, two patterns, no seal)

* Rework stateless session state to final Session/SessionId design

Remove Scope, SessionCodec/sealing, and scoped ctx.get_state. Add the
Session object (get/set/delete/clear over one dict per (principal,
session_id) key), injected session: Session (keyed by principal, requires
auth), session_id: SessionId argument with auto-filled description, and
SessionProvider contributing create_session/end_session.

* Rename injected marker to UserSession; auto-wire SessionProvider on SessionId

* Document stateless session state as a v4 feature

* Require SessionProvider and make sessions create-then-validate

Remove the implicit SessionProvider auto-wiring; a SessionProvider must now be
registered explicitly. create_session records an owned session and get_session
validates the id, rejecting uncreated or foreign ids.

* Add Session.id (public id for session_id sessions, None for UserSession)

* Fix ty: narrow Tool | None and ToolResult.structured_content in session tests

* Fix session-provider enforcement gap for non-local tools; stop embedding raw principal in UserSession key

* Fix disabled session_id tools blocking listing; reject local tools shadowing SessionProvider lifecycle names

* Decouple SessionId description from lifecycle tool name so it survives namespaced mounts

* Remove SessionProvider enforcement; get_session validation is the guarantee

* Fix stale enforcement/key-format docs; document store-owned session TTL

* Dedup SessionId contract description; tighten context.mdx session-state lead

* Make session store/description resolution work in Docket task workers and for partial tools

* Expose get_session as a standalone task-safe function; drop foreground-only Context.get_session

* Move get_session to dependencies alongside the other request accessors

* Reframe context state docs as Request State; cross-request persistence points to Session State

* Address UserSession injection edge cases from review

- inject a UserSession instance (not bare Session) so isinstance holds
- support session: UserSession | None = None (inject None when unauth)
- detect SessionId params past a partial's positional binding
2026-07-23 19:21:00 -04:00
..
apps Add default prefill to FormInput.collect_input (#3937) 2026-04-14 13:23:36 -04:00
cli Migrate to MCP Python SDK v2 (#4437) 2026-07-06 17:36:45 -04:00
client Expose era-neutral client server metadata (#4599) 2026-07-23 15:06:26 -05:00
conformance Make the unit suite fast: in-process HTTP tests, no real sleeps, parallel Windows CI (#4554) 2026-07-20 10:51:14 -04:00
contrib Speed up the unit test suite, and fix the task-notification race it surfaced (#4550) 2026-07-19 18:52:04 -04:00
deprecated Audit mode="legacy" pins in server tests and top-level stragglers 2026-07-20 16:00:27 -04:00
docs Skip live-import validation for frozen v2 doc snapshots 2026-07-07 07:53:10 -04:00
experimental Migrate to MCP Python SDK v2 (#4437) 2026-07-06 17:36:45 -04:00
fixtures test: vendor ext-tasks draft schema as fixture 2026-07-21 20:19:28 -04:00
fs fix(fs): isolate same-named package imports across providers (#4361) 2026-06-24 10:57:01 -04:00
integration_tests Merge remote-tracking branch 'origin/main' into feature/client-auto-default 2026-07-20 12:02:38 -04:00
prompts Migrate to MCP Python SDK v2 (#4437) 2026-07-06 17:36:45 -04:00
resources Make the unit suite fast: in-process HTTP tests, no real sleeps, parallel Windows CI (#4554) 2026-07-20 10:51:14 -04:00
scripts Exempt maintainers from MRE auto-close (#4220) 2026-05-23 09:02:44 -04:00
server Add stateless session state (UserSession / SessionId) (#4604) 2026-07-23 19:21:00 -04:00
telemetry Preserve telemetry attributes when a sampler does not forward them (#4539) 2026-07-19 09:00:04 -04:00
tools Preserve raw CallToolResult returns (#4587) 2026-07-23 15:10:42 -05:00
utilities Fix File helper extension handling (#4531) 2026-07-21 13:04:15 -05:00
__init__.py Update type handling for resources 2024-11-29 19:42:46 -05:00
conftest.py Make the unit suite fast: in-process HTTP tests, no real sleeps, parallel Windows CI (#4554) 2026-07-20 10:51:14 -04:00
test_apps.py Audit mode="legacy" pins in server tests and top-level stragglers 2026-07-20 16:00:27 -04:00
test_apps_prefab.py Migrate to MCP Python SDK v2 (#4437) 2026-07-06 17:36:45 -04:00
test_compat.py Bridge camelCase ToolAnnotations reads (#4597) 2026-07-22 13:55:41 -05:00
test_exceptions.py Emit one SERVER span per request and adopt spec-correct error codes (#4445) 2026-07-07 07:49:06 -04:00
test_fastmcp_app.py Migrate to MCP Python SDK v2 (#4437) 2026-07-06 17:36:45 -04:00
test_json_schema_generation.py fix: resolve Pyright "Module is not callable" on @tool, @resource, @prompt decorators (#3540) 2026-03-17 18:11:42 -04:00
test_mcp_config.py Mark transforming single-server config wrapper legacy-only 2026-07-20 16:34:42 -04:00
test_no_legacy_httpx.py Make the unit suite fast: in-process HTTP tests, no real sleeps, parallel Windows CI (#4554) 2026-07-20 10:51:14 -04:00
test_settings.py Forward-port HTTP host guard compatibility (#4474) 2026-07-08 20:55:56 -04:00
test_upgrade_from_v3.py Document v3->v4 removals and add upgrade-reality tests (#4585) 2026-07-21 17:12:59 -04:00