Restore mcp.server.fastmcp as a deprecated import alias for MCPServer - #3189
Restore mcp.server.fastmcp as a deprecated import alias for MCPServer#3189maxisbey wants to merge 2 commits into
Conversation
`from mcp.server.fastmcp import FastMCP` (and the Context, Image, Audio, Icon names v1 exported alongside it) resolves again, to the v2 objects, and emits MCPDeprecationWarning at import. Only the package init is shimmed; the fastmcp submodule tree still raises ModuleNotFoundError. The alias is removed in v3. MCPServer's constructor now takes everything after `name` as keyword-only, matching the lowlevel Server. A v1 call that passed `instructions` positionally previously landed the text in the new `title` parameter silently; it now raises TypeError, which matters more once the old import path stops forcing users through the guide.
📚 Documentation preview
|
The rename section still called it a simple rename with no functional changes, contradicting the bridge paragraph and the runtime warning, and it claimed the warning enumerates the silent behaviour changes when it points at the guide instead. No-Verification-Needed: doc-only change
| """Deprecated import path: `FastMCP` was renamed to `MCPServer` in v2. | ||
|
|
||
| This module keeps `from mcp.server.fastmcp import FastMCP` working so v1 code | ||
| runs, but importing it emits an `MCPDeprecationWarning`. It is not a | ||
| behaviour-preserving alias: v2 changed defaults and semantics beyond the name | ||
| (the default server name, transport parameters moving off the constructor, | ||
| sync handlers running on a worker thread). Read the migration guide before | ||
| relying on it: | ||
|
|
||
| https://py.sdk.modelcontextprotocol.io/v2/migration/ | ||
|
|
||
| Only this package init is shimmed. Submodules such as | ||
| `mcp.server.fastmcp.server` or `mcp.server.fastmcp.prompts.base` no longer | ||
| exist; their contents live under `mcp.server.mcpserver`. This module is removed | ||
| in v3. | ||
| """ |
There was a problem hiding this comment.
🟡 docs/whats-new.md line 19 still says the old mcp.server.fastmcp import path "is gone rather than deprecated" — after this PR that sentence is wrong on both counts, since the path exists again and emits an MCPDeprecationWarning (only its submodules still raise ModuleNotFoundError). A one-sentence edit to whats-new.md (mirroring the updated symptom row in docs/migration.md) brings it in line.
Extended reasoning...
What's wrong: docs/whats-new.md line 19, in the "FastMCP is now MCPServer" section, reads: "This is the first thing every v1 server hits, because the old import path is gone rather than deprecated." This PR's headline change is precisely that the old import path is no longer gone and is now deprecated: the new src/mcp/server/fastmcp/__init__.py shim makes from mcp.server.fastmcp import FastMCP (plus Context, Image, Audio, Icon) resolve to the v2 objects while emitting an MCPDeprecationWarning. The sentence is therefore false on both counts once this PR merges.
Why it slipped through: the PR did update the docs for this behaviour change — docs/migration.md's quick-reference table now says MCPDeprecationWarning: mcp.server.fastmcp is deprecated, or ModuleNotFoundError for its submodules, and a new paragraph in the "FastMCP renamed" section describes the bridge. But docs/whats-new.md covers the same rename in its own words and wasn't touched, so the two pages now contradict each other about the PR's central feature. AGENTS.md asks that changes affecting user-visible behaviour update the relevant docs/ pages in the same PR, which suggests this is an oversight rather than a scoping decision.
Concrete walkthrough: a v1 user upgrading to v2 reads whats-new.md, which tells them their first symptom will be an import error because "the old import path is gone." They then run their server: from mcp.server.fastmcp import FastMCP succeeds with a warning, and FastMCP("Demo") works (it's MCPServer under the old name). The doc's claim doesn't match what they observe — and worse, a user who trusts the doc might not realize the warning-emitting shim is a temporary bridge removed in v3. Meanwhile migration.md (correctly) tells the same reader the path "is not gone entirely."
Impact: documentation-only. Nothing breaks at runtime; the shim, warning, and tests in this PR all behave as intended. The cost is reader confusion between two docs pages describing the same rename, on the exact behaviour this PR changes.
Fix: a one-sentence edit to docs/whats-new.md line 19, e.g.: "This is the first thing every v1 server hits — the top-level import now resolves with an MCPDeprecationWarning (removed in v3), while submodules like mcp.server.fastmcp.server still raise ModuleNotFoundError." That matches the framing the PR already adopted in docs/migration.md.
All three verifiers confirmed the finding; two rated it nit and one normal. Since the code is correct and only a doc sentence is stale, this doesn't warrant blocking the merge — nit severity.
Adds a deprecated
mcp.server.fastmcpimport path so the single most common line in v1 code,from mcp.server.fastmcp import FastMCP, resolves again on v2 (with anMCPDeprecationWarning) instead of raisingModuleNotFoundError, and makesMCPServer's constructor keyword-only aftername.Motivation and Context
from mcp.server.fastmcp import FastMCPis the first line of nearly every v1 server, and of most tutorial and LLM-generated code, so it's row 1 of the migration guide's "changes almost every project hits" table. For decorator-built servers the rename is genuinely most of the port: the README-shaped v1 quickstart (FastMCP("Demo")+@mcp.tool()/@mcp.resource()/@mcp.prompt()+mcp.run()) runs unmodified on v2 given only the class alias. This is the one v1 name where the alias alone rescues real programs, which is the line for shimming it —mcp.typesandMcpErrorstay hard breaks because an alias there saves nobody.Scope is deliberately narrow:
FastMCP,Context,Image,Audio,Icon(v1's exact__all__) resolve to the v2 objects;mcp.server.fastmcp.server,.prompts.base, etc. still raiseModuleNotFoundError, since nothing beneath them is behaviour-equivalent.MCPDeprecationWarningsubclassesUserWarning, so it shows without-W. Removed in v3.from mcp.server import FastMCPis not restored (v1 exported it there too): that needs a module-level__getattr__onmcp.server, which loosens static checking of everyfrom mcp.server import ...for all downstream users.The keyword-only constructor closes the one hazard the shim would otherwise make silent. v2 inserted
title/descriptionahead ofinstructions, so a v1FastMCP("Demo", "You answer questions about the weather.")used to run without complaint and land the instructions intitle; with the import erroring, users at least met the guide first. Now that the import warns and continues, that call raisesTypeErrorinstead — for shim users and mechanical-rename users alike, matching what the lowlevelServeralready does. The migration guide's constructor section is rewritten from "silently misassigns" to "raises".How Has This Been Tested?
tests/server/test_fastmcp.py: the import warns with the replacement named, and the five re-exports are the v2 objects (FastMCP is MCPServer, v1__all__preserved). Full suite:./scripts/testat 100% coverage,strict-no-coverclean;pyright0 errors.Client: tool call, resource template, and prompt all round-trip; the warning is attributed to the user's own import line (stacklevelcorrect) and fires once per process.from mcp.server.fastmcp.prompts import base→ModuleNotFoundError; positionalFastMCP('Demo', 'instructions')→ theTypeErrorquoted in the guide;python -W error::UserWarning -c 'import mcp.server.fastmcp'→ raises the warning cleanly by category;from mcp.server import FastMCP→ stillImportError.docs/api/before and after: nofastmcppage either way.Breaking Changes
MCPServer(...)no longer acceptstitle,description,instructions,website_url,icons,version,auth_server_provider, ortoken_verifierpositionally — pass them by keyword (the migration guide already recommended this; the signature now enforces it). Documented indocs/migration.md.Types of changes
Checklist
AI Disclaimer