You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEATURE]: Lazy/dynamic loading for mcp tools #8277
I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request
Problem
When multiple MCP servers are enabled, all tool definitions load into the agent's context at session startup. A single MCP server like GitHub can add 15-20k+ tokens just for tool schemas. With several MCPs enabled, context bloat can exceed 50k tokens before the user even sends a message. This is even mentioned in the docs: https://opencode.ai/docs/mcp-servers/
Solution
Lazy loading pattern: Instead of loading full tool schemas at startup, we:
Show a lightweight index in the system prompt with server names and tool names only (~150 tokens vs ~1.5k)
Provide a mcp_load_tools meta-tool that loads specific tools on-demand
The agent loop naturally picks up newly loaded tools on the next iteration
Example Flow
System prompt shows:
"playwright (20 tools): browser_snapshot, browser_click, browser_navigate, ..."
User: "Take a screenshot of google.com"
Agent calls: mcp_load_tools("playwright", ["browser_navigate", "browser_snapshot"])
→ Tools loaded into session state
you can just vibe code a mcp-tool that does the searching, I coded deno with typescript mcp-tool with it's own mcp server config and let agent just search for that in tool skill definition works like a charm. It is also able to generate tools and register them in folder for local/repo re use
Hey — thanks for filing this! There are several open issues requesting essentially the same thing (tool search / deferred tool loading / lazy MCP loading). To consolidate discussion and improve visibility, it'd be great if this could be closed in favor of #8625 which has the most thumbs up on the topic. Consolidating makes it easier for maintainers to see community demand in one place.
Thanks for suggesting the feature, actually i faced the same issue not only with MCPs, but also with built-in tools too that inject 6k -7k tokens in each request.
I create a single file plugin OpenCode Lazy Loading that loads tools and MCPs on demand once per request with ZERO tokens for MCPs and ~323 tokens built-in tools
Setup
Before
After
Saved
12 built-in tools
~6,900 tokens
~323 tokens
~95%
Chrom Devtool MCP
~17,900 tokens
ZERO tokens
~100%
12 built-in + Chrom Devtool MCP
~24,800 tokens
~323 tokens
~98.7%
Reducing opencode's total tokens for default opencode setup from ~10k to ~3.7K
Activity
github-actions commentedon Jan 13, 2026
This issue might be a duplicate of existing issues. Please check:
Both of these issues address similar concerns about lazy/dynamic loading of MCP tools to reduce token consumption and context bloat.
Feel free to ignore if your specific case differs from these proposals.
KenjiPcx commentedon Jan 16, 2026
I think you could also just tie in MCP loaders into skills as they are loaded since skills are already lazy loaded
leandro-ferreira-creditas commentedon Jan 16, 2026
Anthropic did this with Claude Code. A very clever solution that mixes MCP search, dynamic tool update on the fly, and MCP Automatic Trigger.
platem commentedon Jan 16, 2026
+1, that's a great idea, it would clear up the context window well allowing for higher quality outputs.
famitzsy8 commentedon Jan 18, 2026
Implementing a Claude Code style Tool Search Tool on this fork
dennisrutjes-1 commentedon Jan 19, 2026
you can just vibe code a mcp-tool that does the searching, I coded deno with typescript mcp-tool with it's own mcp server config and let agent just search for that in tool skill definition works like a charm. It is also able to generate tools and register them in folder for local/repo re use
famitzsy8 commentedon Jan 19, 2026
Concretely discussing this issue (for MCP as well as built-in tools) in #9461
TheOutdoorProgrammer commentedon Feb 6, 2026
Hey — thanks for filing this! There are several open issues requesting essentially the same thing (tool search / deferred tool loading / lazy MCP loading). To consolidate discussion and improve visibility, it'd be great if this could be closed in favor of #8625 which has the most thumbs up on the topic. Consolidating makes it easier for maintainers to see community demand in one place.
Related issues tracking the same feature:
Semi related issues that would compliment this (for visibility):
I've rebased #8771 here. I've been running it for a few days its working amazing. Looking forward to this being part of OpenCode.
Arrmlet commentedon Feb 20, 2026
Hello I've coded this tool. Lazy MCP tool loading, works with any provider: https://github.com/Arrmlet/dehydrator
feat: lazy MCP loading with session-scoped activation
github-actions commentedon Apr 22, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.
omarwaly-ai commentedon Jun 25, 2026
Thanks for suggesting the feature, actually i faced the same issue not only with MCPs, but also with built-in tools too that inject 6k -7k tokens in each request.
I create a single file plugin OpenCode Lazy Loading that loads tools and MCPs on demand once per request with ZERO tokens for MCPs and ~323 tokens built-in tools
Reducing opencode's total tokens for default opencode setup from ~10k to ~3.7K
Feel free to try it here: https://github.com/omarwaly-ai/opencode-lazy-loading