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
This commit is contained in:
parent
aec5240f22
commit
f9abb74fc0
1 changed files with 3 additions and 8 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
# /// script
|
# /// script
|
||||||
# requires-python = ">=3.10"
|
# requires-python = ">=3.10"
|
||||||
# dependencies = [
|
# dependencies = [
|
||||||
# "mcp @ git+https://github.com/modelcontextprotocol/python-sdk@main",
|
# "mcp>=1.26.0",
|
||||||
# "qrcode[pil]>=8.0",
|
# "qrcode[pil]>=8.0",
|
||||||
# "uvicorn>=0.34.0",
|
# "uvicorn>=0.34.0",
|
||||||
# "starlette>=0.46.0",
|
# "starlette>=0.46.0",
|
||||||
|
|
@ -19,7 +19,6 @@ import base64
|
||||||
import qrcode
|
import qrcode
|
||||||
import uvicorn
|
import uvicorn
|
||||||
from mcp.server.fastmcp import FastMCP
|
from mcp.server.fastmcp import FastMCP
|
||||||
from mcp.server.transport_security import TransportSecuritySettings
|
|
||||||
from mcp import types
|
from mcp import types
|
||||||
from starlette.middleware.cors import CORSMiddleware
|
from starlette.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
|
|
@ -27,7 +26,7 @@ VIEW_URI = "ui://qr-server/view.html"
|
||||||
HOST = os.environ.get("HOST", "0.0.0.0") # 0.0.0.0 for Docker compatibility
|
HOST = os.environ.get("HOST", "0.0.0.0") # 0.0.0.0 for Docker compatibility
|
||||||
PORT = int(os.environ.get("PORT", "3001"))
|
PORT = int(os.environ.get("PORT", "3001"))
|
||||||
|
|
||||||
mcp = FastMCP("QR Code Server")
|
mcp = FastMCP("QR Code Server", stateless_http=True)
|
||||||
|
|
||||||
# Embedded View HTML for self-contained usage (uv run <url> or unbundled)
|
# Embedded View HTML for self-contained usage (uv run <url> or unbundled)
|
||||||
EMBEDDED_VIEW_HTML = """<!DOCTYPE html>
|
EMBEDDED_VIEW_HTML = """<!DOCTYPE html>
|
||||||
|
|
@ -162,11 +161,7 @@ if __name__ == "__main__":
|
||||||
mcp.run(transport="stdio")
|
mcp.run(transport="stdio")
|
||||||
else:
|
else:
|
||||||
# HTTP mode for basic-host (default) - with CORS
|
# HTTP mode for basic-host (default) - with CORS
|
||||||
# Allow Docker bridge IP for container-to-host communication
|
app = mcp.streamable_http_app()
|
||||||
security = TransportSecuritySettings(
|
|
||||||
allowed_hosts=["127.0.0.1:*", "localhost:*", "[::1]:*", "172.17.0.1:*"]
|
|
||||||
)
|
|
||||||
app = mcp.streamable_http_app(stateless_http=True, transport_security=security)
|
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=["*"],
|
allow_origins=["*"],
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue