Skip to content

Commit 94a53a2

Browse files
Radu028claudemaria-rcks
authored
fix(acp): Copilot threads get T3's tools (#26968)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 251834c commit 94a53a2

5 files changed

Lines changed: 179 additions & 12 deletions

File tree

‎apps/server/scripts/acp-mock-agent.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const promptDelayMs = Number(process.env.T3_ACP_PROMPT_DELAY_MS ?? "0");
6161
const terminalOutputBytes = Number(process.env.T3_ACP_EMIT_TERMINAL_OUTPUT_BYTES ?? "0");
6262
const supportsSessionLifecycle = process.env.T3_ACP_SESSION_LIFECYCLE === "1";
6363
const supportsAcpMcp = process.env.T3_ACP_MCP_ACP === "1";
64+
const supportsHttpMcp = process.env.T3_ACP_MCP_HTTP === "1";
6465
const supportsV2Management = process.env.T3_ACP_V2_MANAGEMENT === "1";
6566
const advertisedAuthMethodId = process.env.T3_ACP_AUTH_METHOD_ID?.trim();
6667
const initializeAuthMethodId =
@@ -502,7 +503,14 @@ const program = Effect.gen(function* () {
502503
session: {
503504
...(supportsSessionLifecycle ? { fork: {}, additionalDirectories: {} } : {}),
504505
...(supportsV2Management ? { delete: {} } : {}),
505-
...(supportsAcpMcp ? { mcp: { acp: {} } } : {}),
506+
...(supportsAcpMcp || supportsHttpMcp
507+
? {
508+
mcp: {
509+
...(supportsAcpMcp ? { acp: {} } : {}),
510+
...(supportsHttpMcp ? { http: {} } : {}),
511+
},
512+
}
513+
: {}),
506514
},
507515
...(supportsV2Management ? { providers: {} } : {}),
508516
},

‎apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts‎

Lines changed: 132 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as NodeServices from "@effect/platform-node/NodeServices";
22
import { assert, describe, it } from "@effect/vitest";
33
import {
4+
EnvironmentId,
45
MessageId,
56
NodeId,
67
ProjectId,
@@ -12,7 +13,7 @@ import {
1213
ThreadId,
1314
} from "@t3tools/contracts";
1415
import { pendingBackgroundTurnItems } from "@t3tools/shared/orchestrationV2PendingBackgroundWork";
15-
import { resolveSelfInvocation } from "@t3tools/shared/nodeRuntime";
16+
import { resolveSelfInvocation, selfInvocationArgs } from "@t3tools/shared/nodeRuntime";
1617
import * as Exit from "effect/Exit";
1718
import * as Fiber from "effect/Fiber";
1819
import * as DateTime from "effect/DateTime";
@@ -1113,6 +1114,136 @@ describe("AcpRegistryAdapterV2", () => {
11131114
}).pipe(Effect.provide(layerTest), Effect.scoped),
11141115
);
11151116

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+
11161247
it.effect.each(["before", "after"] as const)(
11171248
"reconciles a full prompt echo %s acknowledgment",
11181249
(ordering) =>

‎packages/provider-acp-registry/src/server/adapter.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu
250250
? {}
251251
: {
252252
clientCapabilitiesMeta: copilotClientCapabilitiesMeta,
253+
// Copilot CLI 1.0.105 rejects stdio MCP servers from the client.
254+
mcpOverHttp: true,
253255
registerExtensions: copilotRouting.registerExtensions,
254256
normalizeSessionUpdate: copilotRouting.normalizeSessionUpdate,
255257
extractSubagentUpdate: extractCopilotSubagentUpdate,

‎packages/provider-acp/src/server/AcpSessionRuntime.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export interface AcpSessionRuntimeOptions {
136136
result: EffectAcpSchema.InitializeResponse,
137137
) => Effect.Effect<void, never>;
138138
readonly acpMcpServers?: ReadonlyArray<EffectAcpSchema.McpServer>;
139+
readonly httpMcpServers?: ReadonlyArray<EffectAcpSchema.McpServer>;
139140
readonly requestLogger?: (event: AcpSessionRequestLogEvent) => Effect.Effect<void, never>;
140141
readonly protocolLogging?: {
141142
readonly logIncoming?: boolean;
@@ -1084,6 +1085,7 @@ export interface AcpSessionRuntimeStartResult {
10841085
export interface AcpSessionActivationOptions {
10851086
readonly mcpServers?: ReadonlyArray<EffectAcpSchema.McpServer>;
10861087
readonly acpMcpServers?: ReadonlyArray<EffectAcpSchema.McpServer>;
1088+
readonly httpMcpServers?: ReadonlyArray<EffectAcpSchema.McpServer>;
10871089
}
10881090

10891091
export class AcpSessionRuntime extends Context.Service<
@@ -2094,13 +2096,15 @@ export const make = Effect.fn("AcpSessionRuntime.make")(function* (
20942096
initializeResult: EffectAcpSchema.InitializeResponse,
20952097
activationOptions?: AcpSessionActivationOptions,
20962098
): ReadonlyArray<EffectAcpSchema.McpServer> => {
2099+
const mcpCapabilities = initializeResult.agentCapabilities?.mcpCapabilities;
20972100
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) {
21022102
return acpServers;
21032103
}
2104+
const httpServers = activationOptions?.httpMcpServers ?? options.httpMcpServers ?? [];
2105+
if (mcpCapabilities?.http === true && httpServers.length > 0) {
2106+
return httpServers;
2107+
}
21042108
return activationOptions?.mcpServers ?? options.mcpServers ?? [];
21052109
};
21062110

‎packages/provider-acp/src/server/adapter.ts‎

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export interface AcpAdapterV2RuntimeInput {
147147
readonly runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy;
148148
readonly mcpServers: ReadonlyArray<EffectAcpSchema.McpServer>;
149149
readonly acpMcpServers?: ReadonlyArray<EffectAcpSchema.McpServer>;
150+
readonly httpMcpServers?: ReadonlyArray<EffectAcpSchema.McpServer>;
150151
readonly processEnvironment?: NodeJS.ProcessEnv;
151152
readonly resumeSessionId?: string;
152153
readonly interruptPromptOnCancel?: boolean;
@@ -281,6 +282,7 @@ export interface AcpAdapterV2Flavor {
281282
readonly clientCapabilitiesMeta?: NonNullable<
282283
EffectAcpSchema.InitializeRequest["clientCapabilities"]
283284
>["_meta"];
285+
readonly mcpOverHttp?: boolean;
284286
readonly normalizeSessionUpdate?: (
285287
notification: EffectAcpSchema.SessionNotification,
286288
) => EffectAcpSchema.SessionNotification;
@@ -641,6 +643,7 @@ function negotiatedCapabilities(
641643
interface AcpMcpContext {
642644
readonly servers: ReadonlyArray<EffectAcpSchema.McpServer>;
643645
readonly acpServers: ReadonlyArray<EffectAcpSchema.McpServer>;
646+
readonly httpServers: ReadonlyArray<EffectAcpSchema.McpServer>;
644647
readonly processEnvironment?: NodeJS.ProcessEnv;
645648
readonly endpoint?: string;
646649
readonly authorization?: string;
@@ -649,11 +652,12 @@ interface AcpMcpContext {
649652
function acpMcpContext(
650653
session: McpProviderSession.McpProviderSessionConfig | undefined,
651654
self: SelfInvocation,
655+
mcpOverHttp: boolean | undefined,
652656
): AcpMcpContext {
653657
if (session === undefined) {
654-
return { servers: [], acpServers: [] };
658+
return { servers: [], acpServers: [], httpServers: [] };
655659
}
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.
657661
return {
658662
servers: [
659663
{
@@ -668,6 +672,17 @@ function acpMcpContext(
668672
},
669673
],
670674
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+
: [],
671686
endpoint: session.endpoint,
672687
authorization: session.authorizationHeader,
673688
processEnvironment: {
@@ -680,7 +695,11 @@ function acpMcpContext(
680695
}
681696

682697
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+
};
684703
}
685704

686705
function nativeThreadId(
@@ -1417,8 +1436,10 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
14171436
const { flavor, selfInvocation: self } = options;
14181437
const readMcpContext = (threadId: ThreadId | null) =>
14191438
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)));
14221443
const driver = flavor.driver;
14231444
const continuationRequests = options.continuationRequests;
14241445
const postSettleContinuationEnabled =
@@ -2043,6 +2064,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
20432064
runtimePolicy: input.runtimePolicy,
20442065
mcpServers: mcpContext.servers,
20452066
acpMcpServers: mcpContext.acpServers,
2067+
httpMcpServers: mcpContext.httpServers,
20462068
...(mcpContext.processEnvironment === undefined
20472069
? {}
20482070
: { processEnvironment: mcpContext.processEnvironment }),
@@ -7303,7 +7325,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
73037325
const mcpSession = yield* mcpSessions.read(turnInput.threadId);
73047326
const instructionState = {
73057327
interactionMode: turnInput.runtimePolicy.interactionMode,
7306-
hasT3Mcp: acpMcpContext(mcpSession, self).servers.length > 0,
7328+
hasT3Mcp: mcpSession !== undefined,
73077329
hasDeviceTools: mcpSession?.capabilities?.has("device") === true,
73087330
} satisfies T3AcpInstructionState;
73097331
const previousInstructionState = (yield* Ref.get(promptInstructionStates)).get(sessionId);

0 commit comments

Comments
 (0)