Skip to content

[FEATURE]: Lazy/dynamic loading for mcp tools #8277

Closed

Description

@DhruvAtreja

Feature 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

Activity

  1. added
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    on Jan 13, 2026
  2. github-actions commented on Jan 13, 2026

    @github-actions
    Contributor

    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.

  3. KenjiPcx commented on Jan 16, 2026

    @KenjiPcx

    I think you could also just tie in MCP loaders into skills as they are loaded since skills are already lazy loaded

  4. leandro-ferreira-creditas commented on Jan 16, 2026

    @leandro-ferreira-creditas

    Anthropic did this with Claude Code. A very clever solution that mixes MCP search, dynamic tool update on the fly, and MCP Automatic Trigger.

  5. platem commented on Jan 16, 2026

    @platem

    +1, that's a great idea, it would clear up the context window well allowing for higher quality outputs.

  6. famitzsy8 commented on Jan 18, 2026

    @famitzsy8

    Implementing a Claude Code style Tool Search Tool on this fork

  7. dennisrutjes-1 commented on Jan 19, 2026

    @dennisrutjes-1

    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

    Image
  8. famitzsy8 commented on Jan 19, 2026

    @famitzsy8

    Concretely discussing this issue (for MCP as well as built-in tools) in #9461

  9. TheOutdoorProgrammer commented on Feb 6, 2026

    @TheOutdoorProgrammer

    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.

  10. Arrmlet commented on Feb 20, 2026

    @Arrmlet

    Hello I've coded this tool. Lazy MCP tool loading, works with any provider: https://github.com/Arrmlet/dehydrator

  11. github-actions commented on Apr 22, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

  12. omarwaly-ai commented on Jun 25, 2026

    @omarwaly-ai

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

discussionUsed for feature requests, proposals, ideas, etc. Open discussion

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions