opencode icon indicating copy to clipboard operation
opencode copied to clipboard

[feature request]: ability to dynamic turn on mcp server for specific agent

Open zelifish opened this issue 2 months ago • 10 comments

Hope I'm not doing this wrong, but with this opencode config in version 0.11.1

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "graphql": {
      "type": "local",
      "enabled": false,
      "command": ["bunx", "mcp-graphql"],
      "environment": {
        "ENDPOINT": "http://localhost:13087/graphql"
      }
    }
  }
}

And this agent definition

---
description: test agaent
mode: primary
tools:
  graphql_*: true
---

This is a test agent

My agent can't actually see the graphql mcp tools. I tried various permutations of graphql, graphql*, graphql_*, etc.

zelifish avatar Oct 03 '25 19:10 zelifish

This issue might be a duplicate of existing issues. Please check:

  • #2888: Discussion about global default tools configuration for agents and tool inheritance behavior
  • #1101: Request for enabling/disabling MCP servers by mode, with detailed tool configuration syntax
  • #2277: Request to restrict MCP tool use to specific agents/subagents only
  • #514: Feature request for enabling/disabling MCP servers at runtime

Feel free to ignore if none of these address your specific case with disabled MCP servers not being accessible through agent tool configurations.

github-actions[bot] avatar Oct 03 '25 19:10 github-actions[bot]

@zelifish so here is what you need to do:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "graphql": {
      "type": "local",
      "enabled": true,
      "command": ["bunx", "mcp-graphql"],
      "environment": {
        "ENDPOINT": "http://localhost:13087/graphql"
      }
    }
  },
  "tools": {
    "graphql*": false
  }
}

enabled being false means the MCP server won't ever turn on at all so it isn't possible to give to llm

rekram1-node avatar Oct 03 '25 19:10 rekram1-node

Hmm, my motivation for this was to mitigate long startup times for tools that we only need when working on the front end portion of our repo. Is there a better way of doing that? My only other solution was to move my opencode configs down into the FE section but then I can't actually use them when working across the back and the front end having started opencode from a higher directory (or can I)?

I guess I could explicitly pass the config in the opencode command but no one's going to obey my complicated instructions if that's what I make them do.

zelifish avatar Oct 03 '25 19:10 zelifish

@zelifish rn there isn't a better way of doing it tbh, in opentui version there will probably be a mechanism to enable and disable mcp servers on the fly but rn it isn't super easy

rekram1-node avatar Oct 03 '25 19:10 rekram1-node

@rekram1-node do you have an estimate for opentui release?

@benceferdinandy-signifyd if you need it specifically for this issue, i can't really give a timeline on when this will be addressed as it is a lower priority rn

As for opentui version shipping in general id say next week probs

rekram1-node avatar Oct 16 '25 20:10 rekram1-node

Just generally opentui, thanks!

@rekram1-node the suggested approach doesn't seem to work for me. I have the GitHub MCP server set up and enabled, tools in the global configuration includes "github*": false and the subagent markdown includes tools: "github*": true, but the agent doesn't have access to the tools. If I comment out the global tools line everything works. What am I missing? 🤔

Edit:

Ah, it looks like configuring the agent tools in opencode.js works in the way described above. Is this a markdown limitation?

  "tools": {
    "github*": false,
    ...
  },
  "agent": {
    "github": {
      "tools": {
        "github*": true
      }
    }
  }

emilford avatar Nov 21 '25 23:11 emilford

@emilford this is what it'd look like in markdown:

---
description: ALWAYS use this when writing docs
tools:
  "github*": false
---

rekram1-node avatar Nov 24 '25 04:11 rekram1-node

@rekram1-node The issue is that the MCP server will appear in all sessions for all agents even though the agents are not allowed to use it...

I've opened another issue that focuses on this context issue. This is very annoying...

https://github.com/sst/opencode/issues/5373

lcswillems avatar Dec 11 '25 10:12 lcswillems