Atlas / services /mcp_client.py
a-zamfir's picture
initial atlas commit
f26de06
raw
history blame contribute delete
942 Bytes
# services/mcp_client.py
import requests
from typing import Any, Dict, List
from config.settings import Settings
class MCPClient:
def __init__(self, base_url: str | None = None):
settings = Settings()
self.base_url = (base_url or settings.mcp_server_url).rstrip("/")
def list_tools(self) -> List[Dict[str, Any]]:
resp = requests.get(f"{self.base_url}/tools", timeout=5)
resp.raise_for_status()
data = resp.json()
return data.get("tools", [])
def call_tool(self, name: str, arguments: Dict[str, Any] | None = None) -> Any:
payload = {"name": name, "arguments": arguments or {}}
resp = requests.post(f"{self.base_url}/tools/call", json=payload, timeout=30)
resp.raise_for_status()
data = resp.json()
if not data.get("success", False):
raise RuntimeError(data.get("error", "Unknown tool error"))
return data.get("result")