)
() => Effect.void,
);
+export const refuses = (failure: OrchestratorMcpFailure) =>
+ declare(
+ () => Effect.fail(failure),
+ () => Effect.fail(failure),
+ );
+
/** Apply the caller check before local execution or forwarding loses the child identity. */
export const withoutSubagents = (
declaration: Declaration<(params: P) => Effect.Effect>,
diff --git a/apps/server/src/mcp/toolkits/core.test.ts b/apps/server/src/mcp/toolkits/core.test.ts
index 81614e5eb4274..57b1f822cf797 100644
--- a/apps/server/src/mcp/toolkits/core.test.ts
+++ b/apps/server/src/mcp/toolkits/core.test.ts
@@ -9,6 +9,7 @@ import {
CommandId,
EnvironmentId,
NodeId,
+ makeThreadInbox,
OrchestratorMcpThreadReadResult,
ProjectId,
ProviderDriverKind,
@@ -153,21 +154,21 @@ it.effect("an answered question reports already answered instead of not found",
const projection = McpToolAccessTestkit.idleThreadProjection(shell);
return Effect.gen(function* () {
const server = yield* McpServer.McpServer;
- const respond = (id: string) =>
+ const read = (id: string) =>
server
.callTool({
name: "t3_pending_request",
- arguments: { action: "respond", requestId: id, answers: { size: "large" } },
+ arguments: { action: "read", requestId: id },
})
.pipe(
Effect.provideService(McpInvocationContext.McpInvocationContext, scope),
Effect.provideService(McpSchema.McpServerClient, client),
);
- expect(declaredFailure(yield* respond(requestId))).toMatchObject({
+ expect(declaredFailure(yield* read(requestId))).toMatchObject({
code: "invalid_request",
message: "The user-input request was already answered.",
});
- expect(declaredFailure(yield* respond("missing-question"))).toMatchObject({
+ expect(declaredFailure(yield* read("missing-question"))).toMatchObject({
code: "invalid_request",
message: "The pending user-input request was not found.",
});
@@ -226,79 +227,102 @@ it.effect("an answered question reports already answered instead of not found",
);
});
-it.effect("a pending question read keeps option previews", () => {
- const shell = McpToolAccessTestkit.liveThreadShell(threadId);
- const requestId = RuntimeRequestId.make("previewed-question");
- const projection = McpToolAccessTestkit.idleThreadProjection(shell);
- const questions = [
- {
- id: "post",
- header: "Review",
- question: "Post it?",
- options: [{ label: "Post", description: "Publish the draft", preview: "Full proposed text" }],
- },
- ];
- return Effect.gen(function* () {
- const server = yield* McpServer.McpServer;
- const result = yield* server
- .callTool({ name: "t3_pending_request", arguments: { action: "read", requestId } })
- .pipe(
- Effect.provideService(McpInvocationContext.McpInvocationContext, scope),
- Effect.provideService(McpSchema.McpServerClient, client),
- );
- expect(result.structuredContent).toEqual({ requestId, questions });
- }).pipe(
- Effect.provide(
- layerThreadToolkit.pipe(
- Layer.provideMerge(McpHttpServer.layerInProcessMcpServer),
- Layer.provide(NodeCrypto.layer),
- Layer.provide(
- Layer.mock(ThreadManagement.ThreadManagementService)({
- getThreadShell: () => Effect.succeed(shell),
- getProjectThreadRecords: () =>
- Effect.succeed({
- ...projection,
- runtimeRequests: [
- {
- id: requestId,
- nodeId: NodeId.make("root"),
- providerTurnId: null,
- nativeRequestRef: null,
- kind: "user_input",
- status: "pending",
- responseCapability: { type: "message" },
- createdAt: shell.createdAt,
- resolvedAt: null,
- },
- ],
- turnItems: [
- {
- id: TurnItemId.make("previewed-question-item"),
- threadId,
- runId: null,
- nodeId: null,
- providerThreadId: null,
- providerTurnId: null,
- nativeItemRef: null,
- parentItemId: null,
- ordinal: 0,
- status: "running",
- title: null,
- startedAt: shell.createdAt,
- completedAt: null,
- updatedAt: shell.updatedAt,
- type: "user_input_request",
- requestId,
- questions,
- },
- ],
- }),
- }),
+it.effect.each(["shared", "agent-only"] as const)(
+ "a question in a %s thread stays visible after an agent is denied",
+ (audience) => {
+ const shell = {
+ ...McpToolAccessTestkit.liveThreadShell(threadId),
+ inbox: makeThreadInbox({ actor: { kind: "agent", id: "test-agent" }, routing: { audience } }),
+ };
+ const requestId = RuntimeRequestId.make("previewed-question");
+ const projection = McpToolAccessTestkit.idleThreadProjection(shell);
+ const questions = [
+ {
+ id: "post",
+ header: "Review",
+ question: "Post it?",
+ options: [
+ { label: "Post", description: "Publish the draft", preview: "Full proposed text" },
+ ],
+ },
+ ];
+ return Effect.gen(function* () {
+ const server = yield* McpServer.McpServer;
+ const call = (args: Record) =>
+ server
+ .callTool({ name: "t3_pending_request", arguments: args })
+ .pipe(
+ Effect.provideService(McpInvocationContext.McpInvocationContext, scope),
+ Effect.provideService(McpSchema.McpServerClient, client),
+ );
+ const respond = { action: "respond", requestId, answers: { post: "Post" } };
+ for (const target of [{}, { environmentId: "linked-test-environment" }]) {
+ expect(declaredFailure(yield* call({ ...respond, ...target }))).toMatchObject({
+ code: "capability_denied",
+ message: expect.stringContaining("needs a human answer"),
+ });
+ }
+ expect((yield* call({ action: "list" })).structuredContent).toEqual({
+ requestIds: [requestId],
+ });
+ expect((yield* call({ action: "read", requestId })).structuredContent).toEqual({
+ requestId,
+ questions,
+ });
+ }).pipe(
+ Effect.provide(
+ layerThreadToolkit.pipe(
+ Layer.provideMerge(McpHttpServer.layerInProcessMcpServer),
+ Layer.provide(NodeCrypto.layer),
+ Layer.provide(
+ Layer.mock(ThreadManagement.ThreadManagementService)({
+ dispatch: () => Effect.die("An agent's answer must never dispatch or emit events"),
+ getThreadShell: () => Effect.succeed(shell),
+ getProjectThreadRecords: () =>
+ Effect.succeed({
+ ...projection,
+ runtimeRequests: [
+ {
+ id: requestId,
+ nodeId: NodeId.make("root"),
+ providerTurnId: null,
+ nativeRequestRef: null,
+ kind: "user_input",
+ status: "pending",
+ responseCapability: { type: "message" },
+ createdAt: shell.createdAt,
+ resolvedAt: null,
+ },
+ ],
+ turnItems: [
+ {
+ id: TurnItemId.make("previewed-question-item"),
+ threadId,
+ runId: null,
+ nodeId: null,
+ providerThreadId: null,
+ providerTurnId: null,
+ nativeItemRef: null,
+ parentItemId: null,
+ ordinal: 0,
+ status: "running",
+ title: null,
+ startedAt: shell.createdAt,
+ completedAt: null,
+ updatedAt: shell.updatedAt,
+ type: "user_input_request",
+ requestId,
+ questions,
+ },
+ ],
+ }),
+ }),
+ ),
),
),
- ),
- );
-});
+ );
+ },
+);
it("bounds public command rejections and redacts internal dispatch causes", () => {
const command = { commandId: CommandId.make("mcp-core-command"), commandType: "thread.settle" };
diff --git a/apps/server/src/mcp/toolkits/thread/handlers.ts b/apps/server/src/mcp/toolkits/thread/handlers.ts
index c3131813a9a6d..2529bda64fcf7 100644
--- a/apps/server/src/mcp/toolkits/thread/handlers.ts
+++ b/apps/server/src/mcp/toolkits/thread/handlers.ts
@@ -286,26 +286,10 @@ export const layer = McpToolAccess.toLayer(ThreadToolkit, {
return { requestId, questions: item.questions };
}),
),
- writesThread((input) =>
- Effect.gen(function* () {
- const requestId = yield* required(input.requestId, "requestId");
- const answers = yield* required(input.answers, "answers");
- const { threads, projection } = yield* readQuestion({
- threadId: input.threadId,
- requestId,
- });
- const result = yield* threads
- .dispatch({
- type: "runtime-request.respond",
- threadId: projection.thread.id,
- commandId: yield* newCommandId(),
- requestId,
- answers,
- // An agent's answer is an agent's message, never a person's.
- createdBy: "agent",
- })
- .pipe(Effect.mapError(dispatchFailure));
- return { sequence: result.sequence };
+ McpToolAccess.refuses(
+ new OrchestratorMcpFailure({
+ code: "capability_denied",
+ message: "This user-input card needs a human answer. Ask a person to answer it in T3 Code.",
}),
),
),
diff --git a/apps/server/src/mcp/toolkits/thread/tools.ts b/apps/server/src/mcp/toolkits/thread/tools.ts
index b39d46216e4e4..e9f72c6e75a1b 100644
--- a/apps/server/src/mcp/toolkits/thread/tools.ts
+++ b/apps/server/src/mcp/toolkits/thread/tools.ts
@@ -133,7 +133,7 @@ const question = Schema.Struct({
const PendingRequestTool = Tool.make("t3_pending_request", {
...commandTool,
description:
- "User questions only (default: this thread). List IDs, read by `requestId`, respond with `answers`. No permission approvals.",
+ "User questions only (default: this thread). List IDs or read by `requestId`. A person answers these cards in T3 Code.",
parameters: Schema.Struct({
action: Schema.Literals(["list", "read", "respond"]),
environmentId: OrchestratorMcpEnvironmentTarget,
diff --git a/apps/server/src/provider/agentContextBudget.json b/apps/server/src/provider/agentContextBudget.json
index c2084d57162bb..6e7a9bd30b8f6 100644
--- a/apps/server/src/provider/agentContextBudget.json
+++ b/apps/server/src/provider/agentContextBudget.json
@@ -1,5 +1,5 @@
{
"claudeSystemAppendBytes": 5930,
"codexAdditionalContextBytes": 7324,
- "mcpToolListJsonBytes": 55827
+ "mcpToolListJsonBytes": 55821
}