π The fast, Pythonic way to build MCP servers and clients.
Docs: mark sampling deprecated, update era matrix and change register
Jeremiah Lowinb023aae51a71
diff --git a/docs/development/v4-notes/change-register.mdx b/docs/development/v4-notes/change-register.mdxindex bd8e94ee5..7a2f6a31b 100644--- a/docs/development/v4-notes/change-register.mdx+++ b/docs/development/v4-notes/change-register.mdx@@ -245,23 +245,31 @@ The push-style Context features that require the server to call back into the cl| `ctx.info` / logging notifications | Supported | Supported || Tools, resources, prompts, completions | Supported | Supported || `ctx.elicit` | Supported | Not yet β MRTR rewrite pending |-| `ctx.sample` | Supported | Not yet β being removed in 4.0 |+| `ctx.sample` / `ctx.sample_step` | Supported (deprecated) | Removed β call an LLM server-side || `ctx.list_roots` | Supported | Not yet β MRTR rewrite pending || Tasks (via the FastMCP client) | Supported | Not yet |-Tools that rely on `ctx.elicit`, `ctx.sample`, or `ctx.list_roots` continue to work against clients on the session-based eras.+Tools that rely on `ctx.elicit` or `ctx.list_roots` continue to work against clients on the session-based eras. Sampling is the exception: it is deprecated on every era and will not return on modern connections (see the Deprecated entry below).-Ordinary `ctx.info` and `ctx.sample` usage now emits an SDK-level `MCPDeprecationWarning` ("The logging/sampling capability is deprecated as of 2026-07-28 (SEP-2577)"). The warnings come from the SDK, not FastMCP, and are benign β the features keep working on session-based connections per the matrix. Users will see them and wonder, so the upgrade guide calls them out explicitly.+Ordinary `ctx.info` usage emits an SDK-level `MCPDeprecationWarning` ("The logging capability is deprecated as of 2026-07-28 (SEP-2577)"). That warning comes from the SDK, not FastMCP, and is benign β logging keeps working on session-based connections per the matrix. `ctx.sample`/`ctx.sample_step` additionally emit a FastMCP-owned `FastMCPDeprecationWarning` (see below). The upgrade guide calls both out explicitly.Wire interop across the transition is verified: a 3.4.3 client against a v4 server and a v4 client against a 3.4.3 server are bidirectionally clean across 9 operations over HTTP (WS2).*Verify:* `docs/getting-started/upgrading/from-fastmcp-3.mdx` (the published matrix and SDK-warning note), `tests/server/test_protocol_eras.py`.-### Push-feature degradation quality β Known gap+### Sampling deprecated, era-gated β Deprecated-The degradation error differs by feature on a `2026-07-28` connection: `ctx.list_roots` raises a clear `NoBackChannelError`, while `ctx.elicit` / `ctx.sample` surface a bare "Method not found" because those methods were removed from the 2026 server-request registry. This is sdk-feedback #10 and is captured by a strict xfail in `test_protocol_eras.py`. FastMCP's planned fix is to era-gate `ctx.elicit`/`ctx.sample` to raise a clear message before the wire.+`ctx.sample()` and `ctx.sample_step()` are deprecated and slated for removal in a future FastMCP release. Server-initiated sampling relies on the `createMessage` back-channel that SEP-2577 removed from the wire as of `2026-07-28`, and unlike elicitation it has no multi-round-trip replacement (the agentic loop would exhaust the round-trip budget). Both methods now emit a `FastMCPDeprecationWarning` once per process (gated on `settings.deprecation_warnings`), and on a `2026-07-28` connection they raise a clear `ToolError` before touching the wire. The client-side sampling handler infrastructure (anthropic/openai/google_genai) is retained for future MRTR work and is not deprecated. The migration is to call an LLM directly from your server rather than borrowing the client's model.-*Verify:* `tests/server/test_protocol_eras.py:319` (strict xfail referencing sdk-feedback #10).+The dead TODO at `server/context.py` (a background-task sampling relay that was never built) is removed: that relay is not being built, so the note is gone rather than left as a promise.++*Verify:* `fastmcp_slim/fastmcp/server/context.py` (`_warn_sampling_deprecated`, `_is_modern_protocol`, the `sample`/`sample_step` gates), `docs/servers/sampling.mdx` (deprecation banner), `tests/server/test_protocol_eras.py` (warning + era-gate tests).++### Push-feature degradation quality β Resolved (was sdk-feedback #10)++On a `2026-07-28` connection the degradation error used to differ by feature: `ctx.list_roots` raised a clear `NoBackChannelError`, while `ctx.elicit` / `ctx.sample` surfaced a bare "Method not found" because those methods attach a `related_request_id` and reach client dispatch before failing. FastMCP now era-gates `ctx.elicit` and `ctx.sample`/`ctx.sample_step` to raise a clear, era-aware `ToolError` before the wire ("server-initiated sampling is not available on MCP 2026-07-28 connectionsβ¦" and "elicitation via server-initiated requests is unavailable on 2026-07-28 connections."). The strict xfail that captured #10 is flipped to a passing test.++*Verify:* `tests/server/test_protocol_eras.py` (`test_elicit_sample_degradation_message_is_clear_on_modern`, now a real test), `server/context.py` (era gates).### The xfail register β Known gapdiff --git a/docs/getting-started/upgrading/from-fastmcp-3.mdx b/docs/getting-started/upgrading/from-fastmcp-3.mdxindex 25c1617dd..50fe44fc2 100644--- a/docs/getting-started/upgrading/from-fastmcp-3.mdx+++ b/docs/getting-started/upgrading/from-fastmcp-3.mdx@@ -126,21 +126,23 @@ Ordinary use of `ctx.info` (client logging) and `ctx.sample` now emits an SDK-leThe logging/sampling capability is deprecated as of 2026-07-28 (SEP-2577)```-These warnings come from the MCP SDK, not from FastMCP, and they are benign: the features keep working on session-based (handshake-era) connections exactly as the protocol table below describes. The SDK is signaling that the `2026-07-28` protocol era removed these capabilities from the wire β the warning is about the protocol's direction, not about your code being broken today.+These warnings come from the MCP SDK, not from FastMCP. For logging they are benign: `ctx.info` keeps working on session-based connections exactly as the protocol table below describes, and the SDK is only signaling the protocol's direction. For sampling, FastMCP additionally emits its own `FastMCPDeprecationWarning`: `ctx.sample` and `ctx.sample_step` are deprecated and slated for removal, so treat that warning as a prompt to migrate to server-side LLM calls rather than as informational.## Protocol version supportFastMCP servers built on the SDK v2 serve multiple protocol eras from the same server. The SDK negotiates the era each client speaks: the sessionless `2026-07-28` era (which discovers capabilities through `server/discover`) and earlier session-based handshake versions are all handled simultaneously. This formally supersedes FastMCP's earlier "latest protocol only" stance β a single server now works with clients across the protocol transition.-Not every Context feature is available on every era yet. The push-style interactions that require the server to call back into the client β elicitation, sampling, and listing roots β depend on the session-based request/response flow of the earlier eras. On a `2026-07-28` connection these raise, because the sessionless era needs a multi-round-trip replacement that is still being built. Logging notifications and the request/response features flow on every era.+Not every Context feature is available on every era yet. The push-style interactions that require the server to call back into the client β elicitation, sampling, and listing roots β depend on the session-based request/response flow of the earlier eras. On a `2026-07-28` connection these raise a clear, era-aware error rather than reaching the client. Logging notifications and the request/response features flow on every era.++Sampling is the exception that does not come back. `ctx.sample` and `ctx.sample_step` are **deprecated** and will be removed in a future FastMCP release: server-initiated sampling was removed from the wire by SEP-2577, and unlike elicitation it has no multi-round-trip replacement (the agentic loop would exhaust the round-trip budget). The migration is to call an LLM directly from your server rather than borrowing the client's model. See [Sampling](/servers/sampling) for details.| Context feature | Earlier eras (session-based) | `2026-07-28` (sessionless) || --- | --- | --- || `ctx.info` / logging notifications | Supported | Supported || Tools, resources, prompts, completions | Supported | Supported || `ctx.elicit` | Supported | Not yet β MRTR rewrite pending |-| `ctx.sample` | Supported | Not yet β MRTR rewrite pending |+| `ctx.sample` / `ctx.sample_step` | Supported (deprecated) | Removed β call an LLM server-side || `ctx.list_roots` | Supported | Not yet β MRTR rewrite pending || Tasks (via the FastMCP client) | Supported | Not yet |-If your tools rely on `ctx.elicit`, `ctx.sample`, or `ctx.list_roots`, they continue to work against clients on the earlier eras. As the sessionless replacements land, this table will expand.+If your tools rely on `ctx.elicit` or `ctx.list_roots`, they continue to work against clients on the earlier eras, and the sessionless replacements will expand this table as they land. Sampling is deprecated on every era and will not return on modern connections β migrate those tools to server-side LLM calls.diff --git a/docs/servers/sampling.mdx b/docs/servers/sampling.mdxindex 4043e2ad7..d19a05c01 100644--- a/docs/servers/sampling.mdx+++ b/docs/servers/sampling.mdx@@ -9,6 +9,20 @@ import { VersionBadge } from "/snippets/version-badge.mdx"<VersionBadge version="2.0.0" />+<Warning>+**Sampling is deprecated and will be removed in a future FastMCP release.**++`ctx.sample()` and `ctx.sample_step()` rely on server-initiated `createMessage`+requests, which MCP removed as of the 2026-07-28 protocol (SEP-2577). They work+only on session-based (handshake-era) connections; on a 2026-07-28 connection+they raise a clear error rather than reaching the client.++**Migration:** call an LLM directly from your server using your own API key and+provider SDK instead of borrowing the client's model. There is no drop-in+replacement on modern connections β this architectural shift is the intended+answer.+</Warning>+LLM sampling allows your MCP tools to request text generation from an LLM during execution. This enables tools to leverage AI capabilities for analysis, generation, reasoning, and moreβwithout the client needing to orchestrate multiple calls.By default, sampling requests are routed to the client's LLM. You can also configure a fallback handler to use a specific provider (like OpenAI) when the client doesn't support sampling, or to always use your own LLM regardless of client capabilities.