diff --git a/src/fastmcp/client/transports.py b/src/fastmcp/client/transports.py index 71aa8c855..3c067b14f 100644 --- a/src/fastmcp/client/transports.py +++ b/src/fastmcp/client/transports.py @@ -3,7 +3,6 @@ import asyncio import contextlib import datetime import os -import secrets import shutil import sys import warnings diff --git a/src/fastmcp/mcp_config.py b/src/fastmcp/mcp_config.py index fde181dc7..47e248c76 100644 --- a/src/fastmcp/mcp_config.py +++ b/src/fastmcp/mcp_config.py @@ -27,7 +27,7 @@ from __future__ import annotations import datetime import re from pathlib import Path -from typing import TYPE_CHECKING, Annotated, Any, Literal +from typing import TYPE_CHECKING, Annotated, Any, Literal, cast from urllib.parse import urlparse import httpx @@ -97,8 +97,12 @@ class _TransformingMCPServerMixin(FastMCPBaseModel): """Turn the Transforming MCPServer into a FastMCP Server and also return the underlying transport.""" from fastmcp import FastMCP from fastmcp.client import Client + from fastmcp.client.transports import ( + ClientTransport, # pyright: ignore[reportUnusedImport] + ) - transport: ClientTransport = self.to_transport() + transport: ClientTransport = super().to_transport() # pyright: ignore[reportUnknownMemberType, reportAttributeAccessIssue, reportUnknownVariableType] + transport = cast(ClientTransport, transport) client: Client[ClientTransport] = Client(transport=transport, name=client_name) diff --git a/src/fastmcp/server/proxy.py b/src/fastmcp/server/proxy.py index 4fcce6b69..9de5da845 100644 --- a/src/fastmcp/server/proxy.py +++ b/src/fastmcp/server/proxy.py @@ -1,7 +1,6 @@ from __future__ import annotations import inspect -import secrets import warnings from collections.abc import Awaitable, Callable from pathlib import Path @@ -550,7 +549,6 @@ class ProxyClient(Client[ClientTransportT]): | str, **kwargs, ): - if "name" not in kwargs: kwargs["name"] = self.generate_name() if "roots" not in kwargs: diff --git a/src/fastmcp/utilities/mcp_config.py b/src/fastmcp/utilities/mcp_config.py index a1f3888f3..32b5e88e8 100644 --- a/src/fastmcp/utilities/mcp_config.py +++ b/src/fastmcp/utilities/mcp_config.py @@ -1,6 +1,5 @@ from typing import Any -from fastmcp.client import Client from fastmcp.client.transports import ( ClientTransport, SSETransport, @@ -11,8 +10,8 @@ from fastmcp.mcp_config import ( MCPConfig, MCPServerTypes, ) -from fastmcp.server.server import FastMCP from fastmcp.server.proxy import ProxyClient +from fastmcp.server.server import FastMCP def mcp_config_to_servers_and_transports( diff --git a/tests/server/proxy/test_proxy_server.py b/tests/server/proxy/test_proxy_server.py index 12873b6a5..561353084 100644 --- a/tests/server/proxy/test_proxy_server.py +++ b/tests/server/proxy/test_proxy_server.py @@ -87,7 +87,7 @@ async def test_create_proxy(fastmcp_server): assert isinstance(server, FastMCPProxy) assert isinstance(server, FastMCP) - assert server.name.startswith("FastMCP-") + assert server.name.startswith("FastMCPProxy-") async def test_as_proxy_with_server(fastmcp_server): diff --git a/tests/server/test_mount.py b/tests/server/test_mount.py index 2defe3578..8fde83446 100644 --- a/tests/server/test_mount.py +++ b/tests/server/test_mount.py @@ -290,18 +290,21 @@ class TestMultipleServerMount: # Use an unreachable port unreachable_client = Client( - transport=SSETransport("http://127.0.0.1:9999/sse/") + transport=SSETransport("http://127.0.0.1:9999/sse/"), + name="unreachable_client", ) # Create a proxy server that will fail to connect - unreachable_proxy = FastMCP.as_proxy(unreachable_client) + unreachable_proxy = FastMCP.as_proxy( + unreachable_client, name="unreachable_proxy" + ) # Mount the unreachable proxy main_app.mount(unreachable_proxy, "unreachable") # All object types should work from working server despite unreachable proxy with caplog_for_fastmcp(caplog): - async with Client(main_app) as client: + async with Client(main_app, name="main_app_client") as client: # Test tools tools = await client.list_tools() tool_names = [tool.name for tool in tools] @@ -326,17 +329,17 @@ class TestMultipleServerMount: record.message for record in caplog.records if record.levelname == "WARNING" ] assert any( - "Failed to get tools from server: 'FastMCP', mounted at: 'unreachable'" + "Failed to get tools from server: 'unreachable_proxy', mounted at: 'unreachable'" in msg for msg in warning_messages ) assert any( - "Failed to get resources from server: 'FastMCP', mounted at: 'unreachable'" + "Failed to get resources from server: 'unreachable_proxy', mounted at: 'unreachable'" in msg for msg in warning_messages ) assert any( - "Failed to get prompts from server: 'FastMCP', mounted at: 'unreachable'" + "Failed to get prompts from server: 'unreachable_proxy', mounted at: 'unreachable'" in msg for msg in warning_messages )