@devries-cameron20 / t3code Mirror · read-only / commits / 94a53a2f79
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 09:30 UTC

fix(acp): Copilot threads get T3's tools (#26968)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Radu-Stefan Popa committed Oct 31, 2026 at 10:48 UTC 94a53a2f79c3b61f3a94ac6a97311ce0deb69306
5 files changed +179 -12
apps/server/scripts/acp-mock-agent.ts
+9 -1
@@ -61,6 +61,7 @@ const promptDelayMs = Number(process.env.T3_ACP_PROMPT_DELAY_MS ?? "0");
61 const terminalOutputBytes = Number(process.env.T3_ACP_EMIT_TERMINAL_OUTPUT_BYTES ?? "0");
62 const supportsSessionLifecycle = process.env.T3_ACP_SESSION_LIFECYCLE === "1";
63 const supportsAcpMcp = process.env.T3_ACP_MCP_ACP === "1";
64 +const supportsHttpMcp = process.env.T3_ACP_MCP_HTTP === "1";
65 const supportsV2Management = process.env.T3_ACP_V2_MANAGEMENT === "1";
66 const advertisedAuthMethodId = process.env.T3_ACP_AUTH_METHOD_ID?.trim();
67 const initializeAuthMethodId =
@@ -502,7 +503,14 @@ const program = Effect.gen(function* () {
503 session: {
504 ...(supportsSessionLifecycle ? { fork: {}, additionalDirectories: {} } : {}),
505 ...(supportsV2Management ? { delete: {} } : {}),
505 - ...(supportsAcpMcp ? { mcp: { acp: {} } } : {}),
506 + ...(supportsAcpMcp || supportsHttpMcp
507 + ? {
508 + mcp: {
509 + ...(supportsAcpMcp ? { acp: {} } : {}),
510 + ...(supportsHttpMcp ? { http: {} } : {}),
511 + },
512 + }
513 + : {}),
514 },
515 ...(supportsV2Management ? { providers: {} } : {}),
516 },
apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts
+132 -1
@@ -1,6 +1,7 @@
1 import * as NodeServices from "@effect/platform-node/NodeServices";
2 import { assert, describe, it } from "@effect/vitest";
3 import {
4 + EnvironmentId,
5 MessageId,
6 NodeId,
7 ProjectId,
@@ -12,7 +13,7 @@ import {
13 ThreadId,
14 } from "@t3tools/contracts";
15 import { pendingBackgroundTurnItems } from "@t3tools/shared/orchestrationV2PendingBackgroundWork";
15 -import { resolveSelfInvocation } from "@t3tools/shared/nodeRuntime";
16 +import { resolveSelfInvocation, selfInvocationArgs } from "@t3tools/shared/nodeRuntime";
17 import * as Exit from "effect/Exit";
18 import * as Fiber from "effect/Fiber";
19 import * as DateTime from "effect/DateTime";
@@ -1113,6 +1114,136 @@ describe("AcpRegistryAdapterV2", () => {
1114 }).pipe(Effect.provide(layerTest), Effect.scoped),
1115 );
1116
1117 + it.effect("gives Copilot T3's MCP server over HTTP when it advertises HTTP", () =>
1118 + Effect.gen(function* () {
1119 + const selfInvocation = yield* resolveSelfInvocation();
1120 + const mockAgentPath = yield* (yield* Path.Path).fromFileUrl(
1121 + new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
1122 + );
1123 + const mcpSessions = yield* McpProviderSessions.McpProviderSessions;
1124 + const endpoint = "http://127.0.0.1:43123/mcp";
1125 + const sessionMcpServers = Effect.fn("sessionMcpServers")(function* (
1126 + config: Record<string, unknown>,
1127 + agentEnvironment: Record<string, string> = {},
1128 + ) {
1129 + const requests: Array<AcpSessionRuntime.AcpSessionRequestLogEvent> = [];
1130 + const instanceId = ProviderInstanceId.make("acp-registry-mcp-transport");
1131 + const threadId = ThreadId.make("thread-acp-registry-mcp-transport");
1132 + const mcpSession = {
1133 + environmentId: EnvironmentId.make("environment-acp-registry-mcp-transport"),
1134 + threadId,
1135 + providerSessionId: "mcp-session-acp-registry-mcp-transport",
1136 + providerInstanceId: instanceId,
1137 + endpoint,
1138 + browserToolsAvailable: false,
1139 + };
1140 + yield* mcpSessions.set({ ...mcpSession, authorizationHeader: "Bearer opened-token" });
1141 + const adapter = yield* makeAcpRegistryAdapterV2({
1142 + selfInvocation,
1143 + instanceId,
1144 + settings: yield* decodeAcpRegistryAdapterSettings(config),
1145 + environment: {},
1146 + nativeLogging: () => ({
1147 + requestLogger: (event) =>
1148 + Effect.sync(() => {
1149 + if (event.status === "started") requests.push(event);
1150 + }),
1151 + }),
1152 + }).pipe(
1153 + Effect.provide(
1154 + Layer.mock(AcpRegistrySupport.AcpRegistryCatalog)({
1155 + resolve: () =>
1156 + Effect.succeed({
1157 + distribution: "local" as const,
1158 + spawn: {
1159 + command: process.execPath,
1160 + args: [mockAgentPath],
1161 + env: { T3_ACP_SESSION_LIFECYCLE: "1", ...agentEnvironment },
1162 + },
1163 + }),
1164 + }),
1165 + ),
1166 + );
1167 + const modelSelection = { instanceId, model: "default" } as const;
1168 + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
1169 + runtimeMode: "full-access",
1170 + interactionMode: "default",
1171 + cwd: process.cwd(),
1172 + });
1173 + const runtime = yield* adapter.openSession({
1174 + threadId,
1175 + providerSessionId: ProviderSessionId.make("provider-session-acp-registry-mcp-transport"),
1176 + modelSelection,
1177 + runtimePolicy,
1178 + });
1179 + const providerThread = yield* runtime.ensureThread({
1180 + threadId,
1181 + modelSelection,
1182 + runtimePolicy,
1183 + });
1184 + yield* mcpSessions.set({ ...mcpSession, authorizationHeader: "Bearer rotated-token" });
1185 + yield* runtime.resumeThread({
1186 + providerThread: {
1187 + ...providerThread,
1188 + nativeThreadRef: {
1189 + driver: ACP_REGISTRY_PROVIDER,
1190 + nativeId: "mock-session-2",
1191 + strength: "strong",
1192 + },
1193 + },
1194 + });
1195 + const sent = (method: string) => {
1196 + const payload = requests.find((event) => event.method === method)?.payload;
1197 + return typeof payload === "object" && payload !== null
1198 + ? Reflect.get(payload, "mcpServers")
1199 + : undefined;
1200 + };
1201 + return { new: sent("session/new"), load: sent("session/load") };
1202 + });
1203 + const http = (authorization: string) => [
1204 + {
1205 + type: "http",
1206 + name: "t3-code",
1207 + url: endpoint,
1208 + headers: [{ name: "Authorization", value: authorization }],
1209 + },
1210 + ];
1211 + const stdio = (authorization: string) => [
1212 + {
1213 + name: "t3-code",
1214 + command: selfInvocation.command,
1215 + args: [...selfInvocationArgs(selfInvocation, ["acp-mcp-bridge"])],
1216 + env: [
1217 + { name: "ELECTRON_RUN_AS_NODE", value: "1" },
1218 + { name: "T3_ACP_MCP_ENDPOINT", value: endpoint },
1219 + { name: "T3_ACP_MCP_AUTHORIZATION", value: authorization },
1220 + ],
1221 + },
1222 + ];
1223 +
1224 + assert.deepEqual(
1225 + yield* sessionMcpServers({ agentId: "github-copilot-cli" }, { T3_ACP_MCP_HTTP: "1" }),
1226 + { new: http("Bearer opened-token"), load: http("Bearer rotated-token") },
1227 + );
1228 + const acp = [{ type: "acp", name: "t3-code", serverId: "t3-code" }];
1229 + assert.deepEqual(
1230 + yield* sessionMcpServers(
1231 + { agentId: "github-copilot-cli" },
1232 + { T3_ACP_MCP_HTTP: "1", T3_ACP_MCP_ACP: "1" },
1233 + ),
1234 + { new: acp, load: acp },
1235 + );
1236 + assert.deepEqual(yield* sessionMcpServers({ agentId: "github-copilot-cli" }), {
1237 + new: stdio("Bearer opened-token"),
1238 + load: stdio("Bearer rotated-token"),
1239 + });
1240 + assert.deepEqual(yield* sessionMcpServers({ agentId: "gemini" }, { T3_ACP_MCP_HTTP: "1" }), {
1241 + new: stdio("Bearer opened-token"),
1242 + load: stdio("Bearer rotated-token"),
1243 + });
1244 + }).pipe(Effect.provide(layerTest), Effect.scoped),
1245 + );
1246 +
1247 it.effect.each(["before", "after"] as const)(
1248 "reconciles a full prompt echo %s acknowledgment",
1249 (ordering) =>
packages/provider-acp-registry/src/server/adapter.ts
+2
@@ -250,6 +250,8 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu
250 ? {}
251 : {
252 clientCapabilitiesMeta: copilotClientCapabilitiesMeta,
253 + // Copilot CLI 1.0.105 rejects stdio MCP servers from the client.
254 + mcpOverHttp: true,
255 registerExtensions: copilotRouting.registerExtensions,
256 normalizeSessionUpdate: copilotRouting.normalizeSessionUpdate,
257 extractSubagentUpdate: extractCopilotSubagentUpdate,
packages/provider-acp/src/server/AcpSessionRuntime.ts
+8 -4
@@ -136,6 +136,7 @@ export interface AcpSessionRuntimeOptions {
136 result: EffectAcpSchema.InitializeResponse,
137 ) => Effect.Effect<void, never>;
138 readonly acpMcpServers?: ReadonlyArray<EffectAcpSchema.McpServer>;
139 + readonly httpMcpServers?: ReadonlyArray<EffectAcpSchema.McpServer>;
140 readonly requestLogger?: (event: AcpSessionRequestLogEvent) => Effect.Effect<void, never>;
141 readonly protocolLogging?: {
142 readonly logIncoming?: boolean;
@@ -1084,6 +1085,7 @@ export interface AcpSessionRuntimeStartResult {
1085 export interface AcpSessionActivationOptions {
1086 readonly mcpServers?: ReadonlyArray<EffectAcpSchema.McpServer>;
1087 readonly acpMcpServers?: ReadonlyArray<EffectAcpSchema.McpServer>;
1088 + readonly httpMcpServers?: ReadonlyArray<EffectAcpSchema.McpServer>;
1089 }
1090
1091 export class AcpSessionRuntime extends Context.Service<
@@ -2094,13 +2096,15 @@ export const make = Effect.fn("AcpSessionRuntime.make")(function* (
2096 initializeResult: EffectAcpSchema.InitializeResponse,
2097 activationOptions?: AcpSessionActivationOptions,
2098 ): ReadonlyArray<EffectAcpSchema.McpServer> => {
2099 + const mcpCapabilities = initializeResult.agentCapabilities?.mcpCapabilities;
2100 const acpServers = activationOptions?.acpMcpServers ?? options.acpMcpServers ?? [];
2098 - if (
2099 - initializeResult.agentCapabilities?.mcpCapabilities?.acp === true &&
2100 - acpServers.length > 0
2101 - ) {
2101 + if (mcpCapabilities?.acp === true && acpServers.length > 0) {
2102 return acpServers;
2103 }
2104 + const httpServers = activationOptions?.httpMcpServers ?? options.httpMcpServers ?? [];
2105 + if (mcpCapabilities?.http === true && httpServers.length > 0) {
2106 + return httpServers;
2107 + }
2108 return activationOptions?.mcpServers ?? options.mcpServers ?? [];
2109 };
2110
packages/provider-acp/src/server/adapter.ts
+28 -6
@@ -147,6 +147,7 @@ export interface AcpAdapterV2RuntimeInput {
147 readonly runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy;
148 readonly mcpServers: ReadonlyArray<EffectAcpSchema.McpServer>;
149 readonly acpMcpServers?: ReadonlyArray<EffectAcpSchema.McpServer>;
150 + readonly httpMcpServers?: ReadonlyArray<EffectAcpSchema.McpServer>;
151 readonly processEnvironment?: NodeJS.ProcessEnv;
152 readonly resumeSessionId?: string;
153 readonly interruptPromptOnCancel?: boolean;
@@ -281,6 +282,7 @@ export interface AcpAdapterV2Flavor {
282 readonly clientCapabilitiesMeta?: NonNullable<
283 EffectAcpSchema.InitializeRequest["clientCapabilities"]
284 >["_meta"];
285 + readonly mcpOverHttp?: boolean;
286 readonly normalizeSessionUpdate?: (
287 notification: EffectAcpSchema.SessionNotification,
288 ) => EffectAcpSchema.SessionNotification;
@@ -641,6 +643,7 @@ function negotiatedCapabilities(
643 interface AcpMcpContext {
644 readonly servers: ReadonlyArray<EffectAcpSchema.McpServer>;
645 readonly acpServers: ReadonlyArray<EffectAcpSchema.McpServer>;
646 + readonly httpServers: ReadonlyArray<EffectAcpSchema.McpServer>;
647 readonly processEnvironment?: NodeJS.ProcessEnv;
648 readonly endpoint?: string;
649 readonly authorization?: string;
@@ -649,11 +652,12 @@ interface AcpMcpContext {
652 function acpMcpContext(
653 session: McpProviderSession.McpProviderSessionConfig | undefined,
654 self: SelfInvocation,
655 + mcpOverHttp: boolean | undefined,
656 ): AcpMcpContext {
657 if (session === undefined) {
654 - return { servers: [], acpServers: [] };
658 + return { servers: [], acpServers: [], httpServers: [] };
659 }
656 - // codex-acp 1.2.0 and pi-acp drop injected HTTP servers; bridge through stdio instead.
660 + // codex-acp 1.2.0 and pi-acp drop injected HTTP servers, so HTTP is opt-in per flavor.
661 return {
662 servers: [
663 {
@@ -668,6 +672,17 @@ function acpMcpContext(
672 },
673 ],
674 acpServers: [{ type: "acp", name: "t3-code", serverId: "t3-code" }],
675 + httpServers:
676 + mcpOverHttp === true
677 + ? [
678 + {
679 + type: "http",
680 + name: "t3-code",
681 + url: session.endpoint,
682 + headers: [{ name: "Authorization", value: session.authorizationHeader }],
683 + },
684 + ]
685 + : [],
686 endpoint: session.endpoint,
687 authorization: session.authorizationHeader,
688 processEnvironment: {
@@ -680,7 +695,11 @@ function acpMcpContext(
695 }
696
697 function acpMcpActivation(context: AcpMcpContext) {
683 - return { mcpServers: context.servers, acpMcpServers: context.acpServers };
698 + return {
699 + mcpServers: context.servers,
700 + acpMcpServers: context.acpServers,
701 + httpMcpServers: context.httpServers,
702 + };
703 }
704
705 function nativeThreadId(
@@ -1417,8 +1436,10 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
1436 const { flavor, selfInvocation: self } = options;
1437 const readMcpContext = (threadId: ThreadId | null) =>
1438 threadId === null
1420 - ? Effect.succeed(acpMcpContext(undefined, self))
1421 - : mcpSessions.read(threadId).pipe(Effect.map((session) => acpMcpContext(session, self)));
1439 + ? Effect.succeed(acpMcpContext(undefined, self, flavor.mcpOverHttp))
1440 + : mcpSessions
1441 + .read(threadId)
1442 + .pipe(Effect.map((session) => acpMcpContext(session, self, flavor.mcpOverHttp)));
1443 const driver = flavor.driver;
1444 const continuationRequests = options.continuationRequests;
1445 const postSettleContinuationEnabled =
@@ -2043,6 +2064,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
2064 runtimePolicy: input.runtimePolicy,
2065 mcpServers: mcpContext.servers,
2066 acpMcpServers: mcpContext.acpServers,
2067 + httpMcpServers: mcpContext.httpServers,
2068 ...(mcpContext.processEnvironment === undefined
2069 ? {}
2070 : { processEnvironment: mcpContext.processEnvironment }),
@@ -7303,7 +7325,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
7325 const mcpSession = yield* mcpSessions.read(turnInput.threadId);
7326 const instructionState = {
7327 interactionMode: turnInput.runtimePolicy.interactionMode,
7306 - hasT3Mcp: acpMcpContext(mcpSession, self).servers.length > 0,
7328 + hasT3Mcp: mcpSession !== undefined,
7329 hasDeviceTools: mcpSession?.capabilities?.has("device") === true,
7330 } satisfies T3AcpInstructionState;
7331 const previousInstructionState = (yield* Ref.get(promptInstructionStates)).get(sessionId);