GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: mcp-search tool for lazy loading mcp by TheOutdoorProgrammer · Pull Request #12520 · anomalyco/opencode

Conversation

@TheOutdoorProgrammer

@TheOutdoorProgrammer TheOutdoorProgrammer commented Feb 6, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

edit: This was originally a rebase only, but I've since added some changes. Im still keeping this branch up to do date but its no longer solely a rebase.

original description

rebased #8771 onto the head of dev.

Closes #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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

superherointj, Ni55aN, and gerardthehuman reacted with thumbs up emoji jenslys, dpippenger, changchinlan, 5kahoisaac, forceuser, mdg-qc, ugurcancaykara, kil-penguin, feiwhang, bbartels, and 26 more reacted with rocket emoji mertkasar, anatoli-tsinovoy, JackCA, bscholar-tt, cenk1cenk2, TheOutdoorProgrammer, and lavreh reacted with eyes emoji
All reactions
  • 👍 3 reactions
  • 🚀 36 reactions
  • 👀 7 reactions
@github-actions

github-actions Bot commented Feb 6, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Related PR Found:

PR #8771 - "feat: add mcp_lazy mode for on-demand MCP tool loading"
#8771

Why it's related: This is the original PR that the current PR #12520 is based on. According to the PR description, PR #12520 is a rebase of PR #8771 onto the head of dev. Both PRs address the same feature: implementing lazy loading for MCP tools with the mcp_search tool to discover and call tools on-demand instead of loading them automatically.

Since PR #12520 is explicitly stated to be a rebase of PR #8771, you should verify whether #8771 is still open or if it should be closed in favor of #12520.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Feb 6, 2026
[FEATURE]: Claude-style Tool Search Tool Implementation in OpenCode #9461
Closed
[FEATURE]:Add mcp search tool, reduce mcp tool occupying a lot of context #8625
Closed
[Feature Request] MCP Tool Search - Lazy Loading for 85% Token Reduction #9350
Closed
[FEATURE]: Lazy/dynamic loading for mcp tools #8277
Closed
@TheOutdoorProgrammer
TheOutdoorProgrammer force-pushed the dev branch 2 times, most recently from 0aea13e to 8ab6573 Compare February 9, 2026 14:55
@rmk40

rmk40 commented Feb 13, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

This feature is absolutely needed — lazy MCP loading is one of the most requested capabilities and critical for users with many MCP servers. Thanks for rebasing and keeping this alive.

A few issues I noticed reviewing the diff:

MCP result handling is duplicated, not shared

This is the core issue. The MCP tool wrapping logic in prompt.ts (~80 lines) handles permissions, plugin hooks, content type parsing (text/image/resource), attachment creation, truncation, and metadata — then gets conditionally skipped when mcp_lazy is true. The call() function in mcp-search.ts reimplements a subset of this same logic, but incompletely. Extracting the MCP result processing into a shared function would fix the issues below and prevent them from diverging further as the codebase evolves.

MCP output fidelity loss in lazy call() path

A consequence of the duplication: the normal path preserves rich content — images become FilePart attachments, resource blobs are handled, and content is passed through for model output ordering. The lazy call() flattens everything to text ([Image: mime, N bytes]), dropping attachments entirely. MCP tools returning images or structured resources will produce degraded output when called through mcp_search.

Plugin hook payload inconsistency

Another consequence: the normal path passes args in the tool.execute.after trigger. The lazy call() path omits it. Plugins relying on args in after-hooks would break silently for lazy-loaded tools.

Search only matches server names

search filters on s.name.toLowerCase().includes(q) — searching for a tool name like "screenshot" returns nothing. Matching against tool names and descriptions would save round trips (list → scan → describe → call becomes search → call).

Generated file churn

The types.gen.ts and openapi.json changes are ~350 lines of reordering with no semantic changes. Regenerating cleanly against current dev would shrink the diff significantly.

Minor: the hasMcpSearch() check in prompt.ts is effectively dead code since mcp_lazy is already checked first and controls whether McpSearchTool is registered.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TheOutdoorProgrammer
TheOutdoorProgrammer force-pushed the dev branch from 8ab6573 to 79cc25b Compare February 13, 2026 14:10
@TheOutdoorProgrammer

TheOutdoorProgrammer commented Feb 13, 2026

Copy link
Copy Markdown
Author

Trying to keep the head of my fork synced so its easy to merge this. @thdxr @adamdotdevin @rekram1-node Is this something you guys would want to add? If its of use to you guys, Im happy to make sure its still updated properly. I just dont want to maintain updating it if its not. 😊

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@manorit2001

manorit2001 commented Feb 17, 2026

Copy link
Copy Markdown

@rekram1-node / @thdxr would be really nice to have this, would be nice to save some on context as well as the cost when adding many MCPs..

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TheOutdoorProgrammer
TheOutdoorProgrammer force-pushed the dev branch from 79cc25b to 1f0176d Compare February 17, 2026 14:16
@sangemaru

sangemaru commented Feb 17, 2026

Copy link
Copy Markdown

This is an absolutely critical feature, really looking forward to this being merged into main soon

heliar-k reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TheOutdoorProgrammer
TheOutdoorProgrammer force-pushed the dev branch 2 times, most recently from f8eed0a to 9fe3de1 Compare February 20, 2026 15:00
@ugurcancaykara

ugurcancaykara commented Feb 22, 2026

Copy link
Copy Markdown

+1

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@advi2715

advi2715 commented Feb 23, 2026

Copy link
Copy Markdown

Any updates on this? We really need a feature like this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TheOutdoorProgrammer
TheOutdoorProgrammer force-pushed the dev branch 3 times, most recently from a81c6a8 to 9f84574 Compare February 24, 2026 16:13
@TheOutdoorProgrammer

TheOutdoorProgrammer commented Feb 24, 2026

Copy link
Copy Markdown
Author

@rmk40 implemented your suggestions 👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dbpolito

dbpolito commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

i was about to write a plugin for this, then i found this PR... would love to see this on core...

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@manorit2001

manorit2001 commented Feb 28, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

@TheOutdoorProgrammer i can see some tests failing btw, any idea on them?

@thdxr @adamdotdevin @rekram1-node is there anything that you are looking for in the support, i don't think it's right to keep people hanging either if there are no intentions to merge this PR at all.

( If it's due to sheer traffic or PRs on this repo that's understadable but it is becoming a bit hard to track what you guys are looking for and what you are not, would be good to have some visbility on them )

yadav-prakhar reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TheOutdoorProgrammer

TheOutdoorProgrammer commented Mar 2, 2026

Copy link
Copy Markdown
Author

@manorit2001 Im not sure. Im happy to dive into the problems but I'd like to wait until I hear from the maintaining team if they want this feature or not (no is perfectly acceptable). Its becoming a bit of a chore maintaining this so it can merge cleanly.

If the maintainers can just give me a thumbs up or a thumbs down I will continue to maintain this PR or not based on their feedback.

yadav-prakhar reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@manorit2001

manorit2001 commented Mar 2, 2026

Copy link
Copy Markdown

ping @nexxeln ?

Also @TheOutdoorProgrammer , can you maybe look into possibility of having a plugin for this instead if possible, would be very handy to integrate if it it's not going in the main repo

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TheOutdoorProgrammer

TheOutdoorProgrammer commented Mar 2, 2026

Copy link
Copy Markdown
Author

@manorit2001 I've actually seen a few plugins in some of the related issues.

  • [FEATURE]: Claude-style Tool Search Tool Implementation in OpenCode #9461
  • [Feature Request] MCP Tool Search - Lazy Loading for 85% Token Reduction #9350
  • [FEATURE]: Lazy/dynamic loading for mcp tools #8277
  • [FEATURE]: Filter which tools are loaded from MCP servers (includeTools/excludeTools) #7399
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nexxeln

nexxeln commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

discussing internally

DexterHuang, Serdnad, feiwhang, strawberrymelonpanda, changchinlan, maxious, gee842, yadav-prakhar, numbr3la, anatoli-tsinovoy, and maxim-kuderko reacted with thumbs up emoji
All reactions
  • 👍 11 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Mar 3, 2026
📊 AI CLI 工具社区动态日报 2026-03-03 duanyytop/agents-radar#65
Closed
@itshahmir

itshahmir commented Mar 4, 2026

Copy link
Copy Markdown

+1

Serdnad reacted with thumbs down emoji
All reactions
  • 👎 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

1 similar comment
@itshahmir

itshahmir commented Mar 4, 2026

Copy link
Copy Markdown

+1

DexterHuang, Void-n-Null, austinh, gee842, and rodrigoGA reacted with thumbs up emoji Serdnad reacted with thumbs down emoji
All reactions
  • 👍 5 reactions
  • 👎 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Jun 3, 2026
📊 AI CLI 工具社区动态日报 2026-06-03 zx0828/big_model_radar#83
Open
@simonklee
simonklee requested a review from rekram1-node June 3, 2026 04:04
@github-actions github-actions Bot mentioned this pull request Jun 3, 2026
feat(permission): wire permission.ask plugin hook #30509
Closed
3 of 6 tasks
@auggie246

auggie246 commented Jun 9, 2026

Copy link
Copy Markdown

What's the hold up?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Jun 13, 2026
feat: nested sub-agent spawning (up to 5 levels) + multi-agent workflow orchestration #32167
Closed
3 tasks done
randomvariable added a commit to randomvariable/opencode that referenced this pull request Jun 14, 2026
@randomvariable @claude
fix(integrate): resolve config schema mismatches from v1.17.6 integra…
8f29fb1
…tion

PR anomalyco#12520 (mcp-search) was written against a dev state where config modules
had already been migrated from Zod to Effect Schema and split into sub-modules.
Cherry-picking onto v1.17.6 brought config.ts with all those imports but not
the migrated sub-modules themselves.

Fixes:
- Extract Effect Schema versions of all config sub-modules (agent, attachment,
  command, console-state, formatter, layout, lsp, mcp, model-id, permission,
  provider, reference, server, skills) from their respective migration commits
- Add AppFileSystem namespace to core/filesystem.ts (alias for FSUtil, which
  config.ts imported post-refactor)
- Restore ConfigPermissionV1 namespace name in core/v1/config/permission.ts
  (renamed from ConfigPermission in a post-v1.17.6 commit)
- Add Info export to config/command.ts re-exporting ConfigCommandV1.Info
- Add effect-zod.ts to core/src (moved from opencode/src/util in dcdbdb2)
- Restore util/log.ts to core (deleted in c06ad7c; still imported by config)
- Fix tools.ts: replace deleted ModelID from @/provider/schema with ModelV2.ID

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@rodboev rodboev mentioned this pull request Jun 17, 2026
OpenCode eagerly exposes connected MCP tools at turn construction time, unlike Codex's deferred MCP model #32621
Closed
@seglo

seglo commented Jun 22, 2026

Copy link
Copy Markdown

This is all I want for Christmas, Santa.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cpt-sd76vg

cpt-sd76vg commented Jun 22, 2026

Copy link
Copy Markdown

I’m also really hoping to see this PR merged.

To the maintainers: I would appreciate it if you could at least review this PR or join the discussion.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@countzero

countzero commented Jun 24, 2026

Copy link
Copy Markdown

@TheOutdoorProgrammer currently this branch has merge conflicts.

@rekram1-node & @thdxr is this feature on the roadmap? What is missing if @TheOutdoorProgrammer fixes the merge conflicts?

I think there is a big community interest in this feature and I personally favor automatic solutions that will reduce the amount of energy spent on tokens 😉

cenk1cenk2 reacted with thumbs up emoji cenk1cenk2 and Michaelts-ma reacted with rocket emoji
All reactions
  • 👍 1 reaction
  • 🚀 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TheOutdoorProgrammer

TheOutdoorProgrammer commented Jun 29, 2026

Copy link
Copy Markdown
Author

I know theres conflicts, this repo changes very often and keeping up with the conflicts turned into a chore. Im willing to rebase when the maintainers tell me this is something they want or not. Otherwise Im rebasing every few hours.

stephanschielke, anton-omelianenko, rodrigoGA, changchinlan, Michaelts-ma, countzero, and abelfodil reacted with thumbs up emoji cpt-sd76vg reacted with eyes emoji
All reactions
  • 👍 7 reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@blak0p blak0p mentioned this pull request Jul 20, 2026
[Feature] Lazy-load MCP tool definitions to reduce token overhead #35376
Closed
@github-actions github-actions Bot mentioned this pull request Jul 30, 2026
fix(core): retry lazy initializer after it throws #39597
Closed
3 of 6 tasks
randomvariable added a commit to randomvariable/opencode that referenced this pull request Aug 3, 2026
@randomvariable @claude
feat: mcp-search tool for lazy loading mcp
3a619cc
Add an experimental `mcp_lazy` config flag. When enabled, MCP tools are no
longer loaded into the model context automatically; instead a new mcp_search
tool (list/search/describe/call) discovers and invokes MCP tools on demand,
and the prompt loop advertises connected MCP servers in the system prompt.
mcp_search is only registered when the flag is set and MCP is available.

Ported from anomalyco#12520 (adapted for the Effect layer: the server advert is built
inline in the prompt loop rather than via a SystemPrompt service method, and
Config is provided at the SessionTools.resolve call site). The TUI "Lazy"
status badge from the original PR is omitted (its dialog moved packages and
the badge is cosmetic). SDK regeneration also includes the session-create
`id` field from anomalyco#32122.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
randomvariable added a commit to randomvariable/opencode that referenced this pull request Aug 3, 2026
@randomvariable @claude
feat(opencode): interrupt a running subagent — steer / cancel / abort
cd4f0a2
Add an experimental subagent-interrupt capability (behind
OPENCODE_EXPERIMENTAL_SUBAGENT_INTERRUPT): an Interrupt service with
pending/terminal state, task_steer/task_cancel/task_abort tools (gated by a
new `interrupt` permission), a POST /session/:id/interrupt endpoint, and a
turn-boundary consume in the prompt loop that injects an escaped steer/cancel
frame plus a visible transcript marker. Cancel records a terminal reason and
force-breaks after a grace window; abort writes a marker, records the
terminal, and cancels the BackgroundJob immediately. The TUI gains an
esc-with-reason flow, footer button, and distinct interrupt markers.

Ported from anomalyco#32425 (adapted for the Effect layer; merged with the prior
task.ts/registry.ts/prompt.ts changes from anomalyco#29447/anomalyco#32122/anomalyco#12520/anomalyco#32192/anomalyco#19961).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@countzero

countzero commented Aug 18, 2026

Copy link
Copy Markdown

@TheOutdoorProgrammer Hi, I have been watching this PR, but it seems stale. So I checked around the code base of OpenCode if there is another feature that could reduce the amount of active tokens in combination with multiple MCPs.

I found that activating OPENCODE_EXPERIMENTAL_CODE_MODE works great for me.

See https://github.com/anomalyco/opencode/tree/dev/packages/codemode for the documentation of that feature.

Dmitrii-Software-Testing reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rekram1-node

rekram1-node commented Aug 18, 2026

Copy link
Copy Markdown
Member

Yes recommend using OPENCODE_EXPERIMENTAL_CODE_MODE, in opencode v2 codemode is enabled by default

countzero and Dmitrii-Software-Testing reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rekram1-node rekram1-node closed this Aug 18, 2026
Bewinxed added a commit to Bewinxed/cawco that referenced this pull request Oct 8, 2026
@Bewinxed @claude
OpenCode: MCP tools behind code mode, a self-looping session is stopp…
f945e78
…ed, stored synthetic text is no one's row

- CawCo's opencode serve runs with OPENCODE_EXPERIMENTAL_CODE_MODE=true
  (upstream's answer to MCP schemas filling the request, anomalyco/opencode#12520).
  With the fleet's MCP servers connected (ElevenLabs: 160 tools, 1.13 MB of
  schemas) a turn's request went from 1,425,289 bytes / 416 tools to
  55,154 bytes / 15 tools; every model under ~400k input tokens had refused
  every turn since ElevenLabs joined the fleet (gpt-5.5 0/17 on obelisk).
- A generation records the launch flags it was started with; one started
  without them fails verification and convergence replaces it.
- A code-mode program's calls become the rows a direct call draws, live and
  read back: OpenCode keeps their names, inputs and statuses; the bridge
  plugin writes what each answered onto the program's part (in its after
  hook, or onto the settled part when the program threw).
- The supervisor stops a session that fails the same way 3 times in a row
  with no send in between, says so as a failure card, and OpenCode keeps the
  stop in the session so a reload draws it too.
- toTranscript no longer draws opencode's synthetic user text (a
  compaction's continue note) as the reader's words.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RicSchonfelder RicSchonfelder mentioned this pull request Oct 24, 2026
[FEATURE]: Code Mode needs a token budget and a per-tool breakdown #58708
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@rekram1-node rekram1-node Awaiting requested review from rekram1-node

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[FEATURE]:Add mcp search tool, reduce mcp tool occupying a lot of context

Uh oh!

There was an error while loading. Please reload this page.

20 participants

@TheOutdoorProgrammer @rmk40 @manorit2001 @sangemaru @ugurcancaykara @advi2715 @dbpolito @nexxeln @itshahmir @mertkasar @Void-n-Null @mihalcind @strawberrymelonpanda @richardlnnr @rickross @DrDexter6000 @giampaolocasolla @laradji @Dmitrii-Software-Testing @sandr1x
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.