From ba8d578a185993af900ebbbe94f2240a459424b7 Mon Sep 17 00:00:00 2001 From: shiraayal-tadata Date: Tue, 1 Apr 2025 11:34:45 +0300 Subject: [PATCH 1/4] skip handle_mcp_connection_mcp_get when creating tools --- fastapi_mcp/http_tools.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fastapi_mcp/http_tools.py b/fastapi_mcp/http_tools.py index 233ae96..c47552a 100644 --- a/fastapi_mcp/http_tools.py +++ b/fastapi_mcp/http_tools.py @@ -83,6 +83,10 @@ def create_mcp_tools_from_openapi( if not operation_id: continue + # Skip MCP's internal tool that doesn't follow the same patterns + if operation_id == "handle_mcp_connection_mcp_get": + continue + # Create MCP tool for this operation create_http_tool( mcp_server=mcp_server, From f31a2b41bc572da389f8bc61afa9315b99dfe6b2 Mon Sep 17 00:00:00 2001 From: shiraayal-tadata Date: Tue, 1 Apr 2025 11:34:58 +0300 Subject: [PATCH 2/4] remove this skip from tests as no longer needed --- tests/test_tool_generation.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/tests/test_tool_generation.py b/tests/test_tool_generation.py index 25102d1..d69b6ff 100644 --- a/tests/test_tool_generation.py +++ b/tests/test_tool_generation.py @@ -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}" @@ -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}" @@ -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}" @@ -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}" From ddb333dcfd9399d17223e851304558f6d98f80d8 Mon Sep 17 00:00:00 2001 From: shiraayal-tadata Date: Sun, 6 Apr 2025 12:04:36 +0300 Subject: [PATCH 3/4] move the mounting to happen after the tool creation so handle_mcp_conneciton won't be created as a tool --- fastapi_mcp/http_tools.py | 4 ---- fastapi_mcp/server.py | 9 +++++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/fastapi_mcp/http_tools.py b/fastapi_mcp/http_tools.py index c47552a..233ae96 100644 --- a/fastapi_mcp/http_tools.py +++ b/fastapi_mcp/http_tools.py @@ -83,10 +83,6 @@ def create_mcp_tools_from_openapi( if not operation_id: continue - # Skip MCP's internal tool that doesn't follow the same patterns - if operation_id == "handle_mcp_connection_mcp_get": - continue - # Create MCP tool for this operation create_http_tool( mcp_server=mcp_server, diff --git a/fastapi_mcp/server.py b/fastapi_mcp/server.py index db65adb..1bf62b0 100644 --- a/fastapi_mcp/server.py +++ b/fastapi_mcp/server.py @@ -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( @@ -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( From 29447434963c85b510ed6eabf2213708301bb479 Mon Sep 17 00:00:00 2001 From: shiraayal-tadata Date: Sun, 6 Apr 2025 12:15:12 +0300 Subject: [PATCH 4/4] version prep --- CHANGELOG.md | 5 +++++ fastapi_mcp/__init__.py | 2 +- pyproject.toml | 2 +- setup.py | 2 +- uv.lock | 2 +- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 339a05b..0020ee5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.1.6] + +### Fixed +- [Issue #23](https://github.com/tadata-org/fastapi_mcp/issues/23): Hide handle_mcp_connection tool. + ## [0.1.5] ### Fixed diff --git a/fastapi_mcp/__init__.py b/fastapi_mcp/__init__.py index 85e7823..0c6a810 100644 --- a/fastapi_mcp/__init__.py +++ b/fastapi_mcp/__init__.py @@ -4,7 +4,7 @@ Created by Tadata Inc. (https://github.com/tadata-org) """ -__version__ = "0.1.5" +__version__ = "0.1.6" from .server import add_mcp_server, create_mcp_server, mount_mcp_server from .http_tools import create_mcp_tools_from_openapi diff --git a/pyproject.toml b/pyproject.toml index b56023a..cd36e2e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "fastapi-mcp" -version = "0.1.5" +version = "0.1.6" description = "Automatic MCP server generator for FastAPI applications - converts FastAPI endpoints to MCP tools for LLM integration" readme = "README.md" requires-python = ">=3.10" diff --git a/setup.py b/setup.py index 31d56b8..5062c44 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name="fastapi-mcp", - version="0.1.5", + version="0.1.6", description="Automatic MCP server generator for FastAPI applications - converts FastAPI endpoints to MCP tools for LLM integration", author="Tadata Inc.", author_email="itay@tadata.com", diff --git a/uv.lock b/uv.lock index 531afe5..83ff7b5 100644 --- a/uv.lock +++ b/uv.lock @@ -207,7 +207,7 @@ wheels = [ [[package]] name = "fastapi-mcp" -version = "0.1.5" +version = "0.1.6" source = { editable = "." } dependencies = [ { name = "fastapi" },