Skip to content

fix(acp): make configured MCP tools callable - #1003

Open
gnanam1990 wants to merge 1 commit into
mainfrom
fix/998-mcp-tools-callable
Open

fix(acp): make configured MCP tools callable#1003
gnanam1990 wants to merge 1 commit into
mainfrom
fix/998-mcp-tools-callable

Conversation

@gnanam1990

@gnanam1990 gnanam1990 commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Fixes #998.

ACP now builds the same scoped MCP-enabled registry as zero exec for each turn. Configured MCP servers run through the sandbox execution runner, respect workspace trust, use low autonomy, are omitted in plan mode, and are closed after success, failure, or cancellation. tool_search is registered after the full ACP-visible registry is built.

Verification:

  • make fmt-check, go vet ./..., go test ./...
  • focused ACP/CLI race checks (-count=20)
  • go run ./cmd/zero-release build and smoke
  • make lint-static, make vulncheck, diff check
  • packaged ZeroApp smoke: ACP handshake, workspace open, environment/sidebar/terminal panels

The storage-heavy mutation sweep was intentionally not run under the active storage-safety restriction.

Summary by CodeRabbit

  • Bug Fixes

    • Improved cleanup of workspace resources after successful, failed, or cancelled agent turns.
    • Permission-prompt cancellations are now reported with the correct cancelled status.
    • Ensured partially initialized tool runtimes are cleaned up when setup fails.
  • Behavior Updates

    • MCP tools are limited in plan mode and enabled according to workspace permissions.
    • Deferred tool search is now available in ACP workspaces.

@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Essentials

Run ID: 8d666841-b432-40b4-bf90-fc510264501e

📥 Commits

Reviewing files that changed from the base of the PR and between 1b5db17 and 185619e.

📒 Files selected for processing (4)
  • internal/acp/agent.go
  • internal/acp/agent_test.go
  • internal/cli/acp.go
  • internal/cli/acp_test.go

Included review availability: 4 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.


Walkthrough

ACP now creates a scoped workspace for each turn. The workspace carries the registry, sandbox, and cleanup callback. MCP tools register for non-plan modes, while failed initialization and turn completion close resources correctly.

Changes

ACP workspace lifecycle

Layer / File(s) Summary
Workspace contract and turn lifecycle
internal/acp/agent.go, internal/acp/agent_test.go
BuildWorkspace now receives context and permission mode and returns a Workspace. runTurn validates, uses, and closes the workspace. Tests cover cleanup after successful and failed turns.
Scoped MCP workspace construction
internal/cli/acp.go, internal/cli/acp_test.go
ACP builds sandbox and registry resources through buildACPWorkspace. Non-plan modes register MCP tools, plan mode suppresses MCP startup, and failure paths close partial runtimes. Tests cover registration, deferred tool search, and cleanup.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 18561

The PR makes configured MCP tools callable in ACP and includes the stated validation checks; no actionable merge-blocking risk remains beyond normal review.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant ACP as runTurn
  participant Workspace as buildACPWorkspace
  participant MCP as MCP runtime
  participant Agent
  Client->>ACP: start turn
  ACP->>Workspace: create with context and permission mode
  Workspace->>MCP: register tools when mode is not plan
  Workspace-->>ACP: return scoped Workspace
  ACP->>Agent: execute with registry and sandbox
  Agent-->>ACP: return result
  ACP->>Workspace: close resources
  ACP-->>Client: return turn result
Loading

Suggested reviewers: pierrunoyt, euxaristia

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary change: making configured MCP tools callable in ACP.
Linked Issues check ✅ Passed The changes address issue #998 by building an MCP-enabled ACP registry, registering configured MCP tools for invocation, and covering trusted, plan-mode, and cleanup behavior with tests.
Out of Scope Changes check ✅ Passed The workspace lifecycle, permission handling, trust checks, plan-mode behavior, and cleanup changes directly support safe MCP tool registration and invocation in ACP.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/998-mcp-tools-callable

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Zero automated PR review

Verdict: No blockers found

Blockers

  • None found.

Validation

  • [pass] Diff hygiene: git diff --check
  • [pass] Tests: go test ./...
  • [pass] Build: go run ./cmd/zero-release build
  • [pass] Smoke build: go run ./cmd/zero-release smoke

Scope

Head: 185619e05600
Changed files (4): internal/acp/agent.go, internal/acp/agent_test.go, internal/cli/acp.go, internal/cli/acp_test.go

This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found issues that need to be addressed before this is ready.

Findings

  • [P1] Make newly configured MCP tools visible in the default ACP mode
    internal/cli/acp.go:97
    This registers real MCP tools into the per-turn workspace, but a fresh ACP session starts in PermissionModeAuto, while mcp.newRegistryTool gives an unapproved tool PermissionPrompt without AdvertiseInAuto. agent.ToolAdvertised therefore filters the tool out before the provider sees it. The same visibility result is used by registerToolSearchIfEligible, so a fresh set of MCP tools also contributes zero eligible tools and does not produce a discovery loader. The new test misses the production path because cliFakeDeferredTool reports PermissionAllow; registry membership consequently passes even though the provider-visible set for a real fresh tool is empty.

    The root cause is the mismatch between ACP's default mode, the safety metadata assigned to MCP tools, and the visibility-aware loader count—not MCP connection or registration itself. Please align those seams so a newly configured MCP tool is discoverable and callable through the ordinary ACP workflow while its execution still requires the existing low-autonomy permission prompt. Avoid fixing this by converting MCP actions to pre-approved actions, weakening plan mode, or globally changing unrelated surfaces. Add an end-to-end regression using production-equivalent PermissionPrompt MCP safety and assert what the ACP provider actually receives in the default mode.

  • [P2] Pass one effective defer threshold through both ACP consumers
    internal/acp/agent.go:296
    buildACPWorkspace reads resolved.Tools.DeferThreshold and may register tool_search, but this agent.Options literal does not pass the same value to the agent. Its zero value reaches partitionToolsCached, where deferral is active only when options.DeferThreshold > 0; the inactive path removes tool_search and eagerly advertises every visible MCP schema. As a result, the loader asserted by TestBuildACPWorkspaceRegistersSandboxedMCPToolsAndClosesThem is never provider-visible, the default threshold of 3 is ignored, and larger MCP installations pay the full schema/context cost on every turn.

    The root cause is split ownership of a single configuration contract: workspace construction consumes the threshold, while the downstream partition independently receives an unset value. Please derive one effective ACP threshold and carry it through loader registration and agent.Options, as the sibling exec/TUI paths do. Cover the complete behavior—not only registry membership—by asserting that at/above threshold the provider receives tool_search while eligible schemas remain deferred. Preserve explicit zero-disable, below-threshold eager exposure, and plan-mode suppression; this does not require redesigning generic deferral.

  • [P2] Preserve and surface MCP setup diagnostics across the workspace boundary
    internal/cli/acp.go:97
    The helper returns two non-fatal diagnostic channels: trustSkip explains when project MCP configuration was excluded by the fail-closed trust gate, and runtime.Skipped() records configured servers that timed out, failed to connect, returned invalid tools, or conflicted by name. This new caller assigns the trust result to _ and retains only runtime.Close, so both outcomes are discarded. The turn then proceeds with a reduced registry and no explanation; to an ACP user, an untrusted project or failed configured server is indistinguishable from the original “MCP tools are not callable” defect. Other consumers explicitly emit the zero trust guidance and redacted configured-server warnings.

    The root cause is an incomplete workspace result/ownership contract: Workspace carries the registry, sandbox, and cleanup callback, but no setup notices survive long enough for the ACP boundary to report them. Please retain the trust and configured-server skip results and surface them through an ACP-safe, redacted diagnostic path. The implementation can choose the appropriate ACP notification or stderr route, but it must not corrupt stdout JSON-RPC framing. Keep trust fail-closed, keep multi-server startup best-effort, keep hard setup errors as errors, and keep unconfigured default-server failures silent; making optional server failure fatal or bypassing trust would introduce scope and behavioral drift.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP tools are not callable

2 participants