-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Restore mcp.server.fastmcp as a deprecated import alias for MCPServer #3189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| """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. | ||
| """ | ||
|
|
||
| import warnings | ||
|
|
||
| from mcp.server.mcpserver import Audio, Context, Icon, Image | ||
| from mcp.server.mcpserver import MCPServer as FastMCP | ||
| from mcp.shared.exceptions import MCPDeprecationWarning | ||
|
|
||
| warnings.warn( | ||
| "mcp.server.fastmcp is deprecated: FastMCP was renamed to MCPServer " | ||
| "(from mcp.server.mcpserver import MCPServer). This is not just a rename; " | ||
| "defaults and behaviour changed in v2, see the migration guide: " | ||
| "https://py.sdk.modelcontextprotocol.io/v2/migration/. " | ||
| "This import path will be removed in v3.", | ||
| MCPDeprecationWarning, | ||
| stacklevel=2, | ||
| ) | ||
|
|
||
| __all__ = ["FastMCP", "Context", "Image", "Audio", "Icon"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| """The `mcp.server.fastmcp` import path is a deprecated alias for `mcp.server.mcpserver`.""" | ||
|
|
||
| import importlib | ||
| import sys | ||
| from types import ModuleType | ||
|
|
||
| import pytest | ||
|
|
||
| from mcp import MCPDeprecationWarning | ||
| from mcp.server.mcpserver import Audio, Context, Icon, Image, MCPServer | ||
|
|
||
|
|
||
| def _import_fastmcp_fresh() -> ModuleType: | ||
| # The warning fires on module execution, so drop any cached module first. | ||
| sys.modules.pop("mcp.server.fastmcp", None) | ||
| return importlib.import_module("mcp.server.fastmcp") | ||
|
|
||
|
|
||
| def test_importing_fastmcp_warns_and_names_the_replacement(): | ||
| with pytest.warns(MCPDeprecationWarning, match="renamed to MCPServer"): | ||
| _import_fastmcp_fresh() | ||
|
|
||
|
|
||
| def test_fastmcp_reexports_the_v1_surface_as_the_v2_objects(): | ||
| with pytest.warns(MCPDeprecationWarning): | ||
| fastmcp = _import_fastmcp_fresh() | ||
|
|
||
| assert fastmcp.__all__ == ["FastMCP", "Context", "Image", "Audio", "Icon"] | ||
| assert fastmcp.FastMCP is MCPServer | ||
| assert fastmcp.Context is Context | ||
| assert fastmcp.Image is Image | ||
| assert fastmcp.Audio is Audio | ||
| assert fastmcp.Icon is Icon |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 docs/whats-new.md line 19 still says the old
mcp.server.fastmcpimport path "is gone rather than deprecated" — after this PR that sentence is wrong on both counts, since the path exists again and emits anMCPDeprecationWarning(only its submodules still raiseModuleNotFoundError). 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.mdline 19, in the "FastMCPis nowMCPServer" 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 newsrc/mcp/server/fastmcp/__init__.pyshim makesfrom mcp.server.fastmcp import FastMCP(plusContext,Image,Audio,Icon) resolve to the v2 objects while emitting anMCPDeprecationWarning. 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 saysMCPDeprecationWarning: mcp.server.fastmcp is deprecated, or ModuleNotFoundError for its submodules, and a new paragraph in the "FastMCPrenamed" section describes the bridge. Butdocs/whats-new.mdcovers 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 relevantdocs/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 FastMCPsucceeds with a warning, andFastMCP("Demo")works (it'sMCPServerunder 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.mdline 19, e.g.: "This is the first thing every v1 server hits — the top-level import now resolves with anMCPDeprecationWarning(removed in v3), while submodules likemcp.server.fastmcp.serverstill raiseModuleNotFoundError." That matches the framing the PR already adopted indocs/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.