Repository navigation
docs(agent-ui): remove fictional /api/mcp/* routes, document the rest of the API - #4340
Conversation
… of the API A client following the docs to manage MCP servers got a 404 or 405: five /api/mcp/* endpoints it documented moved to /api/connectors when MCP-server lifecycle was folded into the connectors model, and the doc never updated. Three quarters of the real backend was also simply missing — all of connectors, goals, onboarding, schedules, and most of hub and memory — and the required X-Gaia-UI CSRF header was never mentioned, so a doc-following client's first mutating call got a silent 403. Added a route-coverage test that builds the real FastAPI app and diffs its route table against every documented endpoint, in both directions, so a route can't drift out of sync with the doc again. Fixes amd#4255
|
Verdict: Approve with suggestions. This fixes a real problem — the Agent UI API doc advertised five MCP-server management endpoints that return 404, left roughly three-quarters of the backend undocumented, and never mentioned the CSRF header a client needs on its first write. I cross-checked every endpoint the doc now lists against the actual backend, method by method, and found no mismatch in either direction. The doc is accurate as of this PR. One thing worth fixing before merge: the new guard test compares only URL paths, not the HTTP verb — so it can't catch the full bug it was written for. The PR's own test plan is the proof: five bogus endpoints were removed, but the test only flagged four. The one it missed was a bogus write to a URL that does exist as a read. Comparing the verb too closes that gap, and I confirmed the stricter check still passes cleanly against the doc as written here, so it's a safe tightening rather than a new round of doc work. Separately, a test in the same folder already walks the route table and already keeps the verbs — worth reusing rather than keeping a second hand-copied walker that drops them. Real-world evidenceN/A — docs and tests only; no runnable surface changed, and no evidence bundle was produced for this PR. Instead of relying on the description, I re-derived the backend's route table from the router source and diffed it against the doc myself: every documented endpoint exists with the verb claimed, and no endpoint is missing. The verdict rests on that check plus static review. 🔍 Technical detailsIssues🟡 Route-coverage guard ignores HTTP methods (
I ran the method-aware comparison against this PR's doc and both directions are empty, so the tightening is green today: def _documented_routes() -> set[tuple[str, str]]:
"""Every ``METHOD /path`` accordion title in the doc."""
text = DOC_PATH.read_text(encoding="utf-8")
return set(
re.findall(r'<Accordion title="(GET|POST|PUT|PATCH|DELETE) ([^"]+)"', text)
)…with 🟢 Duplicate route walker (
🟢 "a separate process this backend never imports" — Strengths
|
Searching files in the Agent UI could walk the entire home directory with no limit. On a real machine one search took minutes, and it never returned at all if one directory read blocked, for example on a cloud mount or a macOS privacy prompt. Now a search stops after 20,000 entries or about 10 seconds and returns what it found so far. The file browser says so when a search stopped early. ## Test plan - [x] `python -m pytest tests/integration/test_files_search_budget.py -q`: 5 passed. All 5 fail on `main`. - [x] `python -m pytest tests/integration/test_files_search_budget.py tests/integration/test_files_router.py tests/unit/chat/ui/test_models.py -q`: 111 passed, 1 skipped. On this Mac, `test_files_router.py`'s search tests hung past 10 minutes against the real home dir before this change; each now returns at the ~11 s cap. - [x] `cd src/gaia/apps/webui && npx vitest run`: 400 passed. The new truncation-note test fails without the component change. - [x] `cd src/gaia/apps/webui && npx tsc --noEmit`: clean - [x] black, isort, pylint clean on the changed Python files - [ ] Manual: Agent UI file browser, search a common name on a large home dir, and see the "Search stopped early" note - [ ] `gaia eval agent`: the Agent UI MCP server's `search_files` tool result gains a `truncated` field <details> <summary>🔍 Technical details</summary> - The walk now runs on a dedicated daemon thread instead of the default executor. A deadline checked between entries can't interrupt a blocked `opendir`, so the endpoint also stops waiting at budget + 1 s grace. A stuck thread exits once its read returns, and it never holds a shared executor slot. - The `$HOME` pass skips the four priority folders it already walked at greater depth. - `truncated` is true only when the entry cap or time budget cut the walk short, not when `max_results` was reached. - Overlaps: amd#4345 adds a generated-types drift check. If it merges first, `api.gen.ts` needs regenerating for `FileSearchResponse.truncated`. amd#4348 edits other parts of `routers/files.py` (the upload dir). New tests are in their own file to stay clear of amd#4344/amd#4348's edits to `test_files_router.py`. The docs edit is outside amd#4340's hunks. </details> Fixes amd#4352 Co-authored-by: Kalin Ovtcharov <[email protected]> Co-authored-by: Kalin Ovtcharov <[email protected]>
…kend (amd#4345) The Agent UI's TypeScript API types are written by hand, and nothing checked them against what the backend actually sends. Five had already drifted: settings were missing the agent mode, system status was missing the active profile, schedules were missing their parsed config, and three fields were typed as never-null although the backend sends null. Now CI fails and names the field whenever a hand-written type and the backend disagree, and those five types are fixed. Nothing changes for users; no UI code read the missing fields yet. This is the type-generation half of amd#4246. It also covers amd#3327's "snapshot the schema" and "check the TS types agree" items, but not its route `response_model` and conformance-test items. ## Test plan - [x] `python -m pytest tests/unit/chat/ui/test_export_openapi.py tests/unit/chat/ui/test_models.py tests/unit/chat/ui/test_server.py tests/unit/test_webui_agent_info_contract.py -q`: 170 passed - [x] `python -m gaia.ui.export_openapi --check` exits 0, also from another working directory with different env - [x] `cd src/gaia/apps/webui && npx tsc --noEmit`: clean. With `main`'s `types/index.ts` restored it fails five times, naming `agent_mode`, `active_profile`, `schedule_config`, `mail_provider`, `extension` - [x] `cd src/gaia/apps/webui && npm test`: 400 passed. Deleting one line from `api.gen.ts` fails the new generation test and `node scripts/gen-api-types.mjs --check` - [x] `npm run build` succeeds - [x] black, isort, pylint clean on the new Python files - [ ] CI: the Agent UI Vitest job's new Type-check step passes <details> <summary>🔍 Technical details</summary> **The pipeline:** `python -m gaia.ui.export_openapi` writes `src/types/api.schemas.json` from `create_app(":memory:").openapi()`, then `npm run gen:api-types` writes `src/types/api.gen.ts`. Each step has a stale check: a pytest test for the JSON and a Vitest test for the TS. `src/types/apiContract.ts` then compares 18 hand-written wire types with their generated counterparts at compile time. It flags backend fields missing from TS, TS fields never sent, and kind mismatches (string/number/boolean/null/array/object). It also has a self-test so it can't pass vacuously. `tsc` runs in the PyPI build on every PR, and now in the Agent UI Vitest job too. **Why not openapi-typescript:** it has a peer dependency on `typescript@^5` and uses the TS 5 compiler API. The Agent UI is on TypeScript 7, the native port, which has no JS API, so npm refuses the install. Its 6.x line has no TS dependency but pulls a vulnerable `undici`. `[email protected]` is pinned exact and adds no new `npm audit` findings (still 6, all pre-existing). The lockfile was written with npm 11 to keep its `libc` fields. **Only the component schemas are snapshotted, not the full OpenAPI doc.** Route docstring edits don't cause regenerations, since the types don't depend on them. **AgentInfo's 14 "TS-only" fields aren't drift.** They're Hub catalog fields from `merge_with_registry`, and `tests/unit/test_webui_agent_info_contract.py` (amd#3846) already checks each one against its emitter. The contract allowlists exactly those 14. **Not covered:** camelCase view models (`Message`, `AgentStep`, `CommandOutput`), and TS types whose routes have no `response_model` (tunnel, MCP, connectors). The latter are amd#3327's remaining work. **Things to know:** - CI installs unpinned `fastapi`/`pydantic`, as the email agent's `export_openapi --check` already does. The committed snapshot matches the current latest (fastapi 0.141.1, pydantic 2.13.5), but a future release that changes schema output would need a regenerate. - A dependabot bump of `json-schema-to-typescript` or its `prettier` dependency may need `npm run gen:api-types` run on its PR. **Overlap:** - amd#4325 removes `SystemStatus.device_supported` from the backend and TS. Whichever of the two PRs merges second must rerun the two regenerate commands. The fixture edits touch separate hunks. - Other open PRs that edit pydantic models in `src/gaia/ui/` need the same regenerate after this lands. - amd#4186 and amd#4340 don't touch these files. </details> Part of amd#4246 --------- Co-authored-by: Kalin Ovtcharov <[email protected]> Co-authored-by: Kalin Ovtcharov <[email protected]>
Summary
Following the Agent UI API docs to manage MCP servers got a client a 404: five documented
/api/mcp/*endpoints (register/enable/disable/delete a server, the catalog) moved to/api/connectorswhen MCP-server lifecycle folded into the connectors model, and the doc never caught up. About three-quarters of the real backend was also simply undocumented — all of connectors, goals, onboarding, schedules, and most of hub and memory — and the requiredX-Gaia-UICSRF header was never mentioned, so a doc-following client's first mutating call got a silent 403.Added a route-coverage test that builds the real FastAPI app and diffs its route table against every documented endpoint in both directions, so a route can't drift out of sync with the doc again the way this one did.
Overlaps with #4277 (also edits this file, in the Sessions accordion group) in file only — rebased on latest
origin/main, no shared lines.Test plan
pytest tests/unit/chat/ui/test_route_doc_coverage.py -q— 3 passed; confirmed it fails against the pre-fix doc (72 undocumented routes, 4 fictional/api/mcp/*ones)pytest tests/unit/chat/ui/ -q— 1038 passed, no regressionspython util/check_doc_links.py --internal-only— 1015 links checked, 0 brokenFixes #4255