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
8 changes: 7 additions & 1 deletion fastapi_mcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def __init__(
Optional[str],
Doc("Name for the MCP server (defaults to app.title)"),
] = None,
version: Annotated[
Optional[str],
Doc("Version for the MCP server (defaults to app.version)"),
] = None,
description: Annotated[
Optional[str],
Doc("Description for the MCP server (defaults to app.description)"),
Expand Down Expand Up @@ -98,6 +102,7 @@ def __init__(

self.fastapi = fastapi
self.name = name or self.fastapi.title or "FastAPI MCP"
self.version = version or self.fastapi.version
self.description = description or self.fastapi.description

self._base_url = "http://apiserver"
Expand Down Expand Up @@ -141,7 +146,7 @@ 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_server: Server = Server(name=self.name, version=self.version, instructions=self.description)

@mcp_server.list_tools()
async def handle_list_tools() -> List[types.Tool]:
Expand Down Expand Up @@ -654,3 +659,4 @@ def _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any])
}

return filtered_tools

3 changes: 3 additions & 0 deletions tests/test_basic_functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ def test_create_mcp_server(simple_fastapi_app: FastAPI):
mcp = FastApiMCP(
simple_fastapi_app,
name="Test MCP Server",
version="1.2.3",
description="Test description",
)

# Verify the MCP server was created correctly
assert mcp.name == "Test MCP Server"
assert mcp.version == "1.2.3"
assert mcp.description == "Test description"
assert isinstance(mcp.server, Server)
assert len(mcp.tools) > 0, "Should have extracted tools from the app"
Expand All @@ -31,6 +33,7 @@ def test_default_values(simple_fastapi_app: FastAPI):

# Verify default values
assert mcp.name == simple_fastapi_app.title
assert mcp.version == simple_fastapi_app.version
assert mcp.description == simple_fastapi_app.description

# Mount with default path
Expand Down