wrolpi/wrolpi_mcp/client.py
Roland ebbea75e26
ai: wrolpi_mcp becomes a thin proxy over /api/ai
Every MCP tool is now one /api/ai call with minimal text rendering;
the formatting, link building, and truncation logic it used to carry
untested lives (tested) in modules/ai.  Tool names are unchanged for
external clients; a source-scan test guards the names and that the
proxy only reaches /api/ai.  New lean blueprint endpoints back the two
tools that had no equivalent: GET archives/{id} (detail + snapshot
history) and GET videos/{id}/comments (paged author lines).  Paged
content is read up to the old 50k-char bound.  get_inventory_items now
takes the inventory slug (inventories are config-only; the old
numeric-id endpoint no longer exists).  This also brings wrolpi_mcp
into version control (venv/ is already gitignored).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-24 14:09:54 -06:00

28 lines
1.1 KiB
Python

"""HTTP client for the WROLPi API."""
import httpx
from wrolpi_mcp.config import API_BASE_URL, VERIFY_TLS
async def api_get(path: str, params: dict | None = None) -> dict:
"""GET request to the WROLPi API. Returns parsed JSON."""
async with httpx.AsyncClient(base_url=API_BASE_URL, verify=VERIFY_TLS, timeout=30.0) as client:
resp = await client.get(path, params=params)
resp.raise_for_status()
return resp.json()
async def api_post(path: str, json: dict | None = None) -> dict:
"""POST request to the WROLPi API. Returns parsed JSON."""
async with httpx.AsyncClient(base_url=API_BASE_URL, verify=VERIFY_TLS, timeout=30.0) as client:
resp = await client.post(path, json=json or {})
resp.raise_for_status()
return resp.json()
async def api_get_text(path: str) -> str:
"""GET request that returns raw text/HTML."""
async with httpx.AsyncClient(base_url=API_BASE_URL, verify=VERIFY_TLS, timeout=30.0) as client:
resp = await client.get(path)
resp.raise_for_status()
return resp.text