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
6 changed files with 713 additions and 693 deletions

View file

@ -9,7 +9,7 @@ from inline_snapshot import snapshot
import mcp.types as types
from mcp.client.client import Client
from mcp.server import Server
from mcp.server.fastmcp import FastMCP
from mcp.server.mcpserver import MCPServer
from mcp.types import (
CallToolResult,
EmptyResult,
@ -68,9 +68,9 @@ def simple_server() -> Server:
@pytest.fixture
def app() -> FastMCP:
"""Create a FastMCP server for testing."""
server = FastMCP("test")
def app() -> MCPServer:
"""Create an MCPServer server for testing."""
server = MCPServer("test")
@server.tool()
def greet(name: str) -> str:
@ -90,7 +90,7 @@ def app() -> FastMCP:
return server
async def test_client_is_initialized(app: FastMCP):
async def test_client_is_initialized(app: MCPServer):
"""Test that the client is initialized after entering context."""
async with Client(app) as client:
assert client.server_capabilities == snapshot(
@ -114,13 +114,13 @@ async def test_client_with_simple_server(simple_server: Server):
)
async def test_client_send_ping(app: FastMCP):
async def test_client_send_ping(app: MCPServer):
async with Client(app) as client:
result = await client.send_ping()
assert result == snapshot(EmptyResult())
async def test_client_list_tools(app: FastMCP):
async def test_client_list_tools(app: MCPServer):
async with Client(app) as client:
result = await client.list_tools()
assert result == snapshot(
@ -147,7 +147,7 @@ async def test_client_list_tools(app: FastMCP):
)
async def test_client_call_tool(app: FastMCP):
async def test_client_call_tool(app: MCPServer):
async with Client(app) as client:
result = await client.call_tool("greet", {"name": "World"})
assert result == snapshot(
@ -158,7 +158,7 @@ async def test_client_call_tool(app: FastMCP):
)
async def test_read_resource(app: FastMCP):
async def test_read_resource(app: MCPServer):
"""Test reading a resource."""
async with Client(app) as client:
result = await client.read_resource("test://resource")
@ -169,7 +169,7 @@ async def test_read_resource(app: FastMCP):
)
async def test_get_prompt(app: FastMCP):
async def test_get_prompt(app: MCPServer):
"""Test getting a prompt."""
async with Client(app) as client:
result = await client.get_prompt("greeting_prompt", {"name": "Alice"})
@ -181,14 +181,14 @@ async def test_get_prompt(app: FastMCP):
)
def test_client_session_property_before_enter(app: FastMCP):
def test_client_session_property_before_enter(app: MCPServer):
"""Test that accessing session before context manager raises RuntimeError."""
client = Client(app)
with pytest.raises(RuntimeError, match="Client must be used within an async context manager"):
client.session
async def test_client_reentry_raises_runtime_error(app: FastMCP):
async def test_client_reentry_raises_runtime_error(app: MCPServer):
"""Test that reentering a client raises RuntimeError."""
async with Client(app) as client:
with pytest.raises(RuntimeError, match="Client is already entered"):
@ -237,7 +237,7 @@ async def test_client_set_logging_level(simple_server: Server):
assert result == snapshot(EmptyResult())
async def test_client_list_resources_with_params(app: FastMCP):
async def test_client_list_resources_with_params(app: MCPServer):
"""Test listing resources with params parameter."""
async with Client(app) as client:
result = await client.list_resources()
@ -255,14 +255,14 @@ async def test_client_list_resources_with_params(app: FastMCP):
)
async def test_client_list_resource_templates(app: FastMCP):
async def test_client_list_resource_templates(app: MCPServer):
"""Test listing resource templates with params parameter."""
async with Client(app) as client:
result = await client.list_resource_templates()
assert result == snapshot(ListResourceTemplatesResult(resource_templates=[]))
async def test_list_prompts(app: FastMCP):
async def test_list_prompts(app: MCPServer):
"""Test listing prompts with params parameter."""
async with Client(app) as client:
result = await client.list_prompts()

View file

@ -5,7 +5,7 @@ import pytest
import mcp.types as types
from mcp import Client
from mcp.server import Server
from mcp.server.fastmcp import FastMCP
from mcp.server.mcpserver import MCPServer
from mcp.types import ListToolsRequest, ListToolsResult
from .conftest import StreamSpyCollection
@ -16,7 +16,7 @@ pytestmark = pytest.mark.anyio
@pytest.fixture
async def full_featured_server():
"""Create a server with tools, resources, prompts, and templates."""
server = FastMCP("test")
server = MCPServer("test")
# pragma: no cover on handlers below - these exist only to register items with the
# server so list_* methods return results. The handlers themselves are never called
@ -55,7 +55,7 @@ async def full_featured_server():
)
async def test_list_methods_params_parameter(
stream_spy: Callable[[], StreamSpyCollection],
full_featured_server: FastMCP,
full_featured_server: MCPServer,
method_name: str,
request_method: str,
):
@ -95,7 +95,7 @@ async def test_list_methods_params_parameter(
async def test_list_tools_with_strict_server_validation(
full_featured_server: FastMCP,
full_featured_server: MCPServer,
):
"""Test pagination with a server that validates request format strictly."""
async with Client(full_featured_server) as client:

View file

@ -3,8 +3,8 @@ from pydantic import FileUrl
from mcp import Client
from mcp.client.session import ClientSession
from mcp.server.fastmcp import FastMCP
from mcp.server.fastmcp.server import Context
from mcp.server.mcpserver import MCPServer
from mcp.server.mcpserver.server import Context
from mcp.server.session import ServerSession
from mcp.shared.context import RequestContext
from mcp.types import ListRootsResult, Root, TextContent
@ -12,7 +12,7 @@ from mcp.types import ListRootsResult, Root, TextContent
@pytest.mark.anyio
async def test_list_roots_callback():
server = FastMCP("test")
server = MCPServer("test")
callback_return = ListRootsResult(
roots=[

View file

@ -4,7 +4,7 @@ import pytest
import mcp.types as types
from mcp import Client
from mcp.server.fastmcp import FastMCP
from mcp.server.mcpserver import MCPServer
from mcp.shared.session import RequestResponder
from mcp.types import (
LoggingMessageNotificationParams,
@ -22,7 +22,7 @@ class LoggingCollector:
@pytest.mark.anyio
async def test_logging_callback():
server = FastMCP("test")
server = MCPServer("test")
logging_collector = LoggingCollector()
# Create a simple test tool

View file

@ -2,7 +2,7 @@ import pytest
from mcp import Client
from mcp.client.session import ClientSession
from mcp.server.fastmcp import FastMCP
from mcp.server.mcpserver import MCPServer
from mcp.shared.context import RequestContext
from mcp.types import (
CreateMessageRequestParams,
@ -16,7 +16,7 @@ from mcp.types import (
@pytest.mark.anyio
async def test_sampling_callback():
server = FastMCP("test")
server = MCPServer("test")
callback_return = CreateMessageResult(
role="assistant",
@ -60,7 +60,7 @@ async def test_sampling_callback():
@pytest.mark.anyio
async def test_create_message_backwards_compat_single_content():
"""Test backwards compatibility: create_message without tools returns single content."""
server = FastMCP("test")
server = MCPServer("test")
# Callback returns single content (text)
callback_return = CreateMessageResult(

View file

@ -5,7 +5,7 @@ import pytest
from mcp import Client
from mcp.client._memory import InMemoryTransport
from mcp.server import Server
from mcp.server.fastmcp import FastMCP
from mcp.server.mcpserver import MCPServer
from mcp.types import Resource
@ -30,9 +30,9 @@ def simple_server() -> Server:
@pytest.fixture
def fastmcp_server() -> FastMCP:
"""Create a FastMCP server for testing."""
server = FastMCP("test")
def mcpserver_server() -> MCPServer:
"""Create an MCPServer server for testing."""
server = MCPServer("test")
@server.tool()
def greet(name: str) -> str:
@ -58,40 +58,40 @@ async def test_with_server(simple_server: Server):
assert write_stream is not None
async def test_with_fastmcp(fastmcp_server: FastMCP):
"""Test creating transport with a FastMCP instance."""
transport = InMemoryTransport(fastmcp_server)
async def test_with_mcpserver(mcpserver_server: MCPServer):
"""Test creating transport with an MCPServer instance."""
transport = InMemoryTransport(mcpserver_server)
async with transport.connect() as (read_stream, write_stream):
assert read_stream is not None
assert write_stream is not None
async def test_server_is_running(fastmcp_server: FastMCP):
async def test_server_is_running(mcpserver_server: MCPServer):
"""Test that the server is running and responding to requests."""
async with Client(fastmcp_server) as client:
async with Client(mcpserver_server) as client:
assert client.server_capabilities is not None
async def test_list_tools(fastmcp_server: FastMCP):
async def test_list_tools(mcpserver_server: MCPServer):
"""Test listing tools through the transport."""
async with Client(fastmcp_server) as client:
async with Client(mcpserver_server) as client:
tools_result = await client.list_tools()
assert len(tools_result.tools) > 0
tool_names = [t.name for t in tools_result.tools]
assert "greet" in tool_names
async def test_call_tool(fastmcp_server: FastMCP):
async def test_call_tool(mcpserver_server: MCPServer):
"""Test calling a tool through the transport."""
async with Client(fastmcp_server) as client:
async with Client(mcpserver_server) as client:
result = await client.call_tool("greet", {"name": "World"})
assert result is not None
assert len(result.content) > 0
assert "Hello, World!" in str(result.content[0])
async def test_raise_exceptions(fastmcp_server: FastMCP):
async def test_raise_exceptions(mcpserver_server: MCPServer):
"""Test that raise_exceptions parameter is passed through."""
transport = InMemoryTransport(fastmcp_server, raise_exceptions=True)
transport = InMemoryTransport(mcpserver_server, raise_exceptions=True)
async with transport.connect() as (read_stream, _write_stream):
assert read_stream is not None