π The fast, Pythonic way to build MCP servers and clients.
Address CodeRabbit suggestions
Chris Guidry33f952fc4820
diff --git a/docs/servers/telemetry.mdx b/docs/servers/telemetry.mdxindex 7fc46d593..475bda055 100644--- a/docs/servers/telemetry.mdx+++ b/docs/servers/telemetry.mdx@@ -231,6 +231,7 @@ For testing, use the in-memory exporter:```pythonimport pytest+from collections.abc import Generatorfrom opentelemetry import tracefrom opentelemetry.sdk.trace import TracerProviderfrom opentelemetry.sdk.trace.export import SimpleSpanProcessor@@ -239,7 +240,7 @@ from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanEfrom fastmcp import FastMCP@pytest.fixture-def trace_exporter():+def trace_exporter() -> Generator[InMemorySpanExporter, None, None]:exporter = InMemorySpanExporter()provider = TracerProvider()provider.add_span_processor(SimpleSpanProcessor(exporter))@@ -247,7 +248,7 @@ def trace_exporter():yield exporterexporter.clear()-async def test_tool_creates_span(trace_exporter):+async def test_tool_creates_span(trace_exporter: InMemorySpanExporter) -> None:mcp = FastMCP("test")@mcp.tool()diff --git a/examples/diagnostics/server.py b/examples/diagnostics/server.pyindex 8aaaacbda..211c5d893 100644--- a/examples/diagnostics/server.py+++ b/examples/diagnostics/server.py@@ -1,8 +1,8 @@"""FastMCP Diagnostics Server - for testing tracing, errors, and observability."""+import asyncioimport osimport subprocess-import timefrom collections.abc import AsyncIteratorfrom contextlib import asynccontextmanagerfrom pathlib import Path@@ -43,13 +43,16 @@ async def lifespan(server: FastMCP) -> AsyncIterator[None]:stderr=subprocess.PIPE,)- # Wait for server to be ready- for _ in range(50):- try:- httpx.get(f"http://localhost:{ECHO_SERVER_PORT}/sse", timeout=0.1)- break- except Exception:- time.sleep(0.1)+ # Wait for server to be ready (async to avoid blocking event loop)+ async with httpx.AsyncClient() as client:+ for _ in range(50):+ try:+ await client.get(+ f"http://localhost:{ECHO_SERVER_PORT}/sse", timeout=0.1+ )+ break+ except Exception:+ await asyncio.sleep(0.1)# Mount proxy to the running echo serverecho_proxy = create_proxy(ECHO_SERVER_URL, name="Echo Proxy")@@ -59,7 +62,11 @@ async def lifespan(server: FastMCP) -> AsyncIterator[None]:yieldfinally:proc.terminate()- proc.wait(timeout=5)+ try:+ proc.wait(timeout=5)+ except subprocess.TimeoutExpired:+ proc.kill()+ proc.wait()mcp = FastMCP("Diagnostics Server", lifespan=lifespan)diff --git a/examples/run_with_tracing.py b/examples/run_with_tracing.pyindex 97d3b2d13..f49255e56 100755--- a/examples/run_with_tracing.py+++ b/examples/run_with_tracing.py@@ -19,7 +19,7 @@ import osimport sys-def main():+def main() -> None:if len(sys.argv) < 2:print(__doc__)sys.exit(1)@@ -51,7 +51,7 @@ def main():# Now run fastmcp CLIfrom fastmcp.cli.cli import app- sys.argv = ["fastmcp", "run"] + sys.argv[1:]+ sys.argv = ["fastmcp", "run", *sys.argv[1:]]app()diff --git a/loq.toml b/loq.tomlindex 8e3634046..2960baeaf 100644--- a/loq.toml+++ b/loq.toml@@ -288,7 +288,7 @@ max_lines = 1019[[rules]]path = "src/fastmcp/server/server.py"-max_lines = 3500+max_lines = 3000[[rules]]path = "tests/deprecated/test_import_server.py"