opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: Add Permission Control for MCP Tools

Open thuanpham582002 opened this issue 1 year ago • 2 comments

Summary: MCP tools currently bypass OpenCode's permission system while built-in tools require approval. Add permission control for MCP tools.

Problem

Currently, MCP (Model Context Protocol) tools completely bypass OpenCode's permission system: Built-in tools (have permission checks):

await Permission.ask({
  type: "bash",
  pattern: patterns,
  sessionID: ctx.sessionID,
   ... approval flow
})

MCP tools (bypass permission system):

In packages/opencode/src/session/prompt.ts

for (const [key, item] of Object.entries(await MCP.tools())) {
  item.execute = async (args, opts) => {
     NO Permission.ask() here!
    await Plugin.trigger("tool.execute.before", ...)
    const result = await execute(args, opts)
    await Plugin.trigger("tool.execute.after", ...)
    return { output }
  }
}

Security Concerns

• No user control: MCP tools can execute without approval • Inconsistent security: Built-in tools require approval, MCP tools don't • Potential abuse: Malicious MCP servers could perform harmful actionsl

thuanpham582002 avatar Sep 23 '25 17:09 thuanpham582002

totally agree

rekram1-node avatar Sep 23 '25 17:09 rekram1-node

this will be done as part of: #1961

rekram1-node avatar Sep 23 '25 19:09 rekram1-node