Skip to content

Commit 185bb47

Browse files
committed
Updates to tests
1 parent f786bc4 commit 185bb47

File tree

6 files changed

+17
-14
lines changed

6 files changed

+17
-14
lines changed

src/fastmcp/client/transports.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import contextlib
44
import datetime
55
import os
6-
import secrets
76
import shutil
87
import sys
98
import warnings

src/fastmcp/mcp_config.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import datetime
2828
import re
2929
from pathlib import Path
30-
from typing import TYPE_CHECKING, Annotated, Any, Literal
30+
from typing import TYPE_CHECKING, Annotated, Any, Literal, cast
3131
from urllib.parse import urlparse
3232

3333
import httpx
@@ -97,8 +97,12 @@ def _to_server_and_underlying_transport(
9797
"""Turn the Transforming MCPServer into a FastMCP Server and also return the underlying transport."""
9898
from fastmcp import FastMCP
9999
from fastmcp.client import Client
100+
from fastmcp.client.transports import (
101+
ClientTransport, # pyright: ignore[reportUnusedImport]
102+
)
100103

101-
transport: ClientTransport = self.to_transport()
104+
transport: ClientTransport = super().to_transport() # pyright: ignore[reportUnknownMemberType, reportAttributeAccessIssue, reportUnknownVariableType]
105+
transport = cast(ClientTransport, transport)
102106

103107
client: Client[ClientTransport] = Client(transport=transport, name=client_name)
104108

src/fastmcp/server/proxy.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import inspect
4-
import secrets
54
import warnings
65
from collections.abc import Awaitable, Callable
76
from pathlib import Path
@@ -550,7 +549,6 @@ def __init__(
550549
| str,
551550
**kwargs,
552551
):
553-
554552
if "name" not in kwargs:
555553
kwargs["name"] = self.generate_name()
556554
if "roots" not in kwargs:

src/fastmcp/utilities/mcp_config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from typing import Any
22

3-
from fastmcp.client import Client
43
from fastmcp.client.transports import (
54
ClientTransport,
65
SSETransport,
@@ -11,8 +10,8 @@
1110
MCPConfig,
1211
MCPServerTypes,
1312
)
14-
from fastmcp.server.server import FastMCP
1513
from fastmcp.server.proxy import ProxyClient
14+
from fastmcp.server.server import FastMCP
1615

1716

1817
def mcp_config_to_servers_and_transports(

tests/server/proxy/test_proxy_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ async def test_create_proxy(fastmcp_server):
8787

8888
assert isinstance(server, FastMCPProxy)
8989
assert isinstance(server, FastMCP)
90-
assert server.name.startswith("FastMCP-")
90+
assert server.name.startswith("FastMCPProxy-")
9191

9292

9393
async def test_as_proxy_with_server(fastmcp_server):

tests/server/test_mount.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,18 +290,21 @@ def working_prompt() -> str:
290290

291291
# Use an unreachable port
292292
unreachable_client = Client(
293-
transport=SSETransport("http://127.0.0.1:9999/sse/")
293+
transport=SSETransport("http://127.0.0.1:9999/sse/"),
294+
name="unreachable_client",
294295
)
295296

296297
# Create a proxy server that will fail to connect
297-
unreachable_proxy = FastMCP.as_proxy(unreachable_client)
298+
unreachable_proxy = FastMCP.as_proxy(
299+
unreachable_client, name="unreachable_proxy"
300+
)
298301

299302
# Mount the unreachable proxy
300303
main_app.mount(unreachable_proxy, "unreachable")
301304

302305
# All object types should work from working server despite unreachable proxy
303306
with caplog_for_fastmcp(caplog):
304-
async with Client(main_app) as client:
307+
async with Client(main_app, name="main_app_client") as client:
305308
# Test tools
306309
tools = await client.list_tools()
307310
tool_names = [tool.name for tool in tools]
@@ -326,17 +329,17 @@ def working_prompt() -> str:
326329
record.message for record in caplog.records if record.levelname == "WARNING"
327330
]
328331
assert any(
329-
"Failed to get tools from server: 'FastMCP', mounted at: 'unreachable'"
332+
"Failed to get tools from server: 'unreachable_proxy', mounted at: 'unreachable'"
330333
in msg
331334
for msg in warning_messages
332335
)
333336
assert any(
334-
"Failed to get resources from server: 'FastMCP', mounted at: 'unreachable'"
337+
"Failed to get resources from server: 'unreachable_proxy', mounted at: 'unreachable'"
335338
in msg
336339
for msg in warning_messages
337340
)
338341
assert any(
339-
"Failed to get prompts from server: 'FastMCP', mounted at: 'unreachable'"
342+
"Failed to get prompts from server: 'unreachable_proxy', mounted at: 'unreachable'"
340343
in msg
341344
for msg in warning_messages
342345
)

0 commit comments

Comments
 (0)