@devries-cameron20 / t3code Mirror · read-only / commits / e47bfe4617
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 23, 13:00 UTC

fix(server): Claude works next to an enterprise managed-mcp.json (#18706)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Dara Adedeji committed Oct 14, 2026 at 16:47 UTC e47bfe4617f6fdca2c6513bd0afe0f6b8d24688a
4 files changed +52 -5
apps/server/src/provider/ClaudeCapabilitiesProbe.test.ts
+16
@@ -41,6 +41,7 @@ it("isolates Claude capability probes without dropping workspace setting sources
41 FORCE_CODE_TERMINAL: "1",
42 },
43 cwd: "/workspace/project",
44 + managedMcpConfig: false,
45 });
46
47 assert.deepEqual(options.mcpServers, {});
@@ -59,6 +60,21 @@ it("isolates Claude capability probes without dropping workspace setting sources
60 assert.equal(options.env?.CLAUDE_CODE_IDE_SKIP_AUTO_INSTALL, "1");
61 });
62
63 +it("drops strict MCP mode, and only that, next to an administrator's managed-mcp.json", () => {
64 + const options = buildClaudeCapabilitiesProbeQueryOptions({
65 + executablePath: "/usr/bin/claude",
66 + abortController: new AbortController(),
67 + environment: { HOME: "/home/user" },
68 + cwd: undefined,
69 + managedMcpConfig: true,
70 + });
71 +
72 + // Claude exits before initializing when handed --strict-mcp-config here.
73 + assert.equal(options.strictMcpConfig, undefined);
74 + assert.deepEqual(options.mcpServers, {});
75 + assert.equal(options.env?.ENABLE_CLAUDEAI_MCP_SERVERS, "false");
76 +});
77 +
78 it.layer(NodeServices.layer)("Claude capability probe SDK boundary", (it) => {
79 it.effect(
80 "discovers commands and skills separately for each cwd without replacing machine metadata",
apps/server/src/provider/ClaudeProvider.ts
+8 -3
@@ -35,7 +35,7 @@ import {
35 type ServerProviderDraft,
36 } from "@t3tools/provider-core/server/snapshotProbe";
37 import { resolveClaudeSdkExecutablePath } from "./Drivers/ClaudeExecutable.ts";
38 -import { makeClaudeEnvironment } from "./Drivers/ClaudeHome.ts";
38 +import { hasClaudeManagedMcpConfig, makeClaudeEnvironment } from "./Drivers/ClaudeHome.ts";
39 import { discoverClaudeSkills } from "./Drivers/ClaudeSkills.ts";
40 import type { ProviderWorkspaceSnapshot } from "@t3tools/provider-core/server/driver";
41 import { makeUnavailableUsageLimits } from "@t3tools/provider-core/server/usageLimits";
@@ -223,6 +223,8 @@ export function buildClaudeCapabilitiesProbeQueryOptions(input: {
223 readonly abortController: AbortController;
224 readonly environment: NodeJS.ProcessEnv;
225 readonly cwd: string | undefined;
226 + /** An administrator's `managed-mcp.json` is installed; see `hasClaudeManagedMcpConfig`. */
227 + readonly managedMcpConfig: boolean;
228 }): ClaudeQueryOptions {
229 return {
230 persistSession: false,
@@ -235,9 +237,10 @@ export function buildClaudeCapabilitiesProbeQueryOptions(input: {
237 settings: { disableAllHooks: true },
238 allowedTools: [],
239 // Ignore MCP definitions from every filesystem setting source above. The
238 - // SDK combines this empty explicit map with --strict-mcp-config.
240 + // SDK combines this empty explicit map with --strict-mcp-config, which
241 + // Claude refuses next to a managed-mcp.json that already excludes them.
242 mcpServers: {},
240 - strictMcpConfig: true,
243 + ...(input.managedMcpConfig ? {} : { strictMcpConfig: true }),
244 env: {
245 ...input.environment,
246 // Connected claude.ai MCP servers are discovered outside filesystem
@@ -384,6 +387,7 @@ const probeClaudeCapabilities = (
387 claudeSettings.binaryPath,
388 claudeEnvironment,
389 );
390 + const managedMcpConfig = yield* hasClaudeManagedMcpConfig();
391 return yield* Effect.tryPromise(async () => {
392 const q = claudeQuery({
393 // Never yield — we only need initialization data, not a conversation.
@@ -397,6 +401,7 @@ const probeClaudeCapabilities = (
401 abortController: abort,
402 environment: claudeEnvironment,
403 cwd,
404 + managedMcpConfig,
405 }),
406 });
407 const init = await q.initializationResult();
apps/server/src/provider/Drivers/ClaudeHome.ts
+20
@@ -1,5 +1,6 @@
1 import type { ClaudeSettings } from "@t3tools/contracts";
2 import * as Effect from "effect/Effect";
3 +import * as FileSystem from "effect/FileSystem";
4 import * as Path from "effect/Path";
5 import * as Schema from "effect/Schema";
6
@@ -53,6 +54,25 @@ export const makeClaudeEnvironment = Effect.fn("makeClaudeEnvironment")(function
54 };
55 });
56
57 +/**
58 + * Whether an administrator installed Claude Code's `managed-mcp.json`. While it
59 + * exists Claude refuses `--strict-mcp-config` and exits before initializing,
60 + * but it already ignores user, project and `--mcp-config` servers on its own,
61 + * so callers that pass the flag for isolation can drop it. Paths match the
62 + * ones Claude Code checks.
63 + */
64 +export const hasClaudeManagedMcpConfig = Effect.fn("hasClaudeManagedMcpConfig")(function* () {
65 + const fileSystem = yield* FileSystem.FileSystem;
66 + const platform = yield* HostProcess.Platform;
67 + const managedMcpConfigPath =
68 + platform === "darwin"
69 + ? "/Library/Application Support/ClaudeCode/managed-mcp.json"
70 + : platform === "win32"
71 + ? "C:\\Program Files\\ClaudeCode\\managed-mcp.json"
72 + : "/etc/claude-code/managed-mcp.json";
73 + return yield* fileSystem.exists(managedMcpConfigPath).pipe(Effect.orElseSucceed(() => false));
74 +});
75 +
76 export const makeClaudeContinuationGroupKey = Effect.fn("makeClaudeContinuationGroupKey")(
77 function* (
78 config: Pick<ClaudeSettings, "homePath">,
apps/server/src/textGeneration/ClaudeTextGeneration.ts
+8 -2
@@ -37,7 +37,10 @@ import {
37 resolveClaudeModelSlug,
38 scopeClaudeModelCatalog,
39 } from "../provider/ClaudeModelCatalog.ts";
40 -import { makeClaudeEnvironment } from "../provider/Drivers/ClaudeHome.ts";
40 +import {
41 + hasClaudeManagedMcpConfig,
42 + makeClaudeEnvironment,
43 +} from "../provider/Drivers/ClaudeHome.ts";
44
45 const CLAUDE_TIMEOUT_MS = 180_000;
46 /** The tools an investigation can see. `--tools` takes bare names; patterns go in the allow list. */
@@ -209,6 +212,7 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
212 ),
213 )
214 : cwd;
215 + const managedMcpConfig = yield* hasClaudeManagedMcpConfig();
216 const spawnCommand = yield* resolveSpawnCommand(
217 claudeSettings.binaryPath || "claude",
218 [
@@ -236,7 +240,9 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
240 ]
241 : ["--tools", ""]),
242 "--disable-slash-commands",
239 - "--strict-mcp-config",
243 + // Claude refuses this flag next to a managed-mcp.json, which already keeps the
244 + // user's own MCP servers out.
245 + ...(managedMcpConfig ? [] : ["--strict-mcp-config"]),
246 "--permission-mode",
247 "dontAsk",
248 ],