feat: add mcp_lazy mode for on-demand MCP tool loading#8771
feat: add mcp_lazy mode for on-demand MCP tool loading#8771xHeaven wants to merge 7 commits intoanomalyco:devfrom
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
|
#8177 also proposes something similar |
Damn, I completely missed that one. Our solutions differ a bit, I guess it comes down to preference. Also, honestly, I'm not sure I'd call either solution "complete", more like an idea of how this feature could be implemented. |
|
There was also this one in November that was closed, #4717 Slightly different and with the idea of loading tools for certain turns and then unloading them |
|
yeah #4717 was a simpler implementation that just worked, maybe not the most feature full approach but did the trick fine. I closed it because it wasn't getting any attention and i wanted to help declutter opencode's growing PR number :D |
That's probably what's going to happen to this PR, too. This is a great feature - probably not the best implementation -, but it's not getting the attention I would expect for something like this. I'm hoping the core contributors will pick up on it and make a better implementation. |
|
There's another proposed implementation here https://github.com/famitzsy8/opencode-tool-search-tool By @famitzsy8 If we are going to keep pushing this idea forward we might need to consolidate all the duplicate issues and PRs. |
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
|
Can you explain how this works with permissions, please? |
|
Looking forward to this PR being merged. |
If you're interested in it, as I am, probably best to just merge it locally. I don't know how OpenCode chooses which PRs to merge, but given the radio silence, I'd say odds aren't great. |
Tier 1 bug fixes: - Fix O(n²) bash output concatenation with StreamingOutput class (anomalyco#9693) - Fix memory leaks in Bus.once, Format, Plugin, ShareNext, Bootstrap (anomalyco#13514) - Fix FileTime race condition using actual file mtime instead of JS clock - Free memory on compaction prune: clear output/attachments/metadata (anomalyco#7049) - Throttle reasoning-delta storage writes to 50ms intervals (anomalyco#11328) - Handle SIGHUP/SIGTERM to prevent orphaned processes (anomalyco#12718) - Add process.once("close") handler for bash tool reliability Tier 2 features: - Support 1M context window for Anthropic models via beta header (anomalyco#14375) - Input-only token counting for compaction with limit.input models - MCP lazy loading: on-demand tool discovery via mcp_search tool (anomalyco#8771) - MCP servers listed in system prompt when lazy mode enabled - StreamingOutput: output_filter regex for build diagnostics - LSP server cleanup callback for temp directory removal - Extract formatSize utility from uninstall to shared util/format - GitHub CI: fix Bus subscription leak in session event handler Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Closes #8625.
What does this PR do?
Adds a new
experimental.mcp_lazyconfig option that prevents MCP tools from being loaded into context automatically. Instead, a newmcp_searchtool is provided to discover and call MCP tools on-demand.This reduces context usage for users with many MCP servers configured. When enabled:
mcp_searchtool allows listing, searching, describing, and calling MCP tools/mcpdialogThe injected prompt:
How did you verify your code works?
experimental.mcp_lazy: truein configmcp_searchappears insteadThe tests were manual, there are no actual tests included here.