π The fast, Pythonic way to build MCP servers and clients.
Follow pagination in the MCP format of fastmcp inspect (#5691)
Asem ahmed8df91c97e525
diff --git a/fastmcp_slim/fastmcp/utilities/inspect.py b/fastmcp_slim/fastmcp/utilities/inspect.pyindex a3d5d6e2e..0974c6218 100644--- a/fastmcp_slim/fastmcp/utilities/inspect.py+++ b/fastmcp_slim/fastmcp/utilities/inspect.py@@ -474,10 +474,10 @@ async def format_mcp_info(mcp: FastMCP[Any] | SDKServer) -> bytes:# handshake carries, so pin the handshake era.async with Client(mcp, mode="legacy") as client:# Get all the MCP protocol objects- tools_result = await client.list_tools_mcp()- prompts_result = await client.list_prompts_mcp()- resources_result = await client.list_resources_mcp()- templates_result = await client.list_resource_templates_mcp()+ tools = await client.list_tools()+ prompts = await client.list_prompts()+ resources = await client.list_resources()+ templates = await client.list_resource_templates()# Get server info from the initialize resultserver_info = client.initialize_result.server_info@@ -491,10 +491,10 @@ async def format_mcp_info(mcp: FastMCP[Any] | SDKServer) -> bytes:"serverInfo": server_info,"instructions": client.initialize_result.instructions,"capabilities": {}, # MCP format doesn't include capabilities at top level- "tools": tools_result.tools,- "prompts": prompts_result.prompts,- "resources": resources_result.resources,- "resourceTemplates": templates_result.resource_templates,+ "tools": tools,+ "prompts": prompts,+ "resources": resources,+ "resourceTemplates": templates,}return pydantic_core.to_json(result, indent=2)diff --git a/tests/utilities/test_inspect.py b/tests/utilities/test_inspect.pyindex 9b9b70d70..d123c8ff6 100644--- a/tests/utilities/test_inspect.py+++ b/tests/utilities/test_inspect.py@@ -1,6 +1,7 @@"""Tests for the inspect.py module."""import importlib.metadata+import jsonfrom mcp.server.mcpserver import MCPServer as SDKServer@@ -9,6 +10,7 @@ from fastmcp import Client, FastMCPfrom fastmcp.utilities.inspect import (FastMCPInfo,ToolInfo,+ format_mcp_info,inspect_fastmcp,inspect_fastmcp_v1,)@@ -602,3 +604,34 @@ class TestFastMCP1xCompatibility:# No templates added in these testsassert len(info1x.templates) == 0assert len(info2x.templates) == 0+++class TestFormatMcpInfo:+ """Tests for the MCP protocol format of inspect."""++ async def test_follows_pagination(self):+ """A server that paginates its lists is not truncated to the first page."""+ mcp = FastMCP("Paged", list_page_size=2)++ for i in range(3):+ mcp.tool(lambda: "x", name=f"tool{i}")+ mcp.prompt(lambda: "x", name=f"prompt{i}")+ mcp.resource(f"data://resource{i}", name=f"resource{i}")(lambda: "x")+ mcp.resource(f"data://template{i}/{{x}}", name=f"template{i}")(+ lambda x: "x"+ )++ data = json.loads(await format_mcp_info(mcp))++ assert [t["name"] for t in data["tools"]] == ["tool0", "tool1", "tool2"]+ assert [p["name"] for p in data["prompts"]] == ["prompt0", "prompt1", "prompt2"]+ assert [r["name"] for r in data["resources"]] == [+ "resource0",+ "resource1",+ "resource2",+ ]+ assert [t["name"] for t in data["resourceTemplates"]] == [+ "template0",+ "template1",+ "template2",+ ]