The open-source app everyone uses to manage agents at work
TypeScript acpxagent-orchestrationagent-skillsagentic-aiai-agentsai-engineeringai-governanceai-toolsautonomous-agentsclaudeclaude-codeclaude-skillscodexhermesllmmcpmulti-agentopenclawproject-managementworkflow-automation
fix(acpx): bound Claude MCP tool calls when runtime MCP servers attach (#16360)
Devin Foley3935e300dde6
diff --git a/doc/MCP-RUNTIME-OPERATIONS.md b/doc/MCP-RUNTIME-OPERATIONS.mdindex 9a05b0157a..011c5c6fbb 100644--- a/doc/MCP-RUNTIME-OPERATIONS.md+++ b/doc/MCP-RUNTIME-OPERATIONS.md@@ -36,6 +36,18 @@ delivery path. Managed gateway discovery excludes historical native assignments.Their stored rows remain available for existing runs. Explicit company gatewayscontinue to use their configured scopes.+## Client-side tool-call deadline++The gateway bounds each provider call, but the agent's MCP client also needs a+bound. Without one, a gateway request that never answers holds the agent turn+until the adapter execution timeout ends the run. Claude's default MCP tool+timeout is far longer than a run, and ACP `mcpServers` entries have no+per-server timeout field. So when an ACP Claude run receives runtime MCP+servers, the ACPX engine sets `MCP_TOOL_TIMEOUT` to 15 minutes. A call that+passes this deadline returns an MCP error to the model, and the turn+continues. An `MCP_TOOL_TIMEOUT` value in the adapter `env` configuration+takes priority.+## MetricsThe board runtime health API summarizes one-hour event windows plus current durable slot state:diff --git a/packages/adapter-utils/src/acpx-engine/constants.ts b/packages/adapter-utils/src/acpx-engine/constants.tsindex 1c37dc958c..a3330c29a2 100644--- a/packages/adapter-utils/src/acpx-engine/constants.ts+++ b/packages/adapter-utils/src/acpx-engine/constants.ts@@ -26,6 +26,16 @@ export const ACPX_HANDSHAKE_TRANSPORT_POLL_MS = 250;// much smaller than the whole-adapter execution timeout.export const ACPX_DUPLEX_LOSS_CANCEL_DEADLINE_MS = 30_000;+// The per-call deadline Claude applies to MCP tool calls (`MCP_TOOL_TIMEOUT`)+// when Paperclip attaches runtime MCP servers. Claude's own default is far+// longer than a run, so a gateway call that never answers holds the turn until+// the 4h sandbox backstop ends the run. The gateway bounds each provider call+// at 60s and approval preparation at 2 minutes; this leaves wide headroom over+// both.+// On expiry Claude returns an MCP error to the model and the turn continues.+// A user-configured `MCP_TOOL_TIMEOUT` still wins.+export const ACPX_CLAUDE_MCP_TOOL_TIMEOUT_MS = 15 * 60 * 1000;+// The closed ACP `ToolKind` enum. Run diagnostics may report these labels for// pending tool calls; tool titles, names, and inputs never leave the run.// Any other reported kind is collapsed to "unknown".diff --git a/packages/adapter-utils/src/acpx-engine/execute.test.ts b/packages/adapter-utils/src/acpx-engine/execute.test.tsindex 095996c1f8..2e604a9719 100644--- a/packages/adapter-utils/src/acpx-engine/execute.test.ts+++ b/packages/adapter-utils/src/acpx-engine/execute.test.ts@@ -37,7 +37,7 @@ import {summarizeAcpxTurnUsage,type AcpxEngineExecutorOptions,} from "./execute.js";-import { ACPX_HANDSHAKE_TIMEOUT_MS } from "./constants.js";+import { ACPX_CLAUDE_MCP_TOOL_TIMEOUT_MS, ACPX_HANDSHAKE_TIMEOUT_MS } from "./constants.js";import { sessionCodec } from "./session-codec.js";import { runChildProcess } from "../server-utils.js";import { createPromptContextFixture } from "../test-fixtures/prompt-context.js";@@ -2986,6 +2986,24 @@ describe("shared ACPX engine runtime behavior", () => {expect(third.runtimeOptions[0]?.mcpServers).toEqual([]);});+ it("bounds Claude MCP tool calls only when runtime MCP servers are attached", async () => {+ const server = { name: "paperclip-assigned", url: "https://example.test/mcp/gateways/g", connectionId: "assignment:x", token: "t" };+ const runtimeMcp = { getServers: () => [server] };+ const envOf = (run: { meta: Array<Record<string, unknown>> }) => run.meta[0]?.env as Record<string, string>;++ const bounded = await runExecutor({ agent: "claude" }, { runtimeMcp });+ expect(envOf(bounded).MCP_TOOL_TIMEOUT).toBe(String(ACPX_CLAUDE_MCP_TOOL_TIMEOUT_MS));++ const withoutServers = await runExecutor({ agent: "claude" });+ expect(envOf(withoutServers).MCP_TOOL_TIMEOUT).toBeUndefined();++ const userConfigured = await runExecutor({ agent: "claude", env: { MCP_TOOL_TIMEOUT: "120000" } }, { runtimeMcp });+ expect(envOf(userConfigured).MCP_TOOL_TIMEOUT).toBe("120000");++ const codex = await runExecutor({ agent: "codex" }, { runtimeMcp });+ expect(envOf(codex).MCP_TOOL_TIMEOUT).toBeUndefined();+ });+it("injects runtime MCP servers and fingerprints their identity without persisting bearer tokens", async () => {const root = await makeTempRoot();const baseConfig = {diff --git a/packages/adapter-utils/src/acpx-engine/execute.ts b/packages/adapter-utils/src/acpx-engine/execute.tsindex 01ae1020b8..e052d04ace 100644--- a/packages/adapter-utils/src/acpx-engine/execute.ts+++ b/packages/adapter-utils/src/acpx-engine/execute.ts@@ -106,6 +106,7 @@ import {} from "acpx/runtime";import {ACP_TOOL_KINDS,+ ACPX_CLAUDE_MCP_TOOL_TIMEOUT_MS,ACPX_DUPLEX_LOSS_CANCEL_DEADLINE_MS,ACPX_HANDSHAKE_TIMEOUT_MS,ACPX_HANDSHAKE_TRANSPORT_POLL_MS,@@ -2047,6 +2048,11 @@ async function buildRuntime(input: {if (requestedModel && acpxAgent === "claude" && !env.ANTHROPIC_MODEL) {env.ANTHROPIC_MODEL = requestedModel;}+ // ACP `mcpServers` entries carry no per-server timeout, so bound Claude's+ // MCP tool calls through its env setting instead.+ if (acpxAgent === "claude" && mcpServers.length > 0 && !env.MCP_TOOL_TIMEOUT) {+ env.MCP_TOOL_TIMEOUT = String(ACPX_CLAUDE_MCP_TOOL_TIMEOUT_MS);+ }// Gemini CLI reads GEMINI_MODEL when creating each ACP session. Its ACP// implementation supports set_model, but not set_config_option; configure// the selected model before startup without changing the transport.