fix(hub): correct tool calling logic
This commit is contained in:
parent
278a1cf6b9
commit
727b431d4b
|
|
@ -9,6 +9,7 @@ import os
|
|||
import logging
|
||||
import uuid
|
||||
import httpx
|
||||
import json
|
||||
import google.auth
|
||||
import google.auth.transport.requests
|
||||
from typing import Literal
|
||||
|
|
@ -93,15 +94,26 @@ def _mcp_headers() -> dict:
|
|||
}
|
||||
|
||||
|
||||
import json
|
||||
...
|
||||
def _call_tool(tool: str, params: dict = None) -> dict:
|
||||
req_id = str(uuid.uuid4())
|
||||
resp = httpx.post(
|
||||
f"{_OPAX_MCP_URL}/tools/call",
|
||||
f"{_OPAX_MCP_URL}/",
|
||||
headers=_mcp_headers(),
|
||||
json={"tool": tool, "params": params or {}},
|
||||
json={
|
||||
"jsonrpc": "2.0",
|
||||
"id": req_id,
|
||||
"method": "tools/call",
|
||||
"params": {"name": tool, "arguments": params or {}},
|
||||
},
|
||||
timeout=30,
|
||||
)
|
||||
resp.raise_for_status()
|
||||
return resp.json()
|
||||
rpc_resp = resp.json()
|
||||
if "error" in rpc_resp:
|
||||
raise Exception(f"Tool call error: {rpc_resp['error']}")
|
||||
return json.loads(rpc_resp["result"]["content"][0]["text"])
|
||||
|
||||
|
||||
def get_billing_summary() -> dict:
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import os
|
|||
import logging
|
||||
import uuid
|
||||
import httpx
|
||||
import json
|
||||
import google.auth
|
||||
import google.auth.transport.requests
|
||||
from typing import Literal
|
||||
|
|
@ -73,10 +74,26 @@ def _identity_token() -> str:
|
|||
def _mcp_headers() -> dict:
|
||||
return {"Authorization": f"Bearer {_identity_token()}", "X-MCP-Secret": _MCP_SECRET, "Content-Type": "application/json"}
|
||||
|
||||
import json
|
||||
...
|
||||
def _call_tool(tool: str, params: dict = None) -> dict:
|
||||
resp = httpx.post(f"{_OPAX_MCP_URL}/tools/call", headers=_mcp_headers(), json={"tool": tool, "params": params or {}}, timeout=30)
|
||||
req_id = str(uuid.uuid4())
|
||||
resp = httpx.post(
|
||||
f"{_OPAX_MCP_URL}/",
|
||||
headers=_mcp_headers(),
|
||||
json={
|
||||
"jsonrpc": "2.0",
|
||||
"id": req_id,
|
||||
"method": "tools/call",
|
||||
"params": {"name": tool, "arguments": params or {}},
|
||||
},
|
||||
timeout=30,
|
||||
)
|
||||
resp.raise_for_status()
|
||||
return resp.json()
|
||||
rpc_resp = resp.json()
|
||||
if "error" in rpc_resp:
|
||||
raise Exception(f"Tool call error: {rpc_resp['error']}")
|
||||
return json.loads(rpc_resp["result"]["content"][0]["text"])
|
||||
|
||||
def get_billing_summary() -> dict:
|
||||
"""Hent billing-oversikt for OSVauco (GCP-kostnader, token-forbruk)."""
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user