Skip to content

fix: keep the /api prefix when proxying /api/logs/* - #74

Open
a-effort wants to merge 1 commit into
mainfrom
fix/bff-api-logs-proxy-prefix
Open

fix: keep the /api prefix when proxying /api/logs/*#74
a-effort wants to merge 1 commit into
mainfrom
fix/bff-api-logs-proxy-prefix

Conversation

@a-effort

@a-effort a-effort commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Problem

GET /api/logs/activity fails through the BFF. The catch-all proxy strips its own /api before forwarding, on the assumption (stated in the file) that mcpgateway mounts every router at the root:

// Wildcard capture excludes the leading '/api/'; FastAPI routes are
// mounted at root, so reattach a single leading slash.

log_search declares prefix="/api/logs", so /api/logs/activity was forwarded to /logs/activity upstream and 404d.

Probed against a live gateway:

path result
/api/logs/activity 401, route exists and needs auth
/logs/activity 404
/api/definitely-not-a-real-route 404, so the 401 above is meaningful

Why now

No caller had ever exercised an /api/logs/* route through the BFF. The other five log routes exist only as generated URL builders in contextForge.ts with no live callers, so the root-mount assumption was never tested. It surfaced the moment the Recent Activity feed asked for real data.

Fix

A toUpstreamPath() helper that keeps the prefix for logs/* and strips it for everything else, plus a correction to the now-false comment.

The exception is deliberately narrow. /api/logs is the only router in mcpgateway mounted under /api. The other 29 sit at the root or under root-relative prefixes (/v1/..., /admin/..., /observability/...) that already proxy correctly. That's recorded next to the constant so it doesn't get "simplified" back.

Tests

Two additions to server/test/proxy.test.ts: /api/logs/activity reaches upstream intact, and /api/logsearch still strips. The second guards the prefix match, since startsWith("logs") without the trailing slash would wrongly catch it.

BFF suite: 79 passed / 8 files. Server typecheck, eslint and prettier clean.

The catch-all proxy strips its own /api before forwarding, on the
assumption that mcpgateway mounts every router at the root. log_search
declares prefix="/api/logs", so /api/logs/activity was forwarded to
/logs/activity and 404d. It is the only router in mcpgateway mounted
under /api; the other 29 sit at the root.

No caller had exercised an /api/logs/* route through the BFF before —
the other five log routes exist only as generated URL builders with no
live callers — so this surfaced as soon as the activity feed asked for
real data.

Signed-off-by: Anna Effort <anna.effort@ibm.com>
@a-effort
a-effort force-pushed the fix/bff-api-logs-proxy-prefix branch from f6f3c36 to a2d00a3 Compare August 22, 2026 01:08
@a-effort
a-effort requested review from gandhipratik203, gcgoncalves, marekdano and vishu-bh and removed request for vishu-bh August 22, 2026 01:13
@a-effort
a-effort marked this pull request as ready for review August 22, 2026 01:14
@a-effort a-effort mentioned this pull request Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant