Skip to content

fix: respect agent allowed_tools in MCP auto-approval check#12965

Merged
kangfenmao merged 4 commits intoCherryHQ:mainfrom
lucamorettibuilds:fix/mcp-auto-approve-agent-tools
Mar 4, 2026
Merged

fix: respect agent allowed_tools in MCP auto-approval check#12965
kangfenmao merged 4 commits intoCherryHQ:mainfrom
lucamorettibuilds:fix/mcp-auto-approve-agent-tools

Conversation

@lucamorettibuilds
Copy link
Copy Markdown
Contributor

Summary

Fixes #12779 — MCP tools cannot be auto-approved when configured through agent allowed_tools.

Problem

When a user configures an agent with specific allowed_tools, those tools still require manual approval in the MCP tool execution flow. The isToolAutoApproved function only checks server-level auto-approve settings and built-in status, ignoring the agent-level allowlist.

Changes

  • src/renderer/src/utils/mcp-tools.ts: Added allowedTools parameter to isToolAutoApproved(). When a tool ID appears in the agent's allowedTools list, it returns true for auto-approval.
  • src/renderer/src/aiCore/utils/mcp.ts: Threaded allowedTools parameter through setupToolsConfig() and convertMcpToolsToAiSdkTools() so the execute callback can pass it to the approval check.
  • src/renderer/src/pages/home/Messages/Tools/hooks/useMcpToolApproval.ts: Wired useActiveAgent() hook to read the current agent's allowed_tools config and pass it into the approval check.

Testing

Verified locally that:

  • Tools in agent allowed_tools are auto-approved without manual confirmation
  • Tools NOT in the allowlist still require approval as before
  • Built-in tools remain auto-approved regardless
  • Server-level auto-approve settings continue to work unchanged

When an agent has allowed_tools configured, the auto-approval check
now considers those tools as pre-authorized. Previously, agent-level
tool allowlists were ignored in the auto-approval flow, requiring
manual approval even for tools explicitly allowed in agent settings.

Changes:
- Pass allowedTools through setupToolsConfig and convertMcpToolsToAiSdkTools
- Add allowedTools parameter to isToolAutoApproved utility
- Wire useActiveAgent hook into useMcpToolApproval to read agent config

Fixes CherryHQ#12779
@DeJeune DeJeune requested a review from EurFelux February 19, 2026 14:40
@DeJeune DeJeune self-assigned this Feb 19, 2026
Copy link
Copy Markdown
Collaborator

@DeJeune DeJeune left a comment

Choose a reason for hiding this comment

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

PR #12965 Review: fix: respect agent allowed_tools in MCP auto-approval check

Summary

The PR adds agent-level allowed_tools as an auto-approval source for MCP tools. The core logic change in isToolAutoApproved is correct, but there are two significant gaps where call sites are missed, and a security consideration worth discussing.

Issues

1. Missing allowedTools at the primary call site in parameterBuilder.ts (Bug)

The most important call site — parameterBuilder.ts:133 — still calls setupToolsConfig(mcpTools) without passing allowedTools. This is the new AI SDK pipeline's entry point for tool setup. The PR only threads allowedTools through the function signatures but the actual caller in the new pipeline never provides it, meaning the fix is incomplete for the main code path.

2. Missing allowedTools in legacy middleware McpToolChunkMiddleware.ts (Bug)

McpToolChunkMiddleware.ts:442 calls isToolAutoApproved(toolResponse.tool, server) without the new allowedTools parameter. Users on the legacy client path won't get agent-level auto-approval either.

3. Missing allowedTools in UI indicator components (Cosmetic inconsistency)

ToolHeader.tsx:238 and MessageMcpTool.tsx:138 both call isToolAutoApproved(tool) without allowedTools. These render the shield-check icon indicating a tool is auto-approved. A tool that's auto-approved via allowed_tools won't show the icon, confusing users.

4. Security consideration: allowedTools check uses tool.id — verify this is tamper-proof

The new check is allowedTools?.includes(tool.id). If a malicious MCP server could craft a tool.id matching an allowed tool from a different server, it could bypass approval. Worth confirming that tool.id includes the serverId suffix making cross-server spoofing unlikely.

Minor Notes

  • Tests should be added for isToolAutoApproved with the new allowedTools parameter.
  • The McpTool.tsx settings page calls don't need allowedTools — they show server-level config, which is correct.

Verdict

The core approach is sound, but the PR is incomplete — the main call site (parameterBuilder.ts) doesn't actually pass allowedTools, so the fix won't work in the new AI SDK pipeline. The legacy middleware path is also missed. Please address issues #1 and #2 before merging.

@DeJeune
Copy link
Copy Markdown
Collaborator

DeJeune commented Feb 20, 2026

Issue 2 doesn’t need to be fixed; it’s already deprecated.

Address review feedback from DeJeune on CherryHQ#12965:

- Add allowedTools to FetchChatCompletionParams (BaseParams)
- Thread allowedTools through ApiService (transformMessagesAndFetch → fetchChatCompletion)
- Pass allowedTools to buildStreamTextParams → setupToolsConfig
- Fetch agent allowed_tools in messageThunk via AgentApiClient
- Drop legacy middleware changes (already deprecated per reviewer)

Issue CherryHQ#1: parameterBuilder now passes allowedTools to setupToolsConfig
Issue CherryHQ#2: Skipped — legacy middleware is deprecated
Issue CherryHQ#3: UI indicator changes deferred to follow-up
Copy link
Copy Markdown
Contributor Author

@lucamorettibuilds lucamorettibuilds left a comment

Choose a reason for hiding this comment

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

Thanks for the detailed review @DeJeune! I've pushed a fix addressing your feedback:

Issue #1 (parameterBuilder): allowedTools is now threaded from agent data all the way through: messageThunktransformMessagesAndFetchfetchChatCompletionbuildStreamTextParamssetupToolsConfig. The thunk fetches the agent's allowed_tools via AgentApiClient when activeAgentId is set.

Issue #2 (legacy middleware): Reverted — agreed it's deprecated and doesn't need the fix.

Issue #3 (UI indicators): Will address in a follow-up — the shield icon in ToolHeader.tsx needs store access to get allowedTools, which is a slightly different pattern.

Issue #4 (tool.id security): Good point about cross-server spoofing. The current isToolAutoApproved already scopes approval by checking the server's autoApproveAll setting alongside the tool match. But I agree a namespaced format like serverName:toolName would be more robust — happy to discuss further.

Let me know if this looks better!

Copy link
Copy Markdown
Collaborator

@EurFelux EurFelux left a comment

Choose a reason for hiding this comment

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

LGTM. I verified the allowed_tools threading from message thunk through parameter builder into MCP auto-approval checks, and the UI hook now reflects agent-level pre-approval for pending MCP calls.

@DeJeune DeJeune requested a review from kangfenmao February 28, 2026 02:11
@DeJeune DeJeune modified the milestones: v1.7.16, v1.7.22 Feb 28, 2026
@kangfenmao kangfenmao merged commit bbd3de7 into CherryHQ:main Mar 4, 2026
7 checks passed
@SiinXu SiinXu mentioned this pull request Mar 20, 2026
5 tasks
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.

[Bug]: MCP Cannot Be Auto-Approved

4 participants