Updates to tests

This commit is contained in:
William Easton 2025-08-24 10:59:01 -05:00
commit 185bb47713
No known key found for this signature in database
6 changed files with 17 additions and 14 deletions

View file

@ -3,7 +3,6 @@ import asyncio
import contextlib
import datetime
import os
import secrets
import shutil
import sys
import warnings

View file

@ -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)

View file

@ -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:

View file

@ -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(

View file

@ -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):

View file

@ -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
)