mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-11-29 06:21:26 +01:00
Adds a workflow that drives this checkout's FastMCP through the latest releases of two major consumers, modeled on uv's ecosystem tests. pydantic-ai's MCPToolset is built on fastmcp.Client, so it runs in the project environment and connects in-process, over stdio, and over streamable HTTP. langchain-mcp-adapters pins mcp<2, so it cannot share an environment with FastMCP 4; it runs in its own environment and reaches the server over stdio and HTTP, covering handshake-era clients. Each path runs an agent loop with a scripted model, direct tool calls, structured output, tool errors, elicitation, progress, logging, resources, resource templates, and prompts. Claude-Session: https://claude.ai/code/session_01KfHgVhbYEhBCC5eSeqGiuG Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
"""Serve server.py over streamable HTTP in a subprocess for the length of a `with` block."""
|
|
|
|
import os
|
|
import socket
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
from collections.abc import Iterator
|
|
from contextlib import contextmanager
|
|
from pathlib import Path
|
|
|
|
SERVER = Path(__file__).with_name("server.py")
|
|
|
|
|
|
def free_port() -> int:
|
|
with socket.socket() as sock:
|
|
sock.bind(("127.0.0.1", 0))
|
|
return sock.getsockname()[1]
|
|
|
|
|
|
@contextmanager
|
|
def http_server(python: list[str]) -> Iterator[str]:
|
|
port = free_port()
|
|
proc = subprocess.Popen([*python, str(SERVER), "http", str(port)], env=os.environ)
|
|
try:
|
|
deadline = time.monotonic() + 30
|
|
while time.monotonic() < deadline:
|
|
if proc.poll() is not None:
|
|
sys.exit(f"server exited with {proc.returncode}")
|
|
try:
|
|
socket.create_connection(("127.0.0.1", port), timeout=0.2).close()
|
|
break
|
|
except OSError:
|
|
time.sleep(0.1)
|
|
else:
|
|
sys.exit("server did not start listening within 30s")
|
|
yield f"http://127.0.0.1:{port}/mcp"
|
|
finally:
|
|
proc.terminate()
|
|
proc.wait(timeout=10)
|