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 — fix(mcp): settle the tool registry when the server set changes by argszero · Pull Request #52214 · anomalyco/opencode

Conversation

@argszero

@argszero argszero commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #51089

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

mcp.add answered 204 as soon as Mcp.Service.add resolved. That call awaits the connection, so GET /api/mcp already reports connected, but the registry a step reads is separate state: it only reloads when the ToolsChanged event reaches McpTool and the 100 ms debounce in front of reconcile fires. The only settle point, McpTool.flush, waits for the initial discovery, so session/context.ts could build the first step after mcp.add from the pre-add catalog. mcp.remove has the mirror problem: the removed server's tools linger until the debounce fires.

This keeps the debounce for background announcements and adds an explicit settle point for the routes that change the server set:

  • McpTool exposes refresh, which re-reads Mcp.tools() and reloads the registry under the same semaphore the debounced path uses, so a refresh cannot interleave with a queued one.
  • mcp.add / mcp.remove / mcp.connect / mcp.disconnect await it after the mutation, so answering 204 means the registry already reflects the change.

flush is unchanged: it stays the cheap "wait for the initial registration" that SessionContext.select awaits on every step.

Targeted at v2 because packages/core/src/tool/mcp.ts and packages/server/src/handlers/mcp.ts do not exist on dev. #51812 is the same family from a different trigger (first prompt after boot, no mcp.add involved) and is out of scope here.

How did you verify your code works?

  • New test refreshes the registry for a change that is still debounced in packages/core/test/mcp.test.ts: registers the mock server catalog, changes it, publishes ToolsChanged, then awaits refresh and asserts the registry already serves the new tool without any clock advance, so the debounced reload cannot be what makes it pass. It fails on the unmodified tree.
  • bun test test/mcp.test.ts in packages/core: 72 pass, 3 fail. Those 3 (terminates MCP descendants after the wrapper exits successfully, MCP connection over the modern protocol, discovers and reads MCP resources through Code Mode) fail identically on the unmodified tree on this machine.
  • tsgo -b tsconfig.json tsconfig.tests.json in packages/core, tsgo -b in packages/server, and oxlint on the three files: clean. The typecheck is what covers the route wiring, since the handlers now require McpTool.Service, which the location graph already provides next to Mcp.Service.
  • No live PUT check: every route in packages/server/test answers 500 on this machine on the unmodified tree too (generate.test.ts, fs.test.ts), so the ordering is covered by the test above plus the typecheck.

Screenshots / recordings

No UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sorry, something went wrong.

Uh oh!

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

nkoynov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@argszero
fix(mcp): settle the tool registry when the server set changes
cad41b0
mcp.add, mcp.remove, mcp.connect and mcp.disconnect answered as soon as the
server set changed, while the session tool registry only reloads on a debounced
ToolsChanged event. A prompt sent right after the response could run its first
step without the tools of a server the client had just added.

McpTool now exposes refresh, which re-reads the connected servers and reloads
the registry, and the routes that change the server set await it before
answering. Background announcements still coalesce through the debounce.
@github-actions github-actions Bot added the needs:issue label Sep 30, 2026
@github-actions

github-actions Bot commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

All reactions

Sorry, something went wrong.

Uh oh!

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

@argszero argszero mentioned this pull request Sep 30, 2026
mcp.add resolves befor the session tool registry has the new server's tools #51089
Open
@github-actions

github-actions Bot commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

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

This was referenced Oct 5, 2026
[Bug]: OpenCode 2: a thread's first turn doesn't see T3 Code's MCP tools (prompt is sent before OpenCode registers them) pingdotgg/t3code#16141
Closed
First prompt after start has no MCP tools: tool list does not wait for pending MCP connections #51812
Closed
@thdxr
thdxr changed the base branch from v2 to dev October 10, 2026 19:24
@github-actions github-actions Bot removed the needs:issue label Oct 10, 2026
@opencode-agent opencode-agent Bot mentioned this pull request Oct 12, 2026
fix(core): refresh MCP tools before session snapshots #54942
Closed
3 of 6 tasks
@argszero

argszero commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Closing this to stay within GitHub's 3-open-pull-request limit for contributors without write access, which currently blocks every new pull request here. The branch remains on my fork, so I can reopen it on request.

All reactions

Sorry, something went wrong.

Uh oh!

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

@argszero argszero closed this Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

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.

mcp.add resolves befor the session tool registry has the new server's tools

Uh oh!

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

1 participant

@argszero
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.