@@ -688,6 +688,46 @@ describe("ClaudeAdapterV2 MCP query overrides", () => {
688688 }),
689689 );
690690 assert.notEqual(rotatedKey, initialKey);
691+ const tools = (stdioSecret: string, httpSecret: string, url: string) => ({
692+ servers: [
693+ {
694+ name: "command",
695+ transport: {
696+ type: "stdio" as const,
697+ command: "node",
698+ args: ["mcp.js"],
699+ env: [{ name: "API_TOKEN", value: stdioSecret, sensitive: true }],
700+ },
701+ },
702+ {
703+ name: "docs",
704+ transport: {
705+ type: "http" as const,
706+ url,
707+ headers: [{ name: "Authorization", value: httpSecret, sensitive: true }],
708+ },
709+ },
710+ ],
711+ disabledSkills: [],
712+ fingerprint: "unchanged",
713+ });
714+ const keyFor = (userTools: McpProviderSession.McpProviderSessionTools) =>
715+ ClaudeAdapterV2.claudeEffectiveQueryPolicyKey(
716+ queryPolicy,
717+ ClaudeAdapterV2.claudeMcpQueryOverrides({
718+ mcpSession: { ...mcpSession, tools: userTools },
719+ readOnlySandbox: false,
720+ }),
721+ );
722+ const userKey = keyFor(tools("stdio-token", "http-token", "https://example.com/mcp"));
723+ assert.notEqual(userKey, initialKey);
724+ for (const changed of [
725+ tools("rotated-stdio", "http-token", "https://example.com/mcp"),
726+ tools("stdio-token", "rotated-http", "https://example.com/mcp"),
727+ tools("stdio-token", "http-token", "https://example.com/other"),
728+ ]) {
729+ assert.notEqual(keyFor(changed), userKey);
730+ }
691731 });
692732
693733 it("matches the read-only allowlist to the orchestrator toolkit annotations", () => {
@@ -2081,7 +2121,7 @@ describe("ClaudeAdapterV2 MCP credential channel", () => {
20812121 url: "http://127.0.0.1:43123/mcp",
20822122 headers: { Authorization: "Bearer dummy-mcp-credential" },
20832123 };
2084- const openWith = (cli: ReturnType<typeof makeFakeClaudeCli>) =>
2124+ const openWith = (cli: ReturnType<typeof makeFakeClaudeCli>, protocolEvents: unknown[] = [] ) =>
20852125 Effect.gen(function* () {
20862126 const runner = yield* ClaudeAdapterV2.ClaudeAgentSdkQueryRunner;
20872127 return yield* runner.open({
@@ -2094,34 +2134,105 @@ describe("ClaudeAdapterV2 MCP credential channel", () => {
20942134 resume: false,
20952135 cwd: null,
20962136 environment: { PATH: "/usr/bin" },
2097- mcpServers: { "t3-code": t3McpServer },
2137+ ...ClaudeAdapterV2.claudeMcpQueryOverrides({
2138+ readOnlySandbox: false,
2139+ mcpSession: {
2140+ environmentId: EnvironmentId.make("environment-claude-mcp-channel"),
2141+ threadId: ThreadId.make("thread-claude-mcp-channel"),
2142+ providerSessionId: "mcp-session-claude-mcp-channel",
2143+ providerInstanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
2144+ endpoint: t3McpServer.url,
2145+ browserToolsAvailable: true,
2146+ authorizationHeader: t3McpServer.headers.Authorization,
2147+ tools: {
2148+ servers: [
2149+ {
2150+ name: "command",
2151+ transport: {
2152+ type: "stdio",
2153+ command: "node",
2154+ args: ["mcp.js"],
2155+ env: [
2156+ { name: "API_TOKEN", value: "superseded-token", sensitive: true },
2157+ { name: "API_TOKEN", value: "stdin-stdio-secret", sensitive: true },
2158+ ],
2159+ },
2160+ },
2161+ {
2162+ name: "docs",
2163+ transport: {
2164+ type: "http",
2165+ url: "https://example.com/mcp",
2166+ headers: [
2167+ { name: "Authorization", value: "superseded-token", sensitive: true },
2168+ { name: "Authorization", value: "stdin-http-secret", sensitive: true },
2169+ ],
2170+ },
2171+ },
2172+ ],
2173+ disabledSkills: [],
2174+ fingerprint: "stdin-tools",
2175+ },
2176+ },
2177+ }),
20982178 }),
20992179 pathToClaudeCodeExecutable: "/opt/claude/cli.js",
21002180 spawnClaudeCodeProcess: cli.spawn,
21012181 },
21022182 });
21032183 }).pipe(
21042184 Effect.provide(ClaudeAdapterV2.layerQueryRunner),
2105- Effect.provideService(
2106- ProviderEventLoggers.ProviderEventLoggers,
2107- ProviderEventLoggers.NoOpProviderEventLoggers,
2108- ),
2185+ Effect.provideService(ProviderEventLoggers.ProviderEventLoggers, {
2186+ canonical: undefined,
2187+ native: {
2188+ filePath: "/tmp/claude-mcp-channel-events.log",
2189+ write: (event) =>
2190+ Effect.sync(() => {
2191+ protocolEvents.push(event);
2192+ }),
2193+ close: () => Effect.void,
2194+ },
2195+ }),
21092196 Effect.provide(NodeServices.layer),
21102197 );
21112198
21122199 it.effect("sends MCP servers over stdin, not argv or the environment", () =>
21132200 Effect.gen(function* () {
21142201 const cli = makeFakeClaudeCli();
2115- const session = yield* openWith(cli);
2202+ const protocolEvents: unknown[] = [];
2203+ const session = yield* openWith(cli, protocolEvents);
21162204 yield* session.close;
21172205
21182206 assert.deepInclude(cli.controlRequests, {
21192207 subtype: "mcp_set_servers",
2120- servers: { "t3-code": t3McpServer },
2208+ servers: {
2209+ "t3-code": { ...t3McpServer, timeout: ClaudeAdapterV2.CLAUDE_T3_MCP_TOOL_TIMEOUT_MS },
2210+ command: {
2211+ type: "stdio",
2212+ command: "node",
2213+ args: ["mcp.js"],
2214+ env: { API_TOKEN: "stdin-stdio-secret" },
2215+ },
2216+ docs: {
2217+ type: "http",
2218+ url: "https://example.com/mcp",
2219+ headers: { Authorization: "stdin-http-secret" },
2220+ },
2221+ },
21212222 });
21222223 const spawned = JSON.stringify(cli.spawns);
21232224 assert.notInclude(spawned, "--mcp-config");
2124- assert.notInclude(spawned, "dummy-mcp-credential");
2225+ assert.isNotEmpty(protocolEvents);
2226+ const logged = JSON.stringify(protocolEvents);
2227+ for (const secret of [
2228+ "dummy-mcp-credential",
2229+ "stdin-stdio-secret",
2230+ "stdin-http-secret",
2231+ "superseded-token",
2232+ ]) {
2233+ assert.notInclude(spawned, secret);
2234+ assert.notInclude(logged, secret);
2235+ }
21252236 }),
21262237 );
21272238
@@ -15776,12 +15887,11 @@ describe("ClaudeAdapterV2 user tools", () => {
1577615887 }
1577715888 assert.equal(commandServer.command, "npx");
1577815889 assert.deepEqual(commandServer.args, ["context7"]);
15779- const materialized = (value: string | undefined) => {
15780- const reference = value?.match(/^\$\{([^}]+)\}$/)?.[1];
15781- return reference === undefined ? value : openedOptions?.env?.[reference];
15782- };
15783- assert.equal(materialized(commandServer.env?.API_TOKEN), "stdio-token");
15784- assert.equal(materialized(httpServer.headers?.Authorization), "winning-token");
15890+ const environment = JSON.stringify(openedOptions?.env);
15891+ assert.notInclude(environment, "stdio-token");
15892+ assert.notInclude(environment, "winning-token");
15893+ assert.equal(commandServer.env?.API_TOKEN, "stdio-token");
15894+ assert.equal(httpServer.headers?.Authorization, "winning-token");
1578515895 assert.equal(openedOptions?.permissionMode, "default");
1578615896 assert.isFunction(openedOptions?.canUseTool);
1578715897 assert.include(
0 commit comments