Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion fastapi_mcp/server.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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]:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down