The open-source agent harness - the runtime layer that turns an LLM into a working agent.
Allow disabling tool approvals entirely or enabling it on specific tools (#125)
Chirag Jain88dfbbc00661
diff --git a/packages/harness/src/core/mcp/ToolSelectorPolicy.ts b/packages/harness/src/core/mcp/ToolSelectorPolicy.tsindex b72d15592..acc72ba27 100644--- a/packages/harness/src/core/mcp/ToolSelectorPolicy.ts+++ b/packages/harness/src/core/mcp/ToolSelectorPolicy.ts@@ -104,14 +104,11 @@ export class ToolSelectorPolicy {}/**- * Approvals are always enabled. Required if the agent's own selectors match OR the tool is- * write/destructive — the default set is a floor the per-agent selectors can widen but never- * drop below.+ * Whether the tool requires human approval. Honors `requireApprovalForTools` exactly: omit /+ * undefined defaults to write+destructive (constructor); an explicit list — including empty —+ * is exact.*/requiresApproval(toolName: string, annotations: ToolAnnotations | undefined): boolean {- return (- toolRequiresApproval(toolName, annotations, this.requireApprovalForTools) ||- toolRequiresApproval(toolName, annotations, DEFAULT_REQUIRE_APPROVAL_FOR_TOOLS)- );+ return toolRequiresApproval(toolName, annotations, this.requireApprovalForTools);}}diff --git a/packages/harness/tests/core/mcp/remoteMcpServer.test.ts b/packages/harness/tests/core/mcp/remoteMcpServer.test.tsindex 3ecb2af15..50881302f 100644--- a/packages/harness/tests/core/mcp/remoteMcpServer.test.ts+++ b/packages/harness/tests/core/mcp/remoteMcpServer.test.ts@@ -222,17 +222,39 @@ describe('RemoteMCP + ToolSet', () => {expect(state.callToolCalls).toBe(0);});- it('enforces the write/destructive approval floor even when the agent narrows require_approval_for_tools', async () => {+ it('honors an empty require_approval_for_tools list (no approvals)', async () => {const state = installFakeConnection();- // Agent explicitly clears its approval selectors; the write/destructive floor must still apply.const server = makeServer({selectors: { enableTools: ['@all'], disableTools: [], preloadTools: [], requireApprovalForTools: [] },});await server.listTools();const res = await server.callTool({ name: 'write_thing', arguments: {} });- expect(isApprovalRequiredResponse(res)).toBe(true);+ if (!isCallToolResponseResult(res)) throw new Error('expected result response');+ expect(res.result.isError).toBeFalsy();+ expect(state.callToolCalls).toBe(1);+ });++ it('honors literal require_approval_for_tools without gating other write tools', async () => {+ const state = installFakeConnection();+ const server = makeServer({+ selectors: {+ enableTools: ['@all'],+ disableTools: [],+ preloadTools: [],+ requireApprovalForTools: ['write_thing'],+ },+ });+ await server.listTools();++ const gated = await server.callTool({ name: 'write_thing', arguments: {} });+ expect(isApprovalRequiredResponse(gated)).toBe(true);expect(state.callToolCalls).toBe(0);++ const ungated = await server.callTool({ name: 'read_thing', arguments: {} });+ if (!isCallToolResponseResult(ungated)) throw new Error('expected result response');+ expect(ungated.result.isError).toBeFalsy();+ expect(state.callToolCalls).toBe(1);});it('short-circuits a denied tool call without hitting the transport', async () => {