( server: McpServer, config: ServerConfig, workspaces: WorkspaceRegistry, processSessions: ProcessSessionManager, )
| 510 | } |
| 511 | |
| 512 | function registerCodexProcessTools( |
| 513 | server: McpServer, |
| 514 | config: ServerConfig, |
| 515 | workspaces: WorkspaceRegistry, |
| 516 | processSessions: ProcessSessionManager, |
| 517 | ): void { |
| 518 | registerAppTool( |
| 519 | server, |
| 520 | "exec_command", |
| 521 | { |
| 522 | title: "Execute command", |
| 523 | description: |
| 524 | "Run a command inside an open workspace. Returns its result when it exits during the yield window, otherwise returns a sessionId for write_stdin. Use this for file inspection, tests, builds, package scripts, and long-running processes. Call open_workspace first and pass workspaceId.", |
| 525 | inputSchema: { |
| 526 | workspaceId: z.string().describe("Workspace identifier returned by open_workspace."), |
| 527 | cmd: z.string().min(1).describe("Shell command to execute."), |
| 528 | tty: z |
| 529 | .boolean() |
| 530 | .optional() |
| 531 | .describe("Allocate a pseudo-terminal for interactive commands. Defaults to false."), |
| 532 | columns: z.number().int().min(1).max(1_000).optional().describe("Initial PTY width. Defaults to 80."), |
| 533 | rows: z.number().int().min(1).max(1_000).optional().describe("Initial PTY height. Defaults to 24."), |
| 534 | workingDirectory: z |
| 535 | .string() |
| 536 | .optional() |
| 537 | .describe("Working directory relative to the workspace root. Defaults to the workspace root."), |
| 538 | yieldTimeMs: z |
| 539 | .number() |
| 540 | .int() |
| 541 | .min(0) |
| 542 | .max(30_000) |
| 543 | .optional() |
| 544 | .describe("Milliseconds to wait before returning a running session. Defaults to 10000."), |
| 545 | maxOutputTokens: z |
| 546 | .number() |
| 547 | .int() |
| 548 | .positive() |
| 549 | .max(100_000) |
| 550 | .optional() |
| 551 | .describe("Approximate output token budget. Defaults to 10000."), |
| 552 | }, |
| 553 | outputSchema: processOutputSchema(), |
| 554 | ...toolWidgetDescriptorMeta(config, "shell"), |
| 555 | annotations: SHELL_TOOL_ANNOTATIONS, |
| 556 | }, |
| 557 | async ({ workspaceId, cmd, tty, columns, rows, workingDirectory, yieldTimeMs, maxOutputTokens }) => { |
| 558 | const startedAt = performance.now(); |
| 559 | const workspace = workspaces.getWorkspace(workspaceId); |
| 560 | const cwd = workspaces.resolveWorkingDirectory(workspace, workingDirectory); |
| 561 | const snapshot = await processSessions.start({ |
| 562 | workspaceId, |
| 563 | command: cmd, |
| 564 | cwd, |
| 565 | tty, |
| 566 | columns, |
| 567 | rows, |
| 568 | yieldTimeMs, |
| 569 | maxOutputTokens, |
no test coverage detected