fix(CI3): bytt MCPToolset med FunctionTools for opax-mcp REST-kall
This commit is contained in:
parent
a095abd8bd
commit
d2a93979a4
|
|
@ -3,10 +3,10 @@ mcp_tools.py — MCP toolset integrations for OSVauco ADK agent.
|
||||||
Supports:
|
Supports:
|
||||||
- Google BigQuery MCP (via StreamableHTTP, uses ADC/OAuth)
|
- Google BigQuery MCP (via StreamableHTTP, uses ADC/OAuth)
|
||||||
- Google Maps MCP (via StreamableHTTP, uses API key)
|
- Google Maps MCP (via StreamableHTTP, uses API key)
|
||||||
- OPAX-MCP (Vauco intern CI/CD-kanal, uses MCP_SECRET + identity token)
|
- OPAX-MCP (Vauco intern CI/CD-kanal, FunctionTools over REST)
|
||||||
- Local stdio MCP server (dev/test only)
|
- Local stdio MCP server (dev/test only)
|
||||||
|
|
||||||
Requires: google-adk >= 2.0.0, google-auth
|
Requires: google-adk >= 2.0.0, google-auth, httpx
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
@ -54,30 +54,77 @@ def get_maps_mcp_toolset() -> MCPToolset:
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# --- OPAX-MCP (Vauco intern CI/CD-kanal) ---
|
|
||||||
|
# --- OPAX-MCP (Vauco intern CI/CD-kanal) via FunctionTools ---
|
||||||
|
# Bruker httpx over REST i stedet for MCPToolset siden opax-mcp er en
|
||||||
|
# vanlig FastAPI-server, ikke en MCP streamable-server med session-handshake.
|
||||||
|
|
||||||
OPAX_MCP_URL = os.environ.get("MCP_SERVER_URL", "https://opax-mcp-zjbqp3prqq-uc.a.run.app")
|
OPAX_MCP_URL = os.environ.get("MCP_SERVER_URL", "https://opax-mcp-zjbqp3prqq-uc.a.run.app")
|
||||||
|
|
||||||
def get_opax_mcp_toolset() -> MCPToolset:
|
def _opax_headers() -> dict:
|
||||||
"""
|
"""Bygg auth-headers for opax-mcp: Cloud Run identity token + MCP-nøkkel."""
|
||||||
Connect to Vauco sin interne opax-mcp server.
|
import google.auth.transport.requests
|
||||||
Auth: Cloud Run identity token (Bearer) + X-MCP-Key header fra Secret Manager.
|
|
||||||
"""
|
|
||||||
mcp_secret = os.environ.get("MCP_SECRET", "")
|
|
||||||
if not mcp_secret:
|
|
||||||
raise ValueError("MCP_SECRET env var ikke satt. Sjekk Secret Manager: mcp-server-key")
|
|
||||||
|
|
||||||
credentials, _ = google.auth.default()
|
credentials, _ = google.auth.default()
|
||||||
credentials.refresh(google.auth.transport.requests.Request())
|
credentials.refresh(google.auth.transport.requests.Request())
|
||||||
|
return {
|
||||||
return MCPToolset(
|
|
||||||
connection_params=StreamableHTTPConnectionParams(
|
|
||||||
url=f"{OPAX_MCP_URL}/mcp",
|
|
||||||
headers={
|
|
||||||
"Authorization": f"Bearer {credentials.token}",
|
"Authorization": f"Bearer {credentials.token}",
|
||||||
"X-MCP-Key": mcp_secret,
|
"X-MCP-Key": os.environ.get("MCP_SECRET", ""),
|
||||||
},
|
"Content-Type": "application/json",
|
||||||
|
}
|
||||||
|
|
||||||
|
def push_static(file_path: str, content: str, content_type: str = "text/html; charset=utf-8") -> dict:
|
||||||
|
"""Last opp en statisk fil (HTML/CSS/JS) til opax.vauco.no via GCS. file_path er relativ sti, f.eks. static/jason.html."""
|
||||||
|
import httpx
|
||||||
|
resp = httpx.post(
|
||||||
|
f"{OPAX_MCP_URL}/tools/push_static",
|
||||||
|
headers=_opax_headers(),
|
||||||
|
json={"file_path": file_path, "content": content, "content_type": content_type},
|
||||||
|
timeout=30,
|
||||||
)
|
)
|
||||||
|
return resp.json()
|
||||||
|
|
||||||
|
def get_build_status() -> dict:
|
||||||
|
"""Hent status på siste Cloud Build-kjøring for OSVauco. Returnerer status, commit, varighet og logg-URL."""
|
||||||
|
import httpx
|
||||||
|
resp = httpx.get(
|
||||||
|
f"{OPAX_MCP_URL}/tools/get_build_status",
|
||||||
|
headers=_opax_headers(),
|
||||||
|
timeout=15,
|
||||||
)
|
)
|
||||||
|
return resp.json()
|
||||||
|
|
||||||
|
def get_logs(lines: int = 50, severity: str = "DEFAULT") -> dict:
|
||||||
|
"""Hent siste Cloud Run-logger for osvauco-agent. severity: ERROR | WARNING | INFO | DEFAULT."""
|
||||||
|
import httpx
|
||||||
|
resp = httpx.get(
|
||||||
|
f"{OPAX_MCP_URL}/tools/get_logs",
|
||||||
|
headers=_opax_headers(),
|
||||||
|
params={"lines": lines, "severity": severity},
|
||||||
|
timeout=15,
|
||||||
|
)
|
||||||
|
return resp.json()
|
||||||
|
|
||||||
|
def deploy_service(branch: str = "main", trigger_id: str = "") -> dict:
|
||||||
|
"""Trigger Cloud Build for å bygge og deploye osvauco-agent. Krever HITL-godkjenning fra Chris."""
|
||||||
|
import httpx
|
||||||
|
resp = httpx.post(
|
||||||
|
f"{OPAX_MCP_URL}/tools/deploy_service",
|
||||||
|
headers=_opax_headers(),
|
||||||
|
json={"branch": branch, "trigger_id": trigger_id},
|
||||||
|
timeout=15,
|
||||||
|
)
|
||||||
|
return resp.json()
|
||||||
|
|
||||||
|
def get_opax_tools() -> list:
|
||||||
|
"""Returner liste med ADK FunctionTool-er for opax-mcp."""
|
||||||
|
from google.adk.tools import FunctionTool
|
||||||
|
return [
|
||||||
|
FunctionTool(func=push_static),
|
||||||
|
FunctionTool(func=get_build_status),
|
||||||
|
FunctionTool(func=get_logs),
|
||||||
|
FunctionTool(func=deploy_service),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
# --- Local stdio MCP server (dev/test only) ---
|
# --- Local stdio MCP server (dev/test only) ---
|
||||||
def get_local_stdio_toolset(command: str, args: list[str]) -> MCPToolset:
|
def get_local_stdio_toolset(command: str, args: list[str]) -> MCPToolset:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user