Rename FastMCP to MCPServer (#1951)

This commit is contained in:
Marcelo Trylesinski 2026-01-25 14:45:52 +01:00 • committed by GitHub
commit 65c614e48e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 713 additions and 693 deletions

View file

@ -1,12 +1,12 @@
import pytest
from mcp.server.fastmcp import FastMCP
from mcp.server.mcpserver import MCPServer
pytestmark = pytest.mark.anyio
async def test_list_tools_returns_all_tools():
mcp = FastMCP("TestTools")
mcp = MCPServer("TestTools")
# Create 100 tools with unique names
num_tools = 100

View file

@ -43,13 +43,13 @@ async def test_lifespan_cleanup_executed():
Path(startup_marker).unlink()
Path(cleanup_marker).unlink()
# Create a minimal MCP server using FastMCP that tracks lifecycle
# Create a minimal MCP server using MCPServer that tracks lifecycle
server_code = textwrap.dedent(f"""
import asyncio
import sys
from pathlib import Path
from contextlib import asynccontextmanager
from mcp.server.fastmcp import FastMCP
from mcp.server.mcpserver import MCPServer
STARTUP_MARKER = {escape_path_for_python(startup_marker)}
CLEANUP_MARKER = {escape_path_for_python(cleanup_marker)}
@ -64,7 +64,7 @@ async def test_lifespan_cleanup_executed():
# This cleanup code now runs properly during shutdown
Path(CLEANUP_MARKER).write_text("cleaned up")
mcp = FastMCP("test-server", lifespan=lifespan)
mcp = MCPServer("test-server", lifespan=lifespan)
@mcp.tool()
def echo(text: str) -> str:
@ -156,7 +156,7 @@ async def test_stdin_close_triggers_cleanup():
import sys
from pathlib import Path
from contextlib import asynccontextmanager
from mcp.server.fastmcp import FastMCP
from mcp.server.mcpserver import MCPServer
STARTUP_MARKER = {escape_path_for_python(startup_marker)}
CLEANUP_MARKER = {escape_path_for_python(cleanup_marker)}
@ -171,7 +171,7 @@ async def test_stdin_close_triggers_cleanup():
# This cleanup code runs when stdin closes, enabling graceful shutdown
Path(CLEANUP_MARKER).write_text("cleaned up")
mcp = FastMCP("test-server", lifespan=lifespan)
mcp = MCPServer("test-server", lifespan=lifespan)
@mcp.tool()
def echo(text: str) -> str:

View file

@ -1,13 +1,13 @@
import pytest
from mcp import types
from mcp.server.fastmcp import FastMCP
from mcp.server.mcpserver import MCPServer
@pytest.mark.anyio
async def test_resource_templates():
# Create an MCP server
mcp = FastMCP("Demo")
mcp = MCPServer("Demo")
# Add a dynamic greeting resource
@mcp.resource("greeting://{name}")
@ -23,7 +23,7 @@ async def test_resource_templates():
# Get the list of resource templates using the underlying server
# Note: list_resource_templates() returns a decorator that wraps the handler
# The handler returns a ServerResult with a ListResourceTemplatesResult inside
result = await mcp._mcp_server.request_handlers[types.ListResourceTemplatesRequest](
result = await mcp._lowlevel_server.request_handlers[types.ListResourceTemplatesRequest](
types.ListResourceTemplatesRequest(params=None)
)
assert isinstance(result, types.ListResourceTemplatesResult)

View file

@ -2,7 +2,7 @@
import pytest
from mcp.server.fastmcp import FastMCP
from mcp.server.mcpserver import MCPServer
from mcp.types import Icon
pytestmark = pytest.mark.anyio
@ -19,7 +19,7 @@ async def test_icons_and_website_url():
)
# Create server with website URL and icon
mcp = FastMCP("TestServer", website_url="https://example.com", icons=[test_icon])
mcp = MCPServer("TestServer", website_url="https://example.com", icons=[test_icon])
# Create tool with icon
@mcp.tool(icons=[test_icon])
@ -100,7 +100,7 @@ async def test_multiple_icons():
icon2 = Icon(src="data:image/png;base64,icon2", mime_type="image/png", sizes=["32x32"])
icon3 = Icon(src="data:image/png;base64,icon3", mime_type="image/png", sizes=["64x64"])
mcp = FastMCP("MultiIconServer")
mcp = MCPServer("MultiIconServer")
# Create tool with multiple icons
@mcp.tool(icons=[icon1, icon2, icon3])
@ -122,7 +122,7 @@ async def test_multiple_icons():
async def test_no_icons_or_website():
"""Test that server works without icons or websiteUrl."""
mcp = FastMCP("BasicServer")
mcp = MCPServer("BasicServer")
@mcp.tool()
def basic_tool() -> str: # pragma: no cover

View file

@ -1,7 +1,7 @@
import pytest
from mcp import Client
from mcp.server.fastmcp import FastMCP
from mcp.server.mcpserver import MCPServer
from mcp.types import (
ListResourceTemplatesResult,
TextResourceContents,
@ -11,7 +11,7 @@ from mcp.types import (
@pytest.mark.anyio
async def test_resource_template_edge_cases():
"""Test server-side resource template validation"""
mcp = FastMCP("Demo")
mcp = MCPServer("Demo")
# Test case 1: Template with multiple parameters
@mcp.resource("resource://users/{user_id}/posts/{post_id}")
@ -64,7 +64,7 @@ async def test_resource_template_edge_cases():
@pytest.mark.anyio
async def test_resource_template_client_interaction():
"""Test client-side resource template interaction"""
mcp = FastMCP("Demo")
mcp = MCPServer("Demo")
# Register some templated resources
@mcp.resource("resource://users/{user_id}/posts/{post_id}")

View file

@ -3,16 +3,16 @@ import base64
import pytest
from mcp import Client, types
from mcp.server.fastmcp import FastMCP
from mcp.server.lowlevel import Server
from mcp.server.lowlevel.helper_types import ReadResourceContents
from mcp.server.mcpserver import MCPServer
pytestmark = pytest.mark.anyio
async def test_fastmcp_resource_mime_type():
async def test_mcpserver_resource_mime_type():
"""Test that mime_type parameter is respected for resources."""
mcp = FastMCP("test")
mcp = MCPServer("test")
# Create a small test image as bytes
image_bytes = b"fake_image_data"

View file

@ -7,14 +7,14 @@ with parameters like 'text/html;profile=mcp-app' which are valid per RFC 2045.
import pytest
from mcp import Client
from mcp.server.fastmcp import FastMCP
from mcp.server.mcpserver import MCPServer
pytestmark = pytest.mark.anyio
async def test_mime_type_with_parameters():
"""Test that MIME types with parameters are accepted (RFC 2045)."""
mcp = FastMCP("test")
mcp = MCPServer("test")
# This should NOT raise a validation error
@mcp.resource("ui://widget", mime_type="text/html;profile=mcp-app")
@ -28,7 +28,7 @@ async def test_mime_type_with_parameters():
async def test_mime_type_with_parameters_and_space():
"""Test MIME type with space after semicolon."""
mcp = FastMCP("test")
mcp = MCPServer("test")
@mcp.resource("data://json", mime_type="application/json; charset=utf-8")
def data() -> str:
@ -41,7 +41,7 @@ async def test_mime_type_with_parameters_and_space():
async def test_mime_type_with_multiple_parameters():
"""Test MIME type with multiple parameters."""
mcp = FastMCP("test")
mcp = MCPServer("test")
@mcp.resource("data://multi", mime_type="text/plain; charset=utf-8; format=fixed")
def data() -> str:
@ -54,7 +54,7 @@ async def test_mime_type_with_multiple_parameters():
async def test_mime_type_preserved_in_read_resource():
"""Test that MIME type with parameters is preserved when reading resource."""
mcp = FastMCP("test")
mcp = MCPServer("test")
@mcp.resource("ui://my-widget", mime_type="text/html;profile=mcp-app")
def my_widget() -> str:

View file

@ -2,7 +2,7 @@ from unittest.mock import AsyncMock, MagicMock
import pytest
from mcp.server.fastmcp import Context
from mcp.server.mcpserver import Context
from mcp.shared.context import RequestContext
pytestmark = pytest.mark.anyio
@ -24,7 +24,7 @@ async def test_progress_token_zero_first_call():
)
# Create context with our mocks
ctx = Context(request_context=request_context, fastmcp=MagicMock())
ctx = Context(request_context=request_context, mcp_server=MagicMock())
# Test progress reporting
await ctx.report_progress(0, 10) # First call with 0

View file

@ -2,12 +2,12 @@ import anyio
import pytest
from mcp import Client
from mcp.server.fastmcp import FastMCP
from mcp.server.mcpserver import MCPServer
@pytest.mark.anyio
async def test_messages_are_executed_concurrently_tools():
server = FastMCP("test")
server = MCPServer("test")
event = anyio.Event()
tool_started = anyio.Event()
call_order: list[str] = []
@ -48,7 +48,7 @@ async def test_messages_are_executed_concurrently_tools():
@pytest.mark.anyio
async def test_messages_are_executed_concurrently_tools_and_resources():
server = FastMCP("test")
server = MCPServer("test")
event = anyio.Event()
tool_started = anyio.Event()
call_order: list[str] = []

View file

@ -2,7 +2,7 @@ from collections.abc import AsyncIterator
from contextlib import asynccontextmanager
from dataclasses import dataclass
from mcp.server.fastmcp import Context, FastMCP
from mcp.server.mcpserver import Context, MCPServer
from mcp.server.session import ServerSession
@ -19,7 +19,7 @@ class Database: # Replace with your actual DB type
# Create a named server
mcp = FastMCP("My App")
mcp = MCPServer("My App")
@dataclass
@ -28,7 +28,7 @@ class AppContext:
@asynccontextmanager
async def app_lifespan(server: FastMCP) -> AsyncIterator[AppContext]: # pragma: no cover
async def app_lifespan(server: MCPServer) -> AsyncIterator[AppContext]: # pragma: no cover
"""Manage application lifecycle with type-safe context"""
# Initialize on startup
db = await Database.connect()
@ -40,7 +40,7 @@ async def app_lifespan(server: FastMCP) -> AsyncIterator[AppContext]: # pragma:
# Pass lifespan to server
mcp = FastMCP("My App", lifespan=app_lifespan)
mcp = MCPServer("My App", lifespan=app_lifespan)
# Access type-safe lifespan context in tools

View file

@ -3,7 +3,7 @@
Regression test for https://github.com/modelcontextprotocol/python-sdk/issues/973
"""
from mcp.server.fastmcp.resources import ResourceTemplate
from mcp.server.mcpserver.resources import ResourceTemplate
def test_template_matches_decodes_space():