diff --git a/fastapi_mcp/server.py b/fastapi_mcp/server.py index bb751067..4c308378 100644 --- a/fastapi_mcp/server.py +++ b/fastapi_mcp/server.py @@ -1,5 +1,6 @@ import json import httpx +import inspect from typing import Dict, Optional, Any, List, Union, Literal, Sequence from typing_extensions import Annotated, Doc @@ -141,7 +142,16 @@ def setup_server(self) -> None: # Filter tools based on operation IDs and tags self.tools = self._filter_tools(all_tools, openapi_schema) - mcp_server: Server = Server(self.name, self.description) + # mcp>=1.12: second positional is `version`, not description (#293, #322). + # Prefer keyword args so description maps to instructions/description and + # FastAPI's app version fills the MCP server version field. + server_kwargs: Dict[str, Any] = {"version": self.fastapi.version or ""} + server_params = inspect.signature(Server.__init__).parameters + if "instructions" in server_params: + server_kwargs["instructions"] = self.description + if "description" in server_params: + server_kwargs["description"] = self.description + mcp_server: Server = Server(self.name, **server_kwargs) @mcp_server.list_tools() async def handle_list_tools() -> List[types.Tool]: diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 79e403ee..f525e082 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -41,6 +41,21 @@ def test_custom_configuration(simple_fastapi_app: FastAPI): assert mcp_server._describe_full_response_schema is True +def test_description_is_not_passed_as_mcp_version(simple_fastapi_app: FastAPI): + """Description must not bind to MCP Server.version (issues #293, #322).""" + custom_description = "MCP Server Description" + mcp = FastApiMCP( + simple_fastapi_app, + name="MCP Server", + description=custom_description, + ) + + lowlevel = mcp.server + assert lowlevel.version != custom_description + assert lowlevel.version == simple_fastapi_app.version + assert lowlevel.instructions == custom_description + + def test_describe_all_responses_config_simple_app(simple_fastapi_app: FastAPI): """Test the describe_all_responses behavior with the simple app.""" mcp_default = FastApiMCP(