fix(opax-mcp): bruk X-MCP-Secret header — ikkje Authorization (kolliderer med Cloud Run IAM)
This commit is contained in:
parent
27290b2ab6
commit
7d4b475189
|
|
@ -1,6 +1,6 @@
|
||||||
"""opax-mcp — MCP tool server for OPAX/Vauco
|
"""opax-mcp — MCP tool server for OPAX/Vauco
|
||||||
Transport: HTTP (FastAPI + uvicorn) for Cloud Run
|
Transport: HTTP (FastAPI + uvicorn) for Cloud Run
|
||||||
Alle tools kalles av Jason/Emma internt — ingen 3part.
|
Auth: Cloud Run IAM (Authorization header) + X-MCP-Secret header for tool-level auth
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import httpx
|
import httpx
|
||||||
|
|
@ -17,13 +17,13 @@ GITHUB_PAT = os.environ.get("GITHUB_PAT", "")
|
||||||
GOOGLE_CLOUD_PROJECT = os.environ.get("GOOGLE_CLOUD_PROJECT", "propane-will-491900-m5")
|
GOOGLE_CLOUD_PROJECT = os.environ.get("GOOGLE_CLOUD_PROJECT", "propane-will-491900-m5")
|
||||||
|
|
||||||
|
|
||||||
def _auth_check(authorization: Optional[str]):
|
def _auth_check(x_mcp_secret: Optional[str]):
|
||||||
if MCP_SECRET and authorization != f"Bearer {MCP_SECRET}":
|
if MCP_SECRET and x_mcp_secret != MCP_SECRET:
|
||||||
raise HTTPException(status_code=401, detail="Unauthorized")
|
raise HTTPException(status_code=401, detail="Unauthorized")
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Health
|
# Health — ingen auth, Cloud Run trenger denne
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
@app.get("/health")
|
@app.get("/health")
|
||||||
|
|
@ -43,9 +43,9 @@ class ToolRequest(BaseModel):
|
||||||
@app.post("/tools/call")
|
@app.post("/tools/call")
|
||||||
async def call_tool(
|
async def call_tool(
|
||||||
req: ToolRequest,
|
req: ToolRequest,
|
||||||
authorization: Optional[str] = Header(default=None)
|
x_mcp_secret: Optional[str] = Header(default=None)
|
||||||
):
|
):
|
||||||
_auth_check(authorization)
|
_auth_check(x_mcp_secret)
|
||||||
handler = TOOLS.get(req.tool)
|
handler = TOOLS.get(req.tool)
|
||||||
if not handler:
|
if not handler:
|
||||||
raise HTTPException(status_code=404, detail=f"Unknown tool: {req.tool}")
|
raise HTTPException(status_code=404, detail=f"Unknown tool: {req.tool}")
|
||||||
|
|
@ -54,8 +54,8 @@ async def call_tool(
|
||||||
|
|
||||||
|
|
||||||
@app.get("/tools")
|
@app.get("/tools")
|
||||||
async def list_tools(authorization: Optional[str] = Header(default=None)):
|
async def list_tools(x_mcp_secret: Optional[str] = Header(default=None)):
|
||||||
_auth_check(authorization)
|
_auth_check(x_mcp_secret)
|
||||||
return {"tools": list(TOOLS.keys())}
|
return {"tools": list(TOOLS.keys())}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user