Remove MCP credential expiration

This commit is contained in:
Julius Marminge authored and Julius Marminge committed 2026-08-14 11:22:52 +02:00
1 parent 559e41a91f
commit be243ae91a
5 files changed
+14 -48

No files matched your search

@@ -171,6 +171,7 @@ Make process sharing a provider capability, not an orchestrator special case:
- when it is false, allocate an isolated provider session per app thread
- Codex enables sharing now; ACP, Claude, Cursor, and OpenCode remain isolated until their adapters are independently proven multiplex-safe
- model selection, cwd, runtime policy, and MCP authorization are applied on thread start/resume/fork rather than process launch
- MCP bearer credentials have no idle or maximum lifetime; reissue, thread detachment, provider-session release, and server shutdown revoke them explicitly
- the manager tracks the loaded native thread configuration per app thread, so reattachment or a model/cwd/policy change reapplies thread-scoped settings without redundantly resuming unchanged threads
- provider-session projections use explicit many-to-many thread bindings
- archiving, deleting, or switching one thread detaches that binding; it does not release a shared runtime used by sibling threads
@@ -21,10 +21,7 @@ const fakeEnvironment = ServerEnvironment.ServerEnvironment.of({
const makeRegistry = (now: () => number, httpServer = fakeHttpServer) =>
McpSessionRegistry.__testing
.make({
now,
livenessWindowMs: 100,
})
.make({ now })
.pipe(
Effect.provideService(HttpServer.HttpServer, httpServer),
Effect.provideService(ServerEnvironment.ServerEnvironment, fakeEnvironment),
@@ -75,7 +72,7 @@ it.effect("builds MCP endpoints from the bound server host", () =>
}),
);
it.effect("expires credentials once their session stops showing signs of life", () =>
it.effect("keeps credentials valid until they are explicitly revoked", () =>
Effect.gen(function* () {
let timestamp = 1_000;
const registry = yield* makeRegistry(() => timestamp);
@@ -84,7 +81,12 @@ it.effect("expires credentials once their session stops showing signs of life",
providerInstanceId: ProviderInstanceId.make("claude"),
});
const token = issued.config.authorizationHeader.replace(/^Bearer\s+/, "");
timestamp += 101;
const resolved = yield* registry.resolve(token);
expect(resolved?.providerSessionId).toBe(issued.config.providerSessionId);
timestamp += 365 * 24 * 60 * 60 * 1_000;
expect(yield* registry.resolve(token)).toEqual(resolved);
yield* registry.revokeProviderSession(issued.config.providerSessionId);
expect(yield* registry.resolve(token)).toBeUndefined();
}),
);
@@ -17,7 +17,6 @@ export const layer = Layer.succeed(
endpoint: "http://127.0.0.1/mcp",
authorizationHeader: `Bearer mcp-test:${threadId}`,
},
expiresAt: Number.MAX_SAFE_INTEGER,
}),
resolve: () => Effect.succeed(undefined),
revokeProviderSession: () => Effect.void,
+5 -40
View File
@@ -21,6 +21,7 @@ export interface McpIssuedCredential {
}
export interface McpSessionRegistryShape {
/** Credentials have no time-based expiry and must be explicitly revoked by their owner. */
readonly issue: (request: McpCredentialRequest) => Effect.Effect<McpIssuedCredential>;
readonly resolve: (
rawToken: string,
@@ -42,9 +43,7 @@ export class McpSessionRegistry extends Context.Service<
>()("t3/mcp/McpSessionRegistry") {}
interface CredentialRecord {
readonly tokenHash: string;
readonly scope: McpInvocationContext.McpInvocationScope;
readonly lastAliveAt: number;
}
interface RegistryState {
@@ -52,26 +51,9 @@ interface RegistryState {
}
export interface McpSessionRegistryOptions {
readonly livenessWindowMs?: number;
readonly now?: () => number;
}
/**
* How long a credential outlives the last sign of life from its provider
* session.
*
* Liveness is refreshed both by MCP traffic and by `touch` on every provider
* turn, so a session that is still doing work never expires no matter how long
* it goes between browser tool calls. This window therefore only bounds
* credentials whose session died without a clean stop — the normal paths
* (`stopSession`, `stopAll`) revoke eagerly and do not wait for it.
*
* The bound matters because `/mcp` is mounted outside the environment auth
* stack and is reachable on whatever host the server binds to, so this token is
* the only thing guarding the preview toolkit on a remote-reachable server.
*/
const DEFAULT_LIVENESS_WINDOW_MS = 24 * 60 * 60 * 1_000;
const bytesToHex = (bytes: Uint8Array): string =>
Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
@@ -97,7 +79,6 @@ const makeWithOptions = Effect.fn("McpSessionRegistry.make")(function* (
const httpServer = yield* HttpServer.HttpServer;
const state = yield* SynchronizedRef.make<RegistryState>({ records: new Map() });
const currentTimeMillis = options.now ? Effect.sync(options.now) : Clock.currentTimeMillis;
const livenessWindowMs = options.livenessWindowMs ?? DEFAULT_LIVENESS_WINDOW_MS;
const endpoint =
httpServer.address._tag === "TcpAddress"
? `http://${getHttpMcpEndpointHost(httpServer.address.hostname)}:${httpServer.address.port}/mcp`
@@ -108,15 +89,6 @@ const makeWithOptions = Effect.fn("McpSessionRegistry.make")(function* (
.digest("SHA-256", new TextEncoder().encode(token))
.pipe(Effect.map(bytesToHex), Effect.orDie);
const pruneDead = (records: ReadonlyMap<string, CredentialRecord>, timestamp: number) => {
const next = new Map(
Array.from(records).filter(
([, record]) => timestamp - record.lastAliveAt <= livenessWindowMs,
),
);
return next.size === records.size ? records : next;
};
const issue: McpSessionRegistryShape["issue"] = Effect.fn("McpSessionRegistry.issue")(
function* (request) {
const issuedAt = yield* currentTimeMillis;
@@ -132,8 +104,8 @@ const makeWithOptions = Effect.fn("McpSessionRegistry.make")(function* (
issuedAt,
};
yield* SynchronizedRef.update(state, ({ records }) => {
const next = new Map(pruneDead(records, issuedAt));
next.set(tokenHash, { tokenHash, scope, lastAliveAt: issuedAt });
const next = new Map(records);
next.set(tokenHash, { scope });
return { records: next };
});
return {
@@ -153,15 +125,8 @@ const makeWithOptions = Effect.fn("McpSessionRegistry.make")(function* (
function* (rawToken) {
if (rawToken.length === 0) return undefined;
const tokenHash = yield* hashToken(rawToken);
const timestamp = yield* currentTimeMillis;
return yield* SynchronizedRef.modify(state, ({ records }) => {
const current = pruneDead(records, timestamp);
const record = current.get(tokenHash);
if (!record) return [undefined, { records: current }] as const;
const next = new Map(current);
next.set(tokenHash, { ...record, lastAliveAt: timestamp });
return [record.scope, { records: next }] as const;
});
const record = (yield* SynchronizedRef.get(state)).records.get(tokenHash);
return record?.scope;
},
);
@@ -454,7 +454,6 @@ describe("orchestrator MCP toolkit", () => {
providerInstanceId: codexInstanceId,
capabilities: new Set(["orchestration"]),
issuedAt: 1,
expiresAt: Number.MAX_SAFE_INTEGER,
};
const invoke = (name: string, args: Record<string, unknown>) =>
server