From b74f9ad773969a76447a7f3554f219371bfdf247 Mon Sep 17 00:00:00 2001 From: Amirreza Hosseini <65878815+Amiirhosseini@users.noreply.github.com> Date: Mon, 7 Sep 2026 20:33:08 -0600 Subject: [PATCH] fix: map FastApiMCP description to instructions, not version mcp>=1.12 treats the second Server positional as version, so description text was showing up as Version in MCP Inspector. Pass FastAPI app version and instructions/description via keywords. Fixes #293, #322. Co-authored-by: Cursor --- fastapi_mcp/server.py | 12 +++++++++++- tests/test_configuration.py | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) 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(