fix(opencode): inherit MCP tool allow permissions in subagent sessions#30288
fix(opencode): inherit MCP tool allow permissions in subagent sessions#30288ollikurki wants to merge 1 commit into
Conversation
Subagents spawned via the Task tool could see MCP tools in their tool registry but got permission denied when trying to execute them. The root cause was that deriveSubagentSessionPermission only forwarded deny rules and external_directory rules from the parent session, never copying the allow rules that MCP tools require. MCP tool permission keys contain underscores (e.g. context7_resolve-library-id, matrix_matrix_read) as they follow the sanitize(clientName) + '_' + sanitize(toolName) naming pattern. This fix copies all allow rules whose permission key contains an underscore, which covers MCP tools while leaving native tools (todowrite, task, bash, edit, etc.) unaffected since they don't contain underscores in their permission names. Wildcard '*' allow rules are also forwarded. Co-authored-by: Olli Kurki <kurki.olli@outlook.com> Co-authored-by: AI <ai@opencode.ai>
|
The following comment was made by an LLM, it may be inaccurate: Based on my search results, I found one potential duplicate: PR #30085 - This PR appears to be addressing the exact same issue as the current PR (#30288). Both PRs are focused on granting/inheriting MCP tool permissions in subagent sessions, which are the issues closed by #16491 and #3808. You should verify whether PR #30085 is open and compare its implementation approach with PR #30288 to determine if one should be closed in favor of the other. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
For context: there are other open PRs addressing #16491 (#30085) that take a different approach — they import the MCP service into |
Issue for this PR
Closes #16491, #3808
Type of change
What does this PR do?
Subagents spawned via the Task tool can see MCP tools in their tool registry but get permission denied when trying to execute them. The root cause is that
deriveSubagentSessionPermission()only forwardsdenyrules andexternal_directoryrules from the parent session — never theallowrules that MCP tools require.MCP tool permission keys follow the pattern
sanitize(clientName) + "_" + sanitize(toolName)(e.g.context7_resolve-library-id,matrix_matrix_read). This fix copies allallowrules whose permission key contains an underscore, which covers MCP tools while leaving native opencode tools (todowrite,task,bash,edit, etc.) unaffected since they don't contain underscores in their names. Wildcard*allow rules are also forwarded.In
deriveSubagentSessionPermission()(packages/opencode/src/agent/subagent-permissions.ts), a new filter extracts MCP-allow rules:These are then spread into the returned ruleset alongside the existing deny, external_directory, and task/todowrite defaults. The approach is:
*allow rules are also forwarded for full-permission parent sessionsHow did you verify your code works?
Added 4 new test cases to
packages/opencode/test/agent/plan-mode-subagent-bypass.test.ts:myserver_tool-one,otherclient_resource-list) after parent approved them*allow rules from parentbash: allowin parent does NOT propagate through the underscore filter — evaluates to"ask"(default), not"allow"All 8 tests pass (4 existing + 4 new):
Screenshots / recordings
N/A — no UI changes, purely a permission logic fix.
Checklist