Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

Fix server_version field in inspect manifest (#1383)

Jeremiah Lowin586210d49978
diff --git a/src/fastmcp/server/server.py b/src/fastmcp/server/server.py
index 493d10804..c8d66b132 100644
--- a/src/fastmcp/server/server.py
+++ b/src/fastmcp/server/server.py
@@ -303,6 +303,10 @@ class FastMCP(Generic[LifespanResultT]):
def instructions(self) -> str | None:
return self._mcp_server.instructions
+ @property
+ def version(self) -> str | None:
+ return self._mcp_server.version
+
async def run_async(
self,
transport: Transport | None = None,
diff --git a/src/fastmcp/utilities/inspect.py b/src/fastmcp/utilities/inspect.py
index da73acf72..18c2c7e94 100644
--- a/src/fastmcp/utilities/inspect.py
+++ b/src/fastmcp/utilities/inspect.py
@@ -9,6 +9,7 @@ from typing import Any
from mcp.server.fastmcp import FastMCP as FastMCP1x
import fastmcp
+from fastmcp import Client
from fastmcp.server.server import FastMCP
@@ -71,7 +72,7 @@ class FastMCPInfo:
instructions: str | None
fastmcp_version: str
mcp_version: str
- server_version: str
+ server_version: str | None
tools: list[ToolInfo]
prompts: list[PromptInfo]
resources: list[ResourceInfo]
@@ -170,7 +171,9 @@ async def inspect_fastmcp_v2(mcp: FastMCP[Any]) -> FastMCPInfo:
instructions=mcp.instructions,
fastmcp_version=fastmcp.__version__,
mcp_version=importlib.metadata.version("mcp"),
- server_version=fastmcp.__version__, # v2.x uses FastMCP version
+ server_version=(
+ mcp.version if hasattr(mcp, "version") else mcp._mcp_server.version
+ ),
tools=tool_infos,
prompts=prompt_infos,
resources=resource_infos,
@@ -179,7 +182,7 @@ async def inspect_fastmcp_v2(mcp: FastMCP[Any]) -> FastMCPInfo:
)
-async def inspect_fastmcp_v1(mcp: Any) -> FastMCPInfo:
+async def inspect_fastmcp_v1(mcp: FastMCP1x) -> FastMCPInfo:
"""Extract information from a FastMCP v1.x instance using a Client.
Args:
@@ -188,7 +191,6 @@ async def inspect_fastmcp_v1(mcp: Any) -> FastMCPInfo:
Returns:
FastMCPInfo dataclass containing the extracted information
"""
- from fastmcp import Client
# Use a client to interact with the FastMCP1x server
async with Client(mcp) as client:
@@ -288,11 +290,11 @@ async def inspect_fastmcp_v1(mcp: Any) -> FastMCPInfo:
}
return FastMCPInfo(
- name=mcp.name,
- instructions=getattr(mcp, "instructions", None),
- fastmcp_version=fastmcp.__version__, # Report current fastmcp version
+ name=mcp._mcp_server.name,
+ instructions=mcp._mcp_server.instructions,
+ fastmcp_version=importlib.metadata.version("mcp"),
mcp_version=importlib.metadata.version("mcp"),
- server_version="1.0", # FastMCP 1.x version
+ server_version=mcp._mcp_server.version,
tools=tool_infos,
prompts=prompt_infos,
resources=resource_infos,
@@ -301,14 +303,7 @@ async def inspect_fastmcp_v1(mcp: Any) -> FastMCPInfo:
)
-def _is_fastmcp_v1(mcp: Any) -> bool:
- """Check if the given instance is a FastMCP v1.x instance."""
-
- # Check if it's an instance of FastMCP1x and not FastMCP2
- return isinstance(mcp, FastMCP1x) and not isinstance(mcp, FastMCP)
-
-
-async def inspect_fastmcp(mcp: FastMCP[Any] | Any) -> FastMCPInfo:
+async def inspect_fastmcp(mcp: FastMCP[Any] | FastMCP1x) -> FastMCPInfo:
"""Extract information from a FastMCP instance into a dataclass.
This function automatically detects whether the instance is FastMCP v1.x or v2.x
@@ -320,7 +315,7 @@ async def inspect_fastmcp(mcp: FastMCP[Any] | Any) -> FastMCPInfo:
Returns:
FastMCPInfo dataclass containing the extracted information
"""
- if _is_fastmcp_v1(mcp):
+ if isinstance(mcp, FastMCP1x):
return await inspect_fastmcp_v1(mcp)
else:
return await inspect_fastmcp_v2(mcp)
diff --git a/tests/utilities/test_inspect.py b/tests/utilities/test_inspect.py
index 723738242..0b734c199 100644
--- a/tests/utilities/test_inspect.py
+++ b/tests/utilities/test_inspect.py
@@ -1,6 +1,7 @@
"""Tests for the inspect.py module."""
-# Import FastMCP1x for testing (always available since mcp is a dependency)
+import importlib.metadata
+
from mcp.server.fastmcp import FastMCP as FastMCP1x
import fastmcp
@@ -8,7 +9,6 @@ from fastmcp import Client, FastMCP
from fastmcp.utilities.inspect import (
FastMCPInfo,
ToolInfo,
- _is_fastmcp_v1,
inspect_fastmcp,
inspect_fastmcp_v1,
)
@@ -67,15 +67,15 @@ class TestGetFastMCPInfo:
async def test_empty_server(self):
"""Test get_fastmcp_info with an empty server."""
- mcp = FastMCP("EmptyServer", instructions="Empty server for testing")
+ mcp = FastMCP("EmptyServer")
info = await inspect_fastmcp(mcp)
assert info.name == "EmptyServer"
- assert info.instructions == "Empty server for testing"
+ assert info.instructions is None
assert info.fastmcp_version == fastmcp.__version__
- assert info.mcp_version is not None
- assert info.server_version == fastmcp.__version__ # v2.x uses FastMCP version
+ assert info.mcp_version == importlib.metadata.version("mcp")
+ assert info.server_version is None
assert info.tools == []
assert info.prompts == []
assert info.resources == []
@@ -85,6 +85,18 @@ class TestGetFastMCPInfo:
assert "prompts" in info.capabilities
assert "logging" in info.capabilities
+ async def test_server_with_instructions(self):
+ """Test get_fastmcp_info with a server that has instructions."""
+ mcp = FastMCP("InstructionsServer", instructions="Test instructions")
+ info = await inspect_fastmcp(mcp)
+ assert info.instructions == "Test instructions"
+
+ async def test_server_with_version(self):
+ """Test get_fastmcp_info with a server that has a version."""
+ mcp = FastMCP("VersionServer", version="1.2.3")
+ info = await inspect_fastmcp(mcp)
+ assert info.server_version == "1.2.3"
+
async def test_server_with_tools(self):
"""Test get_fastmcp_info with a server that has tools."""
mcp = FastMCP("ToolServer")
@@ -246,14 +258,6 @@ class TestGetFastMCPInfo:
class TestFastMCP1xCompatibility:
"""Tests for FastMCP 1.x compatibility."""
- async def test_fastmcp1x_detection(self):
- """Test that FastMCP1x instances are correctly detected."""
- mcp1x = FastMCP1x("Test1x")
- mcp2x = FastMCP("Test2x")
-
- assert _is_fastmcp_v1(mcp1x) is True
- assert _is_fastmcp_v1(mcp2x) is False
-
async def test_fastmcp1x_empty_server(self):
"""Test get_fastmcp_info_v1 with an empty FastMCP1x server."""
mcp = FastMCP1x("Test1x")
@@ -262,9 +266,9 @@ class TestFastMCP1xCompatibility:
assert info.name == "Test1x"
assert info.instructions is None
- assert info.fastmcp_version == fastmcp.__version__
- assert info.mcp_version is not None
- assert info.server_version == "1.0" # v1.x servers use "1.0"
+ assert info.fastmcp_version == importlib.metadata.version("mcp")
+ assert info.mcp_version == importlib.metadata.version("mcp")
+ assert info.server_version is None
assert info.tools == []
assert info.prompts == []
assert info.resources == []
@@ -380,8 +384,8 @@ class TestFastMCP1xCompatibility:
assert "tool2x" in tool2x_names
# Check server versions
- assert info1x.server_version == "1.0"
- assert info2x.server_version == fastmcp.__version__
+ assert info1x.server_version is None
+ assert info2x.server_version is None
# No templates added in these tests
assert len(info1x.templates) == 0