Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions tests/integration/_support/mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from integration._support.asgi import asgi_server
from integration._support.client import Gateway, Scenario
from integration._support.database import read_rows
from mcp.server.fastmcp import FastMCP
from mcp.server.mcpserver import MCPServer
from mcp.server.transport_security import TransportSecuritySettings
from mcp_tests.mcp_e2e_upstream_server import add, multiply
from starlette.requests import Request
Expand All @@ -27,20 +27,19 @@ def drain(self) -> tuple[dict[str, object], ...]:

@contextmanager
def mcp_peer() -> Iterator[McpPeer]:
service: Final = FastMCP(
"integration-math",
stateless_http=True,
json_response=True,
transport_security=TransportSecuritySettings(enable_dns_rebinding_protection=False),
)
service: Final = MCPServer("integration-math")
service.add_tool(add)
service.add_tool(multiply)

@service.tool()
def fail() -> str:
raise ValueError("synthetic tool failure")

app: Final = service.streamable_http_app()
app: Final = service.streamable_http_app(
stateless_http=True,
json_response=True,
transport_security=TransportSecuritySettings(enable_dns_rebinding_protection=False),
)
observed: Final[queue.Queue[dict[str, object]]] = queue.Queue()

async def capture(scope: Scope, receive: Receive, send: Send) -> None:
Expand Down Expand Up @@ -94,9 +93,7 @@ def tool_names(gateway: Gateway, key: str, identity: str) -> dict[str, str]:
}


def call_tool(
gateway: Gateway, key: str, identity: str, name: str, arguments: dict[str, object]
) -> httpx.Response:
def call_tool(gateway: Gateway, key: str, identity: str, name: str, arguments: dict[str, object]) -> httpx.Response:
return gateway.client.post(
"/mcp-rest/tools/call",
headers={"x-litellm-api-key": key},
Expand Down
18 changes: 9 additions & 9 deletions tests/mcp_tests/mcp_e2e_upstream_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Deterministic upstream MCP server for the mcp e2e suite.

A tiny FastMCP server exposing `add` and `multiply` over streamable-http so the
A tiny MCP server exposing `add` and `multiply` over streamable-http so the
suite has a self-hosted, offline upstream to register and exercise. DNS-rebinding
protection is turned off because the litellm container reaches this over the
compose network by service name (`mcp-upstream:8090`), not localhost, and the
Expand All @@ -9,15 +9,10 @@

import os

from mcp.server.fastmcp import FastMCP
from mcp.server.mcpserver import MCPServer
from mcp.server.transport_security import TransportSecuritySettings

mcp: FastMCP = FastMCP(
"e2e-math",
host=os.getenv("MCP_HOST", "0.0.0.0"),
port=int(os.getenv("MCP_PORT", "8090")),
transport_security=TransportSecuritySettings(enable_dns_rebinding_protection=False),
)
mcp: MCPServer = MCPServer("e2e-math")


@mcp.tool()
Expand All @@ -33,7 +28,12 @@ def multiply(a: int, b: int) -> int:


def main() -> None:
mcp.run(transport="streamable-http")
mcp.run(
transport="streamable-http",
host=os.getenv("MCP_HOST", "0.0.0.0"),
port=int(os.getenv("MCP_PORT", "8090")),
transport_security=TransportSecuritySettings(enable_dns_rebinding_protection=False),
)


if __name__ == "__main__":
Expand Down
Loading