Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions apps/server/src/mcp/McpSessionRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,31 @@ it.effect("stores only a token hash, resolves the bearer token, and revokes by t
}),
);

it.effect("revokes one provider session without revoking another credential for the thread", () =>
Effect.gen(function* () {
const registry = yield* makeRegistry(() => 1_000);
const threadId = ThreadId.make("thread-selective-revocation");
const first = yield* registry.issue({
threadId,
providerInstanceId: ProviderInstanceId.make("codex"),
});
const second = yield* registry.issue({
threadId,
providerInstanceId: ProviderInstanceId.make("claudeAgent"),
});
const firstToken = first.config.authorizationHeader.replace(/^Bearer\s+/, "");
const secondToken = second.config.authorizationHeader.replace(/^Bearer\s+/, "");

yield* registry.revokeProviderSession(second.config.providerSessionId);

expect(yield* registry.resolve(firstToken)).toMatchObject({
threadId,
providerSessionId: first.config.providerSessionId,
});
expect(yield* registry.resolve(secondToken)).toBeUndefined();
}),
);

it.effect("builds MCP endpoints from the bound server host", () =>
Effect.gen(function* () {
const cases = [
Expand Down
12 changes: 12 additions & 0 deletions apps/server/src/mcp/McpSessionRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ export const issueActiveMcpCredential = (
.pipe(Effect.andThen(activeMcpSessionRegistry.issue(request)))
: Effect.sync((): McpIssuedCredential | undefined => undefined);

export const issueUncommittedMcpCredential = (
request: McpCredentialRequest,
): Effect.Effect<McpIssuedCredential | undefined> =>
activeMcpSessionRegistry
? activeMcpSessionRegistry.issue(request)
: Effect.sync((): McpIssuedCredential | undefined => undefined);

export const revokeActiveMcpProviderSession = (providerSessionId: string): Effect.Effect<void> =>
activeMcpSessionRegistry
? activeMcpSessionRegistry.revokeProviderSession(providerSessionId)
: Effect.void;

export const revokeActiveMcpThread = (threadId: ThreadId): Effect.Effect<void> =>
activeMcpSessionRegistry ? activeMcpSessionRegistry.revokeThread(threadId) : Effect.void;

Expand Down
25 changes: 16 additions & 9 deletions apps/server/src/orchestration/Layers/ProviderCommandReactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,16 +474,21 @@ const make = Effect.gen(function* () {
const startProviderSession = (input?: {
readonly resumeCursor?: unknown;
readonly provider?: ProviderDriverKind;
readonly activeSession?: "reuse" | "replace";
}) =>
providerService.startSession(threadId, {
providerService.startSession(
threadId,
...(preferredProvider ? { provider: preferredProvider } : {}),
providerInstanceId: desiredInstanceId,
...(effectiveCwd ? { cwd: effectiveCwd } : {}),
modelSelection: desiredModelSelection,
...(input?.resumeCursor !== undefined ? { resumeCursor: input.resumeCursor } : {}),
runtimeMode: desiredRuntimeMode,
});
{
threadId,
...(preferredProvider ? { provider: preferredProvider } : {}),
providerInstanceId: desiredInstanceId,
...(effectiveCwd ? { cwd: effectiveCwd } : {}),
modelSelection: desiredModelSelection,
...(input?.resumeCursor !== undefined ? { resumeCursor: input.resumeCursor } : {}),
runtimeMode: desiredRuntimeMode,
},
{ activeSession: input?.activeSession ?? "reuse" },
);

const bindSessionToThread = (session: ProviderSession) =>
Effect.gen(function* () {
Expand Down Expand Up @@ -564,7 +569,9 @@ const make = Effect.gen(function* () {
hasResumeCursor: resumeCursor !== undefined,
});
const restartedSession = yield* startProviderSession(
resumeCursor !== undefined ? { resumeCursor } : undefined,
resumeCursor !== undefined
? { resumeCursor, activeSession: "replace" }
: { activeSession: "replace" },
);
yield* Effect.logInfo("provider command reactor restarted provider session", {
threadId,
Expand Down
Loading
Loading