diff --git a/packages/core/src/mcp/instructions.ts b/packages/core/src/mcp/instructions.ts index b6cfd31bef9..7866e4af919 100644 --- a/packages/core/src/mcp/instructions.ts +++ b/packages/core/src/mcp/instructions.ts @@ -92,8 +92,8 @@ export const layer = Layer.effect( const visible = instructions .flatMap((item) => { const owned = tools.filter((tool) => tool.server === item.server) - const codemode = owned[0]?.codemode !== false - if (codemode && !canExecute) return [] + // Without execute, Code Mode server tools are exposed directly. + const codemode = canExecute && owned[0]?.codemode !== false if ( !owned.some( (tool) => diff --git a/packages/core/src/tool.ts b/packages/core/src/tool.ts index 50f5816f948..659cee2643d 100644 --- a/packages/core/src/tool.ts +++ b/packages/core/src/tool.ts @@ -255,10 +255,13 @@ const layer = Layer.effect( if (whollyDisabled(tool.options?.permission ?? name, rules)) continue active.set(name, tool) } - const direct = new Map(Array.from(active).filter(([, tool]) => tool.options?.codemode === false)) + const codeModeEnabled = !whollyDisabled("execute", rules) + // Without Code Mode its tools would be unreachable, so expose them as direct tools instead. + const direct = codeModeEnabled + ? new Map(Array.from(active).filter(([, tool]) => tool.options?.codemode === false)) + : active const codeModeTools = new Map(Array.from(active).filter(([, tool]) => tool.options?.codemode !== false)) const names = Array.from(codeModeTools.keys()).join("\0") - const codeModeEnabled = !whollyDisabled("execute", rules) // Discovery is immutable for a registry revision and visible tool set. Keep executors // fresh, but share the inventory, whose prepared runtime and much larger rendered catalog // are cached by identity, and the execute tool's definition across steps. diff --git a/packages/core/test/mcp-instructions.test.ts b/packages/core/test/mcp-instructions.test.ts index 8635a80d0e4..dda4467ff73 100644 --- a/packages/core/test/mcp-instructions.test.ts +++ b/packages/core/test/mcp-instructions.test.ts @@ -65,14 +65,22 @@ describe("McpInstructions", () => { ), ) - it.effect("omits instructions when the agent cannot use execute", () => + it.effect("lists Code Mode servers as direct tools when the agent cannot use execute", () => Effect.gen(function* () { const service = yield* McpInstructions.Service const generation = yield* service .load([{ action: "execute", resource: "*", effect: "deny" }]) .pipe(Effect.flatMap(readInitial)) - expect(generation.text).toBe("") + expect(generation.text).toBe( + [ + "", + ' ', + " Alpha instructions", + " ", + "", + ].join("\n"), + ) }).pipe( Effect.provide( layer( diff --git a/packages/core/test/tool-registry.test.ts b/packages/core/test/tool-registry.test.ts index dc446ca3bb5..3d52fd9fd45 100644 --- a/packages/core/test/tool-registry.test.ts +++ b/packages/core/test/tool-registry.test.ts @@ -707,6 +707,27 @@ describe("Tool", () => { }), ) + it.effect("exposes Code Mode tools directly when execute is denied", () => + Effect.gen(function* () { + const service = yield* Tool.Service + yield* transform(service, { lookup: make() }, { namespace: "mcp" }) + yield* transform(service, { bash: make() }, { codemode: false }) + const denyExecute: Permission.Ruleset = [{ action: "execute", resource: "*", effect: "deny" }] + + const snapshot = yield* service.snapshot(denyExecute) + expect(snapshot.definitions.map((tool) => tool.name)).toEqual(["bash", "mcp_lookup"]) + expect(snapshot.codeModeCatalog).toBeUndefined() + expect((yield* snapshot.execute(call("mcp_lookup"))).output).toEqual({ text: "mcp_lookup" }) + + const hidden = yield* service.snapshot([ + ...denyExecute, + { action: "mcp_lookup", resource: "*", effect: "deny" }, + ]) + expect(hidden.definitions.map((tool) => tool.name)).toEqual(["bash"]) + expect(yield* hidden.execute(call("mcp_lookup")).pipe(Effect.flip)).toBeInstanceOf(Tool.Error) + }), + ) + it.effect("filters disabled tools with edit aliases and ordered wildcard precedence", () => Effect.gen(function* () { const service = yield* Tool.Service