feat(mcp): migrate to mcp 2.x (MCPServer), replacing the <2 ceiling

Pilot for moving the fleet off mcp 1.x before it goes away. The port is
three mechanical changes plus docs:

  - import:      mcp.server.fastmcp.FastMCP -> mcp.server.mcpserver.MCPServer
  - constructor: transport options moved off it; MCPServer(name) only
  - run():       host/port/stateless_http/transport_security are now kwargs,
                 and `mcp.settings` no longer exists

`@mcp.tool()` is unchanged — all six tools keep their decorators and
signatures untouched.

Verified, not assumed:

1. tools/list is byte-for-byte identical between mcp 1.27.1 and 2.x
   (6 tools, same names, same inputSchema properties and required lists,
   dumped with by_alias=True so the comparison is in wire format). This
   was the real risk: 2.x switched the protocol types to snake_case
   internally, and tool schemas are what decide routing.
2. The server boots for real over streamable-http with stateless_http=True
   and DNS-rebinding protection disabled, and answers initialize 200 with
   the same capability set.
3. CI now runs `import docs_mcp.server` inside the built image before push.

One behavior change: an unversioned server reports serverInfo.version ""
under 2.x instead of the SDK version, so Drawbar will see an empty version
string. Cosmetic — left as-is rather than inventing a version scheme.

Dependency note: 2.x has no [fastmcp] extra, replaces httpx with httpx2,
and requires opentelemetry-api. Our own httpx>=0.27 pin is unaffected —
httpx2 is a separate distribution.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FnVuG79cYPcRLTp4pC8ujR
This commit is contained in:
2026-09-10 14:22:00 -04:00
co-authored by Claude Opus 5
parent e5ec32bff6
commit 2bba426cee
4 changed files with 29 additions and 14 deletions
+21 -9
View File
@@ -25,7 +25,8 @@ import re
from pathlib import Path
from typing import Annotated, Any
from mcp.server.fastmcp import FastMCP
from mcp.server.mcpserver import MCPServer
from mcp.server.transport_security import TransportSecuritySettings
from pydantic import Field
from .usage import TimedCall
@@ -57,9 +58,12 @@ RRF_K = int(os.environ.get("RRF_K", "60"))
# ---------------------------------------------------------------------------
# FastMCP setup.
# MCPServer setup.
#
# mcp 2.x moved every transport option (stateless_http, host, port,
# transport_security, ...) off the constructor and onto run() — see main().
# ---------------------------------------------------------------------------
mcp = FastMCP(f"{PRODUCT_NAME}-docs", stateless_http=True)
mcp = MCPServer(f"{PRODUCT_NAME}-docs")
# ---------------------------------------------------------------------------
@@ -1196,12 +1200,20 @@ def main() -> None:
if args.transport == "stdio":
mcp.run()
else:
mcp.settings.host = args.host
mcp.settings.port = args.port
if os.environ.get("MCP_DISABLE_DNS_REBINDING_PROTECTION") in {"1", "true", "yes"}:
mcp.settings.transport_security.enable_dns_rebinding_protection = False
mcp.run(transport=args.transport)
return
# mcp 2.x: transport options are run() kwargs, and `mcp.settings` is gone.
run_kwargs: dict[str, Any] = {"host": args.host, "port": args.port}
if args.transport == "streamable-http":
# Was a constructor arg under 1.x. Required in prod — see CLAUDE.md.
run_kwargs["stateless_http"] = True
if os.environ.get("MCP_DISABLE_DNS_REBINDING_PROTECTION") in {"1", "true", "yes"}:
# We're only reachable as `seed-mcp:8080` on Drawbar's internal docker
# network, never published to a host port.
run_kwargs["transport_security"] = TransportSecuritySettings(
enable_dns_rebinding_protection=False,
)
mcp.run(transport=args.transport, **run_kwargs)
if __name__ == "__main__":