[PR #8771] feat: add mcp_lazy mode for on-demand MCP tool loading #12865

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

Original Pull Request: https://github.com/anomalyco/opencode/pull/8771

State: open
Merged: No


Closes https://github.com/anomalyco/opencode/issues/8625.

What does this PR do?

Adds a new experimental.mcp_lazy config option that prevents MCP tools from being loaded into context automatically. Instead, a new mcp_search tool is provided to discover and call MCP tools on-demand.

This reduces context usage for users with many MCP servers configured. When enabled:

  • MCP tools are excluded from the tool list sent to the model
    • Instead, available MCP servers are injected into the system prompt in a compact format.
  • The mcp_search tool allows listing, searching, describing, and calling MCP tools
  • MCP servers show "Lazy" status in the /mcp dialog

The injected prompt:

<mcp_servers>
Available MCP servers: context7, firecrawl, playwright
Use mcp_search tool to discover and call tools from these servers.
</mcp_servers>

How did you verify your code works?

  • Tested with experimental.mcp_lazy: true in config
  • Verified MCP tools are not in context and mcp_search appears instead
  • Tested all operations: list, search, describe, call
  • Confirmed servers connect on-demand when calling tools

The tests were manual, there are no actual tests included here.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/8771 **State:** open **Merged:** No --- Closes https://github.com/anomalyco/opencode/issues/8625. ### What does this PR do? Adds a new `experimental.mcp_lazy` config option that prevents MCP tools from being loaded into context automatically. Instead, a new `mcp_search` tool is provided to discover and call MCP tools on-demand. This reduces context usage for users with many MCP servers configured. When enabled: - MCP tools are excluded from the tool list sent to the model - Instead, available MCP servers are injected into the system prompt in a compact format. - The `mcp_search` tool allows listing, searching, describing, and calling MCP tools - MCP servers show "Lazy" status in the `/mcp` dialog The injected prompt: ```xml <mcp_servers> Available MCP servers: context7, firecrawl, playwright Use mcp_search tool to discover and call tools from these servers. </mcp_servers> ``` ### How did you verify your code works? - Tested with `experimental.mcp_lazy: true` in config - Verified MCP tools are not in context and `mcp_search` appears instead - Tested all operations: list, search, describe, call - Confirmed servers connect on-demand when calling tools The tests were manual, there are no actual tests included here.
yindo added the pull-request label 2026-02-16 18:17:45 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12865