Repository: tadata-org/fastapi_mcp
File: fastapi_mcp/http_tools.py (Python)

Code before:
            # Default to localhost with FastAPI default port
            port = 8000
            for route in app.routes:
                if hasattr(route, "app") and hasattr(route.app, "port"):
                    port = route.app.port
                    break
            base_url = f"http://localhost:{port}"

    # Normalize base URL
    if base_url.endswith("/"):
        base_url = base_url[:-1]

    # Process each path in the OpenAPI schema
    for path, path_item in openapi_schema.get("paths", {}).items():
        for method, operation in path_item.items():
            # Skip non-HTTP methods
            if method not in ["get", "post", "put", "delete", "patch"]:
                continue

            # Get operation metadata
            operation_id = operation.get("operationId")
            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,
                base_url=base_url,
                path=path,
                method=method,
                operation_id=operation_id,
                summary=operation.get("summary", ""),
                description=operation.get("description", ""),
                parameters=operation.get("parameters", []),
                request_body=operation.get("requestBody", {}),
                responses=operation.get("responses", {}),
                openapi_schema=openapi_schema,
                describe_all_responses=describe_all_responses,
                describe_full_response_schema=describe_full_response_schema,
            )


def create_http_tool(
    mcp_server: FastMCP,
    base_url: str,
    path: str,
    method: str,

Review comment (suggestion):
@shiraayal-tadata I would instead love to understand where is the name `handle_mcp_connection_mcp_get` coming from in the first place, and take it from there.
That way, if the python mcp library changes the name of that function, the fix would still work.
So I suggest searching for it in the implementation of mcp sdk. Most likely we can pull it from a function's `__name__` property or something like that.

Code after:

def create_http_tool(
    mcp_server: FastMCP,
    base_url: str,
    path: str,
    method: str,
    operation_id: str,
    summary: str,
    description: str,
    parameters: List[Dict[str, Any]],
    request_body: Dict[str, Any],
    responses: Dict[str, Any],
    openapi_schema: Dict[str, Any],
    describe_all_responses: bool,
    describe_full_response_schema: bool,
) -> None:
    """
    Create an MCP tool that makes an HTTP request to a FastAPI endpoint.

    Args:
        mcp_server: The MCP server to add the tool to
        base_url: Base URL for API requests
        path: API endpoint path
        method: HTTP method
        operation_id: Operation ID
        summary: Operation summary
        description: Operation description
        parameters: OpenAPI parameters
        request_body: OpenAPI request body
        responses: OpenAPI responses
        openapi_schema: The full OpenAPI schema
        describe_all_responses: Whether to include all possible response schemas in tool descriptions
        describe_full_response_schema: Whether to include full response schema in tool descriptions
    """
    # Build tool description
    tool_description = f"{summary}" if summary else f"{method.upper()} {path}"
    if description:
        tool_description += f"\n\n{description}"

    # Add response schema information to description
    if responses:
        response_info = "\n\n### Responses:\n"

        # Find the success response (usually 200 or 201)
        success_codes = ["200", "201", "202", 200, 201, 202]
        success_response = None
        for status_code in success_codes:
            if str(status_code) in responses:
                success_response = responses[str(status_code)]
                break