Repository navigation
Description
Summary
The XJ-03 Spotify Portal OAuth bridge (portal-bridge MCP server) fails to
complete the OAuth authorization-code flow because the derived redirect_uri
uses the wrong host.
mcp-remote derives the loopback redirect URI from the host it is told to
bind. When the bridge is launched with localhost, the derived redirect URI is
http://localhost:<port>/oauth/callback. The Portal authorization server
requires the loopback host to be the literal address 127.0.0.1, and rejects
localhost outright.
Observed behavior (live, against the production AS)
GET http://127.0.0.1:47290/oauth/callback -> HTTP 302 (accepted)
GET http://localhost:47290/oauth/callback -> HTTP 400 (rejected)
Root cause
Two independent defects combined:
-
Wrong redirect host. The bridge was configured to bind
localhost,
producing aredirect_uriwhose host islocalhostinstead of
127.0.0.1. The AS rejects it, so the authorization-code exchange never
completes. -
Wrong argument order. The corrected
mcp-remoteinvocation was not
being used — the bridge config passed its flags in an order that made
mcp-remoteparse the host argument as something else, silently falling
back tolocalhost.
Fix
Correct the portal-bridge entry so that it:
- passes the argument order
mcp-remoteactually expects, - binds explicitly to
127.0.0.1, - keeps
[email protected],http-only, and the production CIMD / resource, - uses
timeout_secs: 120.
The canonical config lives at ~/.kcode/mcp.json; scripts/portal-mcp-bridge.json
in this repo mirrors the same vector.
Acceptance criteria
- The bridge reaches the MCP server through the exact canonical config.
-
initializereturns thebackstageserver at the expected version. -
tools/listreturns the full tool inventory. -
auth.who-am-ireturns the operator identity. - The derived callback port matches the CIMD registration.
- No consent gate is triggered on a warm cache (cached token is reused).
- The regression test for the stub CIMD server asserts the corrected
argument order rather than a condition that passes vacuously.
Additional finding: refresh-token rotation
The Portal authorization server rotates refresh tokens. A refresh returns a
new access/refresh pair and immediately invalidates the token it consumed:
- refresh with RT-A -> HTTP 200
- reuse RT-A -> HTTP 400
invalid_grant - refresh with RT-B -> HTTP 200
A manual refresh whose result is not persisted therefore leaves a dead refresh
token on disk, and every subsequent launch fails with invalid_grant.
To make this safe, scripts/refresh-portal-token.py refreshes and persists the
rotated token pair atomically (temp file + os.replace), sets mode 0600,
never prints token material, and supports --check for a read-only report.
References
- PR: fix(portal): XJ-03 bridge — --host 127.0.0.1 fixes redirect_uri host mismatch #138
- Session record:
docs/sessions/2026-10-15-portal-xirp-resume/STATE.md(section 29)
Activity