Skip to content

Let an owner reuse their revoked MCP connection's ID - #54

Merged
shuv1337 merged 1 commit into
v2from
shuv/connection-id-reuse-20261022
Oct 23, 2026
Merged

shuv1337 merged 1 commit into
v2from
shuv/connection-id-reuse-20261022

Conversation

@shuv1337

Copy link
Copy Markdown
Owner

Post-cutover backlog, item (c): let an owner reuse their revoked connection's ID. During the Mesh cutover, a revoked firstmate-mesh couldn't be recreated (409 ConnectionIdTaken), which forced firstmate-mesh-2. The ID is part of the MCP URL agents configure.

Cause

createMcpConnection (packages/mcp-auth/src/implementation/oauth.ts) answered 409 whenever a record with that ID existed, revoked or not. Grants, connection keys and PAT grant IDs refer to a connection only by its ID string, so simply un-revoking the record could have brought old credentials back.

Design (no schema change)

The record's createdAt now acts as the connection's generation.

  • Recreating a revoked ID (same user and organization only):
    • revoke every remaining grant that names the ID and delete their tokens;
    • re-enable the connection's OAuth resources;
    • rewrite the row with the new name and access, revoked: false, and a new createdAt later than the revocation.
  • OAuth grants: after a grant is stored, the connection is read again. If it's revoked or its generation changed, the grant is revoked and the request gets 403. This covers an authorization in flight during a revoke.
  • Connection keys (bearer-access.ts): a key bound to the connection is refused if it was created before the connection's createdAt. Creating a connection deletes keys older than it, and revoking still deletes them all.
  • PAT grant IDs (approvals, event subscriptions): they carry the generation. A mismatch is refused; IDs issued before this change have none and are still accepted.
  • Duplicates:
    • Live ID, same user, identical body: returns the existing connection, as before.
    • Live ID, different body: now 409. It used to return the existing connection unchanged, silently ignoring the new body.
    • Another user's ID, live or revoked: still 409.

Rebased on #53 (per-key revoke). The one conflict was in the revoke-all-keys endpoint; it keeps this PR's generation-aware filter.

Tests

  • connection-keys.spec.ts:
    • after a revoke, recreating with the same ID returns 200 with a later createdAt;
    • both pre-revoke keys get 401 at the connection URL and at plain /mcp, while a new key works;
    • an identical retry is unchanged, and a different body gets 409;
    • another member gets 409 on the owner's ID, live or revoked.
  • mcp-connections.spec.ts: after recreating, the old OAuth token's call fails and its refresh is refused, while a new authorization at the same URL works.
  • Before the fix: both fail with 409 where 200 is expected.
  • On the combined tree after the rebase, the connection-related scenarios on self-host: 24 passed (connection-keys, mcp-connections, connection-api-keys, oauth clients, app account links and others).
  • Not covered by tests: old keys are already deleted at revoke, so the key-age check and the in-flight grant race can't be produced in a scenario. They're reasoned, not tested.
  • bun run check passes.
connection-keys.spec.ts
mcp-connections.spec.ts
connection-api-keys.spec.ts

A revoked connection's ID was permanently taken, so a cutover had to move agents
to a new URL. Its owner can now create a connection with that ID. Revival replaces
the record with a new generation, the record's createdAt. It revokes every grant
that names the ID again and re-enables the connection's OAuth resources.
Connection keys minted before the new generation, and PAT grant IDs carrying an
older one, are refused and swept. A grant stored while its connection was revoked
or replaced is revoked at creation. Creating a live connection again is idempotent
only for an identical name and access; another body, or another user's ID, stays
ConnectionIdTaken.
@shuv1337
shuv1337 merged commit bc24532 into v2 Oct 23, 2026
3 checks passed
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