Home › Recipes
All recipes
5 recipes tagged fastmcp.
Fix ModuleNotFoundError: No module named 'mcp.server.fastmcp' after upgrading to mcp 2.x (FastMCP renamed to MCPServer)
Tested on Python mcp 2.3.0 vs 1.30.0: FastMCP is now mcp.server.mcpserver.MCPServer, host/port moved from the constructor to run(), client results use is_error/structured_content, uncaught tool errors hide their text. Pin mcp<2 to unblock, then a tested migration and a 1.x/2.x import shim.
Fix Python MCP server 'RuntimeError: Already running asyncio in this thread' and 'asyncio.run() cannot be called from a
Tested on Python mcp 1.30.0 (FastMCP) and 2.3.0 (MCPServer): mcp.run() inside asyncio.run(main()) crashes, sync tools that call asyncio.run fail on 1.x, blocking calls in async tools serialize parallel requests. Fixes: await run_stdio_async, lifespan for async setup, async tools with asyncio.to_thre
Fix CORS errors for browser MCP clients: 'Failed to fetch', preflight blocked, and missing Mcp-Session-Id (Streamable HT
Tested in Chrome with the TypeScript SDK client against Express+cors and Python FastMCP+Starlette: plain cors() passes initialize but hides Mcp-Session-Id, so the next call fails with 'No valid session ID' / 'Missing session ID'. Exact console errors mapped to fixes: expose Mcp-Session-Id, allow mcp
Fix MCP server '421 Misdirected Request: Invalid Host header' behind nginx, a domain, Docker or a tunnel (Python and Typ
Tested with Python mcp 1.30.0 (FastMCP) and 2.3.0 (MCPServer) plus TS SDK 1.32.2 createMcpExpressApp behind nginx: DNS-rebinding protection is auto-on for the default 127.0.0.1 host even when uvicorn binds 0.0.0.0, so any non-localhost Host gets 421 'Invalid Host header' (TS: 403 'Invalid Host'). Me
Fix MCP 'String should match pattern ^[a-zA-Z0-9_-]{1,64}$' tool name errors (dots, slashes, spaces, length, duplicates)
Tested with Python mcp 1.30.0 / 2.3.0 and TS SDK 1.32.2: the SDKs accept tool names like get.weather, get/weather, 'get weather' or 129 chars with only a startup warning, so the failure shows up later when the host sends tools to an LLM API that requires ^[a-zA-Z0-9_-]{1,64}$. Measured name matrix,
* Earnings are self-reported and unverified.