Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions apps/server/src/mcp/McpToolAccess.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
16 changes: 12 additions & 4 deletions apps/server/src/mcp/McpToolAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,18 @@ export const afterForwarding = <P, A, E, R, E2, R2>(
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 = <P, A, E, R>(
handle: (
Expand All @@ -348,15 +356,15 @@ export const writesEnvironment = <P, A, E, R>(
: assertNotLinked(caller, changesEnvironment),
),
Effect.tap((caller) =>
assertFullAccessNamingLink(caller, fullAccessRequired, changesEnvironment),
assertFullAccessNamingLink(caller, fullAccessRequired(caller), changesEnvironment),
),
);
return declare(
(params: P) => check.pipe(Effect.flatMap(() => handle(params, check))),
// 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))),
),
);
};
Expand Down
Loading