Skip to content

docs(agent-ui): remove fictional /api/mcp/* routes, document the rest of the API - #4340

Merged
kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:docs/4255-agent-ui-api-docs
Sep 26, 2026
Merged

kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:docs/4255-agent-ui-api-docs

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

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/connectors when 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 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 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 regressions
  • python util/check_doc_links.py --internal-only — 1015 links checked, 0 broken

Fixes #4255

… 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
@github-actions github-actions Bot added documentation Documentation changes tests Test changes labels Sep 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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 evidence

N/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 details

Issues

🟡 Route-coverage guard ignores HTTP methods (tests/unit/chat/ui/test_route_doc_coverage.py:657)

_documented_paths() discards the verb from the accordion title ((?:GET|POST|…) is a non-capturing group) and _all_real_paths() never records route.methods. So <Accordion title="POST /api/mcp/servers"> passes both tests, because /api/mcp/servers exists as a GET. That is precisely the accordion this PR deletes — and it explains the "4 fictional" count in the test plan against 5 removed accordions.

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 _all_real_paths() emitting (m, normalised) for each m in methods excluding HEAD/OPTIONS, _in_scope() taking the tuple's path, and both assertions diffing tuple sets. test_walk_finds_the_whole_surface's > 100 threshold still holds on the per-method set.

🟢 Duplicate route walker (tests/unit/chat/ui/test_route_doc_coverage.py:620)

_all_api_routes in test_ui_request_guard.py:112 is the same walk, already returns {(path, frozenset(methods))}, and carries the FastAPI-version rationale. Lifting it into tests/unit/chat/ui/conftest.py and importing it here removes the fork and hands you the methods for free. It also avoids the from fastapi.routing import APIRoute import the original deliberately went without.

🟢 /v1/email exclusion comment is slightly off (tests/unit/chat/ui/test_route_doc_coverage.py:609)

"a separate process this backend never imports" — server.py:656 does import gaia.ui.email_sidecar.router; what it never imports is the email wheel. Worth a word change so a future reader doesn't chase a contradiction.

Strengths

  • The doc claims hold up. I diffed every (method, path) in the accordion titles against the @router.* decorators across all 14 routers: no fictional route, no missing route, no wrong verb. Spot-checks of the prose went the same way — the GAIA_MEMORY_ADMIN 403, the GAIA_DEBUG 404, the tunnel-active export refusal, the three false memory-settings defaults, and the X-Gaia-UI / Origin: null rationale all match the code (security.py's own module docstring, memory.py:513, connectors.py:596, agents.py:59).
  • test_walk_finds_the_whole_surface is the right instinct — a walk that silently finds nothing would make both coverage assertions vacuous, and this fails loudly instead. Same pattern the neighbouring guard test uses.
  • Hub-before-Agents ordering is documented where it matters, matching the GET /api/agents/{agent_id:path} greedy-match comment at server.py:629. That's the kind of non-obvious constraint a doc should carry.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 26, 2026
Merged via the queue into amd:main with commit 9daf949 Sep 26, 2026
29 of 30 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the docs/4255-agent-ui-api-docs branch September 26, 2026 05:04
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Sep 26, 2026
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]>
pull Bot pushed a commit to bhardwajRahul/gaia that referenced this pull request Sep 26, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Documentation changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs(agent-ui): about half the Agent UI API is undocumented, and five documented endpoints don't exist

2 participants