Require MCP registry for V2 provider sessions

This commit is contained in:
Julius Marminge authored and Julius Marminge committed 2026-08-07 13:18:41 +02:00
1 parent 14abe0feb7
commit ec79eb1411
10 files changed
+100 -37

No files matched your search

@@ -0,0 +1,27 @@
import { EnvironmentId } from "@t3tools/contracts";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import { McpSessionRegistry } from "./McpSessionRegistry.ts";
export const layer = Layer.succeed(
McpSessionRegistry,
McpSessionRegistry.of({
issue: ({ threadId, providerInstanceId }) =>
Effect.succeed({
config: {
environmentId: EnvironmentId.make("environment:mcp-test"),
threadId,
providerSessionId: `mcp-test:${threadId}`,
providerInstanceId,
endpoint: "http://127.0.0.1/mcp",
authorizationHeader: `Bearer mcp-test:${threadId}`,
},
expiresAt: Number.MAX_SAFE_INTEGER,
}),
resolve: () => Effect.succeed(undefined),
revokeProviderSession: () => Effect.void,
revokeThread: () => Effect.void,
revokeAll: Effect.succeed(undefined),
}),
);
@@ -29,6 +29,7 @@ import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
import * as VcsProcess from "../vcs/VcsProcess.ts";
import { OrchestratorV2 } from "./Orchestrator.ts";
import { OrchestrationV2LayerLive } from "./runtimeLayer.ts";
import { layer as mcpSessionRegistryTestLayer } from "../mcp/McpSessionRegistry.testkit.ts";
const liveAgentId = process.env.T3_ACP_REGISTRY_LIVE_AGENT_ID?.trim() || "devin";
const liveCommandPath = process.env.T3_ACP_REGISTRY_LIVE_COMMAND?.trim();
@@ -77,6 +78,7 @@ const providerInstanceRegistryLayer = ProviderInstanceRegistryHydrationLive.pipe
);
const liveLayer = OrchestrationV2LayerLive.pipe(
Layer.provide(mcpSessionRegistryTestLayer),
Layer.provide(SqlitePersistenceMemory),
Layer.provide(checkpointStoreLayer),
Layer.provide(serverConfigLayer),
@@ -27,6 +27,7 @@ import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
import * as VcsProcess from "../vcs/VcsProcess.ts";
import { OrchestratorV2 } from "./Orchestrator.ts";
import { OrchestrationV2LayerLive } from "./runtimeLayer.ts";
import { layer as mcpSessionRegistryTestLayer } from "../mcp/McpSessionRegistry.testkit.ts";
import { CURSOR_MODEL_SELECTION } from "./testkit/fixtures/shared.ts";
const serverConfigLayer = ServerConfig.layerTest(process.cwd(), {
@@ -60,6 +61,7 @@ const providerInstanceRegistryLayer = ProviderInstanceRegistryHydrationLive.pipe
);
const liveLayer = OrchestrationV2LayerLive.pipe(
Layer.provide(mcpSessionRegistryTestLayer),
Layer.provide(SqlitePersistenceMemory),
Layer.provide(checkpointStoreLayer),
Layer.provide(serverConfigLayer),
@@ -27,6 +27,7 @@ import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
import * as VcsProcess from "../vcs/VcsProcess.ts";
import { OrchestratorV2 } from "./Orchestrator.ts";
import { OrchestrationV2LayerLive } from "./runtimeLayer.ts";
import { layer as mcpSessionRegistryTestLayer } from "../mcp/McpSessionRegistry.testkit.ts";
import { GROK_MODEL_SELECTION } from "./testkit/fixtures/shared.ts";
const serverConfigLayer = ServerConfig.layerTest(process.cwd(), {
@@ -60,6 +61,7 @@ const providerInstanceRegistryLayer = ProviderInstanceRegistryHydrationLive.pipe
);
const liveLayer = OrchestrationV2LayerLive.pipe(
Layer.provide(mcpSessionRegistryTestLayer),
Layer.provide(SqlitePersistenceMemory),
Layer.provide(checkpointStoreLayer),
Layer.provide(serverConfigLayer),
@@ -304,9 +304,16 @@ function makeTestLayer(input: {
TestStoresLayer,
TestEventSinkLayer,
idAllocatorLayer,
TestMcpRegistryLayer,
providerSessionManagerLayerWithOptions({ idleTimeoutMs: input.idleTimeoutMs }).pipe(
Layer.provide(
Layer.mergeAll(registryLayer, TestEventSinkLayer, idAllocatorLayer, TestStoresLayer),
Layer.mergeAll(
registryLayer,
TestEventSinkLayer,
idAllocatorLayer,
TestMcpRegistryLayer,
TestStoresLayer,
),
),
),
);
@@ -322,7 +329,10 @@ const fakeEnvironment = ServerEnvironment.of({
getDescriptor: Effect.die("unused"),
});
const TestMcpRegistryLayer = McpSessionRegistry.layer.pipe(
const TestMcpRegistryLayer = Layer.effect(
McpSessionRegistry.McpSessionRegistry,
McpSessionRegistry.__testing.make(),
).pipe(
Layer.provide(Layer.succeed(HttpServer.HttpServer, fakeHttpServer)),
Layer.provide(Layer.succeed(ServerEnvironment, fakeEnvironment)),
Layer.provide(NodeServices.layer),
@@ -530,7 +540,7 @@ it.effect(
state,
idleTimeoutMs: 1_000,
mcpConfigs,
}).pipe(Layer.provideMerge(TestMcpRegistryLayer)),
}),
),
);
}),
@@ -190,6 +190,8 @@ type ProviderSessionEventSignal =
export interface ProviderSessionManagerV2LayerOptions {
readonly idleTimeoutMs?: number;
/** Test replay harnesses can omit T3's MCP server from provider protocol fixtures. */
readonly configureMcp?: boolean;
}
function releaseStatusFor(
@@ -236,12 +238,17 @@ export const layerWithOptions = (
): Layer.Layer<
ProviderSessionManagerV2,
never,
EventSinkV2 | IdAllocatorV2 | ProjectionStoreV2 | ProviderAdapterRegistryV2
| EventSinkV2
| IdAllocatorV2
| McpSessionRegistry.McpSessionRegistry
| ProjectionStoreV2
| ProviderAdapterRegistryV2
> =>
Layer.effect(
ProviderSessionManagerV2,
Effect.gen(function* () {
const registry = yield* ProviderAdapterRegistryV2;
const mcpSessionRegistry = yield* McpSessionRegistry.McpSessionRegistry;
const eventSink = yield* EventSinkV2;
const idAllocator = yield* IdAllocatorV2;
const projectionStore = yield* ProjectionStoreV2;
@@ -251,20 +258,22 @@ export const layerWithOptions = (
const openSemaphore = yield* Semaphore.make(1);
const idleTimeoutMs = Math.max(1, options.idleTimeoutMs ?? DEFAULT_IDLE_TIMEOUT_MS);
const prepareMcpSession = (threadId: ThreadId, providerInstanceId: ProviderInstanceId) =>
McpSessionRegistry.issueActiveMcpCredential({
threadId,
providerInstanceId,
}).pipe(
Effect.tap((credential) =>
credential === undefined
? Effect.void
: Effect.sync(() => McpProviderSession.setMcpProviderSession(credential.config)),
),
);
options.configureMcp === false
? Effect.sync(() => McpProviderSession.clearMcpProviderSession(threadId))
: mcpSessionRegistry.revokeThread(threadId).pipe(
Effect.andThen(mcpSessionRegistry.issue({ threadId, providerInstanceId })),
Effect.tap((credential) =>
Effect.sync(() => McpProviderSession.setMcpProviderSession(credential.config)),
),
);
const clearMcpSession = (threadId: ThreadId) =>
McpSessionRegistry.revokeActiveMcpThread(threadId).pipe(
Effect.tap(() => Effect.sync(() => McpProviderSession.clearMcpProviderSession(threadId))),
);
mcpSessionRegistry
.revokeThread(threadId)
.pipe(
Effect.tap(() =>
Effect.sync(() => McpProviderSession.clearMcpProviderSession(threadId)),
),
);
const publishToSubscribers = (
subscribers: Ref.Ref<ReadonlyMap<number, Queue.Queue<ProviderSessionEventSignal>>>,
@@ -17,6 +17,7 @@ import { ServerConfig } from "../config.ts";
import { GitCoreLive } from "../git/Layers/GitCore.ts";
import { SqlitePersistenceMemory } from "../persistence/Layers/Sqlite.ts";
import { ServerSettingsService } from "../serverSettings.ts";
import { layer as mcpSessionRegistryTestLayer } from "../mcp/McpSessionRegistry.testkit.ts";
import { ProviderInstanceRegistry } from "../provider/Services/ProviderInstanceRegistry.ts";
import type { ProviderInstance } from "../provider/ProviderDriver.ts";
import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
@@ -72,6 +73,7 @@ const TestProviderInstanceRegistry = Layer.succeed(ProviderInstanceRegistry, {
});
const TestLayer = OrchestrationV2LayerLive.pipe(
Layer.provide(mcpSessionRegistryTestLayer),
Layer.provide(SqlitePersistenceMemory),
Layer.provide(CheckpointStoreTestLayer),
Layer.provide(ServerConfigLayer),
@@ -13,6 +13,7 @@ import * as CheckpointStore from "../../checkpointing/CheckpointStore.ts";
import { ServerConfig } from "../../config.ts";
import { SqlitePersistenceMemory } from "../../persistence/Layers/Sqlite.ts";
import { ServerSettingsService } from "../../serverSettings.ts";
import { layer as mcpSessionRegistryTestLayer } from "../../mcp/McpSessionRegistry.testkit.ts";
import * as VcsDriverRegistry from "../../vcs/VcsDriverRegistry.ts";
import * as VcsProcess from "../../vcs/VcsProcess.ts";
import { layer as checkpointCaptureServiceLayer } from "../CheckpointCaptureService.ts";
@@ -35,7 +36,7 @@ import { layer as projectionStoreLayer } from "../ProjectionStore.ts";
import type { OrchestratorV2, OrchestratorV2Error } from "../Orchestrator.ts";
import { ProviderAdapterRegistryV2 } from "../ProviderAdapterRegistry.ts";
import { layer as providerEventIngestorLayer } from "../ProviderEventIngestor.ts";
import { layer as providerSessionManagerLayer } from "../ProviderSessionManager.ts";
import { layerWithOptions as providerSessionManagerLayerWithOptions } from "../ProviderSessionManager.ts";
import { layer as providerSwitchServiceLayer } from "../ProviderSwitchService.ts";
import { layer as providerTurnControlServiceLayer } from "../ProviderTurnControlService.ts";
import { layer as providerTurnStartServiceLayer } from "../ProviderTurnStartService.ts";
@@ -262,8 +263,18 @@ export function makeOrchestratorV2ReplayLayerWithRegistry<Error>(
idAllocatorLayer,
providerEventIngestorProvided,
);
const providerSessionManagerProvided = providerSessionManagerLayer.pipe(
Layer.provide(Layer.mergeAll(registryLayer, eventSinkProvided, idAllocatorLayer, storesLayer)),
const providerSessionManagerProvided = providerSessionManagerLayerWithOptions({
configureMcp: false,
}).pipe(
Layer.provide(
Layer.mergeAll(
registryLayer,
eventSinkProvided,
idAllocatorLayer,
mcpSessionRegistryTestLayer,
storesLayer,
),
),
);
const providerSwitchServiceProvided = providerSwitchServiceLayer.pipe(
Layer.provide(registryLayer),
+11 -7
View File
@@ -128,6 +128,7 @@ import * as T3ProjectFileLoader from "./project/T3ProjectFileLoader.ts";
import * as ProjectSetupScriptRunner from "./project/ProjectSetupScriptRunner.ts";
import * as RepositoryIdentityResolver from "./project/RepositoryIdentityResolver.ts";
import * as ServerEnvironment from "./environment/ServerEnvironment.ts";
import { layer as mcpSessionRegistryTestLayer } from "./mcp/McpSessionRegistry.testkit.ts";
import * as WorkspaceEntries from "./workspace/WorkspaceEntries.ts";
import * as WorkspaceFileSystem from "./workspace/WorkspaceFileSystem.ts";
import * as WorkspacePaths from "./workspace/WorkspacePaths.ts";
@@ -571,14 +572,17 @@ const buildAppUnderTest = (options?: {
disableLogger: true,
}).pipe(
Layer.provide(
Layer.mock(Keybindings.Keybindings)({
loadConfigState: Effect.succeed({
keybindings: [],
issues: [],
Layer.merge(
mcpSessionRegistryTestLayer,
Layer.mock(Keybindings.Keybindings)({
loadConfigState: Effect.succeed({
keybindings: [],
issues: [],
}),
streamChanges: Stream.empty,
...options?.layers?.keybindings,
}),
streamChanges: Stream.empty,
...options?.layers?.keybindings,
}),
),
),
Layer.provide(
Layer.mock(ProviderRegistry.ProviderRegistry)({
+4 -10
View File
@@ -430,14 +430,8 @@ export const makeRoutesLayer = Layer.mergeAll(
staticAndDevRouteLayer,
websocketRpcRouteLayer,
),
McpHttpServer.layer.pipe(Layer.provide(McpSessionRegistry.layer)),
).pipe(
Layer.provide(PreviewAutomationBroker.layer),
Layer.provide(ServerSelfUpdate.layer),
Layer.provide(commandReadinessLayer),
Layer.provide(browserApiCorsLayer),
Layer.provide(httpCompressionLayer),
);
McpHttpServer.layer,
).pipe(Layer.provide(browserApiCorsLayer));
export const makeServerLayer = Layer.unwrap(
Effect.gen(function* () {
@@ -641,8 +635,8 @@ export const makeServerLayer = Layer.unwrap(
);
return serverApplicationLayer.pipe(
Layer.provideMerge(runtimeServicesLive),
Layer.provide(activationLayer),
Layer.provideMerge(RuntimeServicesLive),
Layer.provideMerge(McpSessionRegistry.layer.pipe(Layer.provide(ServerEnvironment.layer))),
Layer.provideMerge(serverRelayBrokerTracingLayer),
Layer.provideMerge(HttpServerLive),
Layer.provide(ApplicationObservabilityLive),