Skip to content
Merged
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
13 changes: 13 additions & 0 deletions apps/server/src/mcp/toolkits/orchestrator/tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ it("refuses a t3_thread_update whose fields do not fit its action", () => {
);
});

it("accepts a single taskId for t3_background_wait", () => {
const tool = OrchestratorToolkit.tools.t3_background_wait;
const decode = Schema.decodeUnknownExit(tool.parametersSchema);
expect(decode({ taskId: "a" })).toEqual(Exit.succeed({ taskIds: ["a"], waiting: undefined }));
expect(decode({ taskIds: ["a"], taskId: "b", waiting: false })).toEqual(
Exit.succeed({ taskIds: ["a", "b"], waiting: false }),
);
expect(String(decode({}))).toContain("Pass `taskIds`");
// The MCP server rejects arguments the advertised schema does not declare.
const advertised = Tool.getJsonSchema(tool) as { readonly properties: object };
expect(Object.keys(advertised.properties)).toEqual(["taskIds", "taskId", "waiting"]);
});

const parseExample = Schema.decodeSync(Schema.fromJsonString(Schema.Unknown));
const exampleTools = [
{
Expand Down
36 changes: 33 additions & 3 deletions apps/server/src/mcp/toolkits/orchestrator/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ import {
TrimmedNonEmptyString,
} from "@t3tools/contracts";
import { McpSchema, Tool, Toolkit } from "effect/ai";
import * as Effect from "effect/Effect";
import * as Schema from "effect/Schema";
import * as SchemaIssue from "effect/SchemaIssue";
import * as SchemaTransformation from "effect/SchemaTransformation";
import * as Struct from "effect/Struct";

import * as ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts";
Expand Down Expand Up @@ -145,16 +148,43 @@ const WorkflowStopTool = Tool.make("t3_workflow_stop", {
.annotate(Tool.Title, "Stop a workflow")
.annotate(Tool.Destructive, true);

const backgroundWaitParameters = Schema.Struct({
taskIds: Schema.Array(TrimmedNonEmptyString).check(Schema.isMinLength(1), Schema.isMaxLength(20)),
const BackgroundTaskIds = Schema.Array(TrimmedNonEmptyString).check(
Schema.isMinLength(1),
Schema.isMaxLength(20),
);
const BackgroundWaitInput = Schema.Struct({
taskIds: BackgroundTaskIds,
waiting: Schema.optional(Schema.Boolean),
});
// Agents often pass a single `taskId`, the shape of Claude Code's own task tools.
const backgroundWaitParameters = Schema.Struct({
taskIds: Schema.optional(BackgroundTaskIds),
taskId: Schema.optional(TrimmedNonEmptyString),
waiting: Schema.optional(Schema.Boolean),
}).pipe(
Schema.decodeTo(
BackgroundWaitInput,
SchemaTransformation.transformEffect({
decode: ({ taskIds = [], taskId, waiting }) => {
const ids = taskId === undefined ? taskIds : [...taskIds, taskId];
return ids.length === 0
? Effect.fail(
new SchemaIssue.InvalidValue({
message: 'Pass `taskIds`, e.g. `{"taskIds":["<id>"]}`.',
}),
)
: Effect.succeed<typeof BackgroundWaitInput.Type>({ taskIds: ids, waiting });
},
encode: (value) => Effect.succeed(value),
}),
),
);
const backgroundWaitExample = {
taskIds: ["task-123"],
} satisfies typeof backgroundWaitParameters.Encoded;

const BackgroundWaitTool = Tool.make("t3_background_wait", {
description: `Keep this thread in Working while background work runs. Pass its task IDs after starting it. Not for dev servers or watchers. \`waiting=false\` clears without stopping tasks. Claude only. Example: \`${Schema.encodeSync(Schema.fromJsonString(Schema.Unknown))(backgroundWaitExample)}\`.`,
description: `Keep this thread in Working while background work runs. Pass its task IDs once started. Not for dev servers or watchers. \`waiting=false\` clears without stopping tasks. Claude only. Example: \`${Schema.encodeSync(Schema.fromJsonString(Schema.Unknown))(backgroundWaitExample)}\`.`,
parameters: backgroundWaitParameters,
success: Schema.Struct({
matched: Schema.Array(Schema.String),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1932,7 +1932,7 @@ const CLAUDE_BACKGROUND_WAIT_INSTRUCTIONS = `

### Background work you wait on

To wait for a background command or Monitor you started (tests, a build), call \`t3_background_wait\` with its task ID before you end your turn. Do not mark work you leave running, or PRs. T3 MCP tools are deferred: load one with ToolSearch before you call it.
To wait for a background command or Monitor you started (tests, a build), call \`t3_background_wait\` with \`taskIds\` before you end your turn. Do not mark work you leave running, or PRs. T3 MCP tools are deferred: load one with ToolSearch before you call it.
`;

// Native subagents start from their task, not this session's system prompt.
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/provider/agentContextBudget.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"claudeSystemAppendBytes": 5680,
"claudeSystemAppendBytes": 5678,
"codexAdditionalContextBytes": 7410,
"mcpToolListJsonBytes": 59344
"mcpToolListJsonBytes": 59343
}
Loading