Skip to content

Commit f9abb74

Browse files
authored
fix(qr-server): use stable mcp SDK from PyPI (#360)
* fix(qr-server): use stable mcp SDK from PyPI - Replace git-based mcp dependency with mcp>=1.26.0 from PyPI for stability - Remove TransportSecuritySettings that was blocking browser connections - Keep simple FastMCP initialization like other Python examples Fixes ModuleNotFoundError and 403 Forbidden errors when connecting from basic-host * fix(qr-server): use stable mcp SDK from PyPI - Replace git-based mcp dependency with mcp>=1.26.0 from PyPI - Add stateless_http=True for proper HTTP transport handling - Remove TransportSecuritySettings that blocked browser connections
1 parent aec5240 commit f9abb74

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

examples/qr-server/server.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# /// script
33
# requires-python = ">=3.10"
44
# dependencies = [
5-
# "mcp @ git+https://github.com/modelcontextprotocol/python-sdk@main",
5+
# "mcp>=1.26.0",
66
# "qrcode[pil]>=8.0",
77
# "uvicorn>=0.34.0",
88
# "starlette>=0.46.0",
@@ -19,15 +19,14 @@
1919
import qrcode
2020
import uvicorn
2121
from mcp.server.fastmcp import FastMCP
22-
from mcp.server.transport_security import TransportSecuritySettings
2322
from mcp import types
2423
from starlette.middleware.cors import CORSMiddleware
2524

2625
VIEW_URI = "ui://qr-server/view.html"
2726
HOST = os.environ.get("HOST", "0.0.0.0") # 0.0.0.0 for Docker compatibility
2827
PORT = int(os.environ.get("PORT", "3001"))
2928

30-
mcp = FastMCP("QR Code Server")
29+
mcp = FastMCP("QR Code Server", stateless_http=True)
3130

3231
# Embedded View HTML for self-contained usage (uv run <url> or unbundled)
3332
EMBEDDED_VIEW_HTML = """<!DOCTYPE html>
@@ -162,11 +161,7 @@ def view() -> str:
162161
mcp.run(transport="stdio")
163162
else:
164163
# HTTP mode for basic-host (default) - with CORS
165-
# Allow Docker bridge IP for container-to-host communication
166-
security = TransportSecuritySettings(
167-
allowed_hosts=["127.0.0.1:*", "localhost:*", "[::1]:*", "172.17.0.1:*"]
168-
)
169-
app = mcp.streamable_http_app(stateless_http=True, transport_security=security)
164+
app = mcp.streamable_http_app()
170165
app.add_middleware(
171166
CORSMiddleware,
172167
allow_origins=["*"],

0 commit comments

Comments
 (0)