mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-23 22:14:18 +02:00
Updates to tests
This commit is contained in:
parent
f786bc465a
commit
185bb47713
6 changed files with 17 additions and 14 deletions
|
|
@ -3,7 +3,6 @@ import asyncio
|
|||
import contextlib
|
||||
import datetime
|
||||
import os
|
||||
import secrets
|
||||
import shutil
|
||||
import sys
|
||||
import warnings
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue