create-caspian-app 1.6.3 → 1.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.py +16 -1
- package/package.json +1 -1
package/dist/main.py
CHANGED
|
@@ -271,7 +271,10 @@ class MCPAuthMiddleware:
|
|
|
271
271
|
await self.app(scope, receive, send)
|
|
272
272
|
|
|
273
273
|
async def _deny(self, send: Send, status_code: int, message: str):
|
|
274
|
-
|
|
274
|
+
headers = {}
|
|
275
|
+
if status_code == 401:
|
|
276
|
+
headers["WWW-Authenticate"] = 'Bearer realm="Caspian MCP"'
|
|
277
|
+
response = JSONResponse({"error": message}, status_code=status_code, headers=headers)
|
|
275
278
|
|
|
276
279
|
async def receive_empty_body():
|
|
277
280
|
return {"type": "http.request", "body": b"", "more_body": False}
|
|
@@ -1510,6 +1513,18 @@ register_rpc_routes(app)
|
|
|
1510
1513
|
|
|
1511
1514
|
# Mount the FastMCP app at /mcp so the endpoint is exactly /mcp.
|
|
1512
1515
|
if mcp_app is not None:
|
|
1516
|
+
# Starlette's automatic mount redirect builds an absolute URL from the
|
|
1517
|
+
# incoming ASGI scheme. Some edge proxies do not forward that scheme, which
|
|
1518
|
+
# can make an HTTPS request redirect to HTTP. A relative Location header
|
|
1519
|
+
# preserves the client's original origin and keeps POST bodies with 307.
|
|
1520
|
+
@app.api_route(
|
|
1521
|
+
"/mcp",
|
|
1522
|
+
methods=["GET", "HEAD", "POST", "DELETE", "OPTIONS"],
|
|
1523
|
+
include_in_schema=False,
|
|
1524
|
+
)
|
|
1525
|
+
async def redirect_mcp_to_canonical_path():
|
|
1526
|
+
return RedirectResponse(url="/mcp/", status_code=307)
|
|
1527
|
+
|
|
1513
1528
|
app.mount("/mcp", mcp_app)
|
|
1514
1529
|
|
|
1515
1530
|
# ====
|