This commit is contained in:
Timothy Jaeryang Baek committed 2026-10-31 08:06:23 +09:00
1 parent f9d1d8cdaf
commit b6c46ab00a
5 files changed
+245 -34

No files matched your search

+17 -5
View File
@@ -9,7 +9,6 @@ from __future__ import annotations
import copy
import json
import logging
from typing import Any
import httpx
@@ -66,9 +65,7 @@ async def fetch_openapi_spec(
# ── Schema conversion ──────────────────────────────────────
def _resolve_schema(
schema: dict, components: dict, resolved: set | None = None
) -> dict:
def _resolve_schema(schema: dict, components: dict, resolved: set | None = None) -> dict:
"""Recursively resolve $ref references in a JSON schema."""
if not schema:
return {}
@@ -168,7 +165,7 @@ def convert_openapi_to_tool_specs(openapi_spec: dict) -> list[dict]:
pschema = param.get("schema", {})
desc = pschema.get("description", "") or param.get("description", "")
if pschema.get("enum") and isinstance(pschema["enum"], list):
desc += f'. Possible values: {", ".join(str(v) for v in pschema["enum"])}'
desc += f". Possible values: {', '.join(str(v) for v in pschema['enum'])}"
prop = {
"type": pschema.get("type") or "string",
@@ -298,6 +295,21 @@ async def execute_openapi_tool(
json=body_params if body_params else None,
)
if resp.status_code >= 400:
body = resp.text.strip()
try:
body = json.dumps(resp.json(), indent=2, ensure_ascii=False)
except Exception:
pass
return json.dumps(
{
"error": f"HTTP {resp.status_code} from tool server",
"status_code": resp.status_code,
"body": body[:4000],
},
ensure_ascii=False,
)
# Try to parse as JSON
try:
data = resp.json()