Repository navigation
[FEATURE]: Granular per-agent tool permissions (allow/deny individual tools) #17607
Description
Feature hasn't been suggested before.
- I have verified this feature I'm about to request hasn't been suggested before.
Note: #5529 requests per-agent filesystem boundaries (path-level sandboxing). Our request is complementary but different: we need tool-level granularity — controlling which specific tools (built-in and MCP) each agent can access, not which filesystem paths.
Describe the enhancement you want to request
Problem: OpenCode's per-agent permission config only supports coarse categories (allow, ask, deny for read, edit, bash, mcp). There is no way to allow/deny individual tools per agent.
For example, you cannot express:
- Agent A may use
mcp__muninn__*tools but noteditorbash - Agent B may use
editandbashbut notmcp__muninn__* - Agent C may use
mcp__github__*but notmcp__docker__*
Why this matters: In multi-agent orchestration systems, different agents have different roles with different trust levels. A PM agent should access project management tools but never edit code. A dev agent should edit code but not access CRM tools. Currently, MCP tools are all-or-nothing — mcp: "allow" grants access to every registered MCP server.
Current workaround: We use two layers:
session.permission— blocks denied tool categories via permission dialogbody.toolsin the API message — pre-filters the tool list before the LLM sees it (using the deprecated but functionaltoolsfield)
This works but is fragile:
body.toolsis deprecated and may be removed- Session permissions are too coarse (can't distinguish between MCP servers)
- The workaround requires maintaining an allowlist externally
Proposed solution: Extend the per-agent permission config to support tool-level granularity:
{
"agents": {
"pm-agent": {
"tools": {
"allow": ["mcp__muninn__*", "mcp__huginn__*", "read"],
"deny": ["edit", "bash", "mcp__docker__*"]
}
},
"dev-agent": {
"tools": {
"allow": ["edit", "bash", "read", "glob", "grep"],
"deny": ["mcp__muninn__*", "mcp__crm__*"]
}
}
}
}Key design points:
- Glob patterns for MCP tool names (e.g.,
mcp__server__*) allowacts as whitelist — only listed tools are availabledenyacts as blacklist — all tools except listed are available- If both specified,
denytakes precedence - Default behavior unchanged (all tools available) for backwards compatibility
Use cases:
- Multi-agent orchestration with role-based tool access
- Security isolation — prevent agents from accessing tools outside their domain
- Compliance — audit which agents can access which external services
- Reduced token usage — agents with fewer tools need less system prompt space
Related: #5529 (filesystem boundaries — complementary but different scope)
Environment: OpenCode v1.2.25. The user.tools filtering in the API still works as a workaround but the field is marked deprecated.
Activity
github-actions commentedon Mar 15, 2026
This issue might be a duplicate of existing issues. Please check:
Jehu commentedon Mar 15, 2026
Thanks for flagging the related issues. I've reviewed both:
[FEATURE]: Granular permission pattern matching for MCP tools #12358 addresses granular permission prompts for MCP tools (pattern matching on tool input parameters like
operation=read). Our request is about controlling which tools an agent sees at all, not about the permission prompt behavior for individual invocations.[FEATURE]: Filter which tools are loaded from MCP servers (includeTools/excludeTools) #7399 is the closest match —
includeTools/excludeToolsper MCP server plus per-agent MCP overrides covers a significant part of our use case. However, our request goes slightly further: we also need per-agent control over built-in tools (e.g., agent A getsedit+bash, agent B only getsread+glob), not just MCP tool filtering.If #7399 gets implemented with the per-agent override pattern shown there, it would solve ~80% of our needs. We'd still want built-in tool filtering per agent, but that could be a follow-up.
Happy to close this as a duplicate of #7399 if the maintainers prefer — or keep it open as an extension that covers built-in tools as well.
Jehu commentedon Mar 15, 2026
Bug Report:
body.toolsoverwrites session permissionsWhile working around the missing granular tool permissions, we discovered a concrete bug in the current implementation:
Location:
packages/opencode/src/session/prompt.ts(lines ~170-181)Impact: When
body.toolsis sent on a message, it replaces the session-level permissions set viacreate_session(permission=...)instead of merging with them. This means:body.toolsbody.toolsdict (but denied at session level) revert to the default"ask"behavior — effectively bypassing the deny rulesOur workaround: We stopped sending
body.toolsentirely and rely exclusively oncreate_session(permission=...)for tool access control.Suggested fix: Either merge
body.toolspermissions with existing session permissions, or document thatbody.toolsis a full replacement (and ideally deprecate it in favor of session-level permissions only).This is directly relevant to this issue — even if per-agent tool filtering is implemented, the overwrite behavior would break any multi-message session where permissions are set at creation time.
stuckinsnow commentedon May 14, 2026
Another vote for this. I think it should allow custom modes/agents in config that can be activated via
session/set_mode, that way you can switch in the same session. But also, adding a prompt in the config would be worthwhile as well. For example...{ "agent": { "reviewer": { "mode": "primary", "prompt": "You are in review mode. You are read-only. Report findings using the annotation tool.", "tools": { "read": true, "grep": true, "glob": true, "edit": false, "write": false, "bash": false }, "mcp": { // Only these MCP server tools are visible to the model in this mode "annotation-server": true, "file-editor-server": false } }, "scoped-editor": { "mode": "primary", "prompt": "Use the file_edit MCP tool to make changes. If rejected, move on.", "tools": { "edit": false, "write": false }, "mcp": { "file-editor-server": true, "annotation-server": false } } } }Then an ACP client sends
session/set_modewith{"modeId": "reviewer"}and the model's visible tools and system prompt switch accordingly, so it's more knowledgeable as to what happened in the switch.rekram1-node commentedon Jun 23, 2026
the
toolsthing isnt recommended, u can usepermissionsto achieve all this, see our docs for example