GeezerVison is showing github.com — [FEATURE]: Lazy/dynamic loading for mcp tools · Issue #8277 · anomalyco/opencode
[FEATURE]: Lazy/dynamic loading for mcp tools #8277Labels discussionUsed for feature requests, proposals, ideas, etc. Open discussion DescriptionFeature hasn't been suggested before.
- 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
Agent calls: playwright_browser_navigate({ url: "https://google.com/" })
Agent calls: playwright_browser_snapshot()
Related
Reacted by 657, Marco Michely, platem, Surge, Utkarsh Patil, Derek Pearson, Levi Zitting, rqdmap, GammelSami, Lukas Zorich and 32 more Activitygithub-actions commented on 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 commented on 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 commented on Jan 16, 2026 Reacted by Derek Pearson, Dhruv Atreja, Stanislav U., Karim Bellioum and Prakhar Yadav platem commented on Jan 16, 2026 +1, that's a great idea, it would clear up the context window well allowing for higher quality outputs. famitzsy8 commented on Jan 18, 2026 Implementing a Claude Code style Tool Search Tool on this fork Reacted by Eric Guo Reacted by Eric Guo dennisrutjes-1 commented on 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 commented on Jan 19, 2026 Concretely discussing this issue (for MCP as well as built-in tools) in #9461 TheOutdoorProgrammer commented on 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 commented on Feb 20, 2026 github-actions commented on 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 commented on 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
| 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
Feel free to try it here: https://github.com/omarwaly-ai/opencode-lazy-loading Reacted by Eric Guo, Tien Bac Nguyen and Padure Sergio
MetadataMetadatadiscussionUsed for feature requests, proposals, ideas, etc. Open discussion DevelopmentNo branches or pull requestsIssue actions
|