Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 5 additions & 4 deletions fastapi_mcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ async def handle_mcp_connection(request: Request):
mcp_server._mcp_server.create_initialization_options(),
)

# Mount the MCP connection handler
app.get(mount_path)(handle_mcp_connection)
app.mount(f"{mount_path}/messages/", app=sse_transport.handle_post_message)

# Serve tools from the FastAPI app if requested
if serve_tools:
create_mcp_tools_from_openapi(
Expand All @@ -100,6 +96,11 @@ async def handle_mcp_connection(request: Request):
describe_all_responses=describe_all_responses,
describe_full_response_schema=describe_full_response_schema,
)

# Mount the MCP connection handler
app.get(mount_path)(handle_mcp_connection)
app.mount(f"{mount_path}/messages/", app=sse_transport.handle_post_message)



def add_mcp_server(
Expand Down
16 changes: 0 additions & 16 deletions tests/test_tool_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ def test_tool_generation_basic(sample_app):
assert hasattr(tool, "parameters"), "Tool missing 'parameters' property"
assert hasattr(tool, "fn_metadata"), "Tool missing 'fn_metadata' property"

# Skip MCP's internal tool that doesn't follow the same patterns
if tool.name == "handle_mcp_connection_mcp_get":
continue

# With describe_all_responses=False by default, description should only include success response code
assert "200" in tool.description, f"Expected success response code in description for {tool.name}"
assert "422" not in tool.description, f"Expected not to see 422 response in tool description for {tool.name}"
Expand Down Expand Up @@ -104,10 +100,6 @@ def test_tool_generation_with_full_schema(sample_app):

# Check all tools have the appropriate schema information
for tool in tools:
# Skip MCP's internal tool that doesn't follow the same patterns
if tool.name == "handle_mcp_connection_mcp_get":
continue

description = tool.description
# Check that the tool includes information about the Item schema
assert "Item" in description, f"Item schema should be included in the description for {tool.name}"
Expand All @@ -126,10 +118,6 @@ def test_tool_generation_with_all_responses(sample_app):

# Check all API tools include all response status codes
for tool in tools:
# Skip MCP's internal tool that doesn't follow the same patterns
if tool.name == "handle_mcp_connection_mcp_get":
continue

assert "200" in tool.description, f"Expected success response code in description for {tool.name}"
assert "422" in tool.description, f"Expected 422 response code in description for {tool.name}"

Expand All @@ -150,10 +138,6 @@ def test_tool_generation_with_all_responses_and_full_schema(sample_app):

# Check all tools include all response status codes and the full output schema
for tool in tools:
# Skip MCP's internal tool that doesn't follow the same patterns
if tool.name == "handle_mcp_connection_mcp_get":
continue

assert "200" in tool.description, f"Expected success response code in description for {tool.name}"
assert "422" in tool.description, f"Expected 422 response code in description for {tool.name}"
assert "Output Schema" in tool.description, f"Expected output schema in description for {tool.name}"
Expand Down