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

Open
opened 2026-02-16 17:52:32 -05:00 by yindo · 0 comments
Owner

Originally created by @DhruvAtreja on GitHub (Jan 13, 2026).

Originally assigned to: @thdxr on GitHub.

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

Originally created by @DhruvAtreja on GitHub (Jan 13, 2026). Originally assigned to: @thdxr on GitHub. ### Feature hasn't been suggested before. - [x] 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 - Addresses: #514, #1101, #2888, #2953, #3612, #5373, #6024
yindo added the discussion label 2026-02-16 17:52:32 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#5425