diff --git a/apps/server/src/mcp/McpToolAccess.test.ts b/apps/server/src/mcp/McpToolAccess.test.ts index 6cfd86bd3d836..298cd1294460a 100644 --- a/apps/server/src/mcp/McpToolAccess.test.ts +++ b/apps/server/src/mcp/McpToolAccess.test.ts @@ -495,6 +495,24 @@ it.effect.each(["reads_as_caller", "acts_as_caller"] as const)( ), ); +// A provider can load an approved T3 MCP client beside the thread's own server. +it.effect("an environment change refused for a client's approved access names that access", () => + Effect.gen(function* () { + const built = yield* ProbeToolkit; + const { result } = yield* built + .handle("writes_environment", {}) + .pipe(Stream.unwrap, Stream.run(Sink.last()), Effect.flatMap(Effect.fromOption)); + expect(result).toMatchObject({ code: "capability_denied" }); + const { message } = result as OrchestratorMcpFailure; + expect(message).not.toContain("calling thread"); + expect(message).toContain("auto"); + }).pipe( + Effect.provide(McpToolAccess.HandlersLayer.layer(layerProbeHandlers)), + Effect.provideService(McpInvocationContext.McpInvocationContext, clientCaller("auto")), + Effect.provide(Layer.mock(ThreadManagement.ThreadManagementService)({})), + ), +); + it.effect("refuses to build a thread-bound tool that outside clients would be offered", () => Effect.gen(function* () { const CallerToolkit = Toolkit.make(Tool.make("reads_as_caller", probe)); diff --git a/apps/server/src/mcp/McpToolAccess.ts b/apps/server/src/mcp/McpToolAccess.ts index bbf090809c682..fcd09b7ddb0d7 100644 --- a/apps/server/src/mcp/McpToolAccess.ts +++ b/apps/server/src/mcp/McpToolAccess.ts @@ -323,10 +323,18 @@ export const afterForwarding =
( forwarded, ); -const fullAccessRequired = - "Changing projects or environment settings needs a live full-access/default calling thread or a full-access client."; const changesEnvironment = "change projects or environment settings"; +/** An outside client is held by its own approval, not a thread, so its refusal names that. */ +const fullAccessRequired = ({ scope: { client }, limits }: Caller) => { + if (client === undefined) + return "Changing projects or environment settings needs a live full-access/default calling thread or a full-access client."; + const below = `below the full access needed to ${changesEnvironment}.`; + return client.access !== "full-access" + ? `This MCP client (${client.label}) was approved with ${client.access} access, ${below} To allow it, reconnect this client and approve it with Full access, or make the change from a T3 thread running with full access.` + : `This MCP client (${client.label}) is limited to ${limits.runtimeMode}/${limits.interactionMode} on this request, ${below}`; +}; + /** Recheck after waits before writing; caller modes may have changed. */ export const writesEnvironment =
( handle: ( @@ -348,7 +356,7 @@ export const writesEnvironment =
( : assertNotLinked(caller, changesEnvironment), ), Effect.tap((caller) => - assertFullAccessNamingLink(caller, fullAccessRequired, changesEnvironment), + assertFullAccessNamingLink(caller, fullAccessRequired(caller), changesEnvironment), ), ); return declare( @@ -356,7 +364,7 @@ export const writesEnvironment =
( // Linked work never reaches a link at all; that is checked as the call goes. () => orchestratingCaller.pipe( - Effect.tap((caller) => assertFullAccess(caller, fullAccessRequired)), + Effect.tap((caller) => assertFullAccess(caller, fullAccessRequired(caller))), ), ); };