feat(mcp): migrate to mcp 2.x (MCPServer) (#10)
Co-authored-by: claude <[email protected]>
This commit was merged in pull request #10.
This commit is contained in:
+19
-13
@@ -25,9 +25,10 @@ import logging
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import Annotated
|
||||
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
|
||||
@@ -65,13 +66,12 @@ RRF_K = int(os.environ.get("RRF_K", "60"))
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# FastMCP setup.
|
||||
# MCPServer setup.
|
||||
#
|
||||
# stateless_http=True — every request creates an ephemeral session and
|
||||
# discards it on return. Critical for production: clients don't get
|
||||
# 404 storms when the container is recreated by Watchtower.
|
||||
# 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")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -1140,14 +1140,20 @@ def main() -> None:
|
||||
|
||||
if args.transport == "stdio":
|
||||
mcp.run()
|
||||
else:
|
||||
mcp.settings.host = args.host
|
||||
mcp.settings.port = args.port
|
||||
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"}:
|
||||
# DNS-rebinding protection defaults to localhost-only — disable for
|
||||
# container-network DNS hostnames. See PLAN.md "Hosting" notes.
|
||||
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)
|
||||
run_kwargs["transport_security"] = TransportSecuritySettings(
|
||||
enable_dns_rebinding_protection=False,
|
||||
)
|
||||
mcp.run(transport=args.transport, **run_kwargs)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user