Skip to content

[FEATURE]: Granular per-agent tool permissions (allow/deny individual tools) #17607

Description

@Jehu

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 not edit or bash
  • Agent B may use edit and bash but not mcp__muninn__*
  • Agent C may use mcp__github__* but not mcp__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:

  1. session.permission — blocks denied tool categories via permission dialog
  2. body.tools in the API message — pre-filters the tool list before the LLM sees it (using the deprecated but functional tools field)

This works but is fragile:

  • body.tools is 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__*)
  • allow acts as whitelist — only listed tools are available
  • deny acts as blacklist — all tools except listed are available
  • If both specified, deny takes 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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions