fix: create mcp_registry on first /mcp add in a running session - #911
Open
mabaeyens wants to merge 1 commit into
Open
fix: create mcp_registry on first /mcp add in a running session#911mabaeyens wants to merge 1 commit into
mabaeyens wants to merge 1 commit into
Conversation
refresh_config() only synced the active servers into mcp_registry when the registry already existed. In the interactive TUI, AgentLoop is constructed with defer_heavy_init=True, so mcp_registry stays None until _ensure_remote_registries() runs once at startup and only creates it if config.mcp_servers is already non-empty at that point. Adding the very first MCP server in a running session via `/mcp add` persists the server and calls refresh_config(), but mcp_registry remained None forever afterward, so the immediate `/mcp login` (and any later `/mcp status`/`/mcp login`) failed with "No MCP servers configured." even though the server was correctly written to config.toml. refresh_config() now calls _ensure_remote_registries() before syncing, matching the same lazy-creation call already used at startup and elsewhere, so the registry is created as soon as the config actually has servers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #910
Summary
/mcp adding the first MCP server in a running session (i.e. one that started with zero[[mcp_servers]]entries) persisted the server toconfig.tomlcorrectly, but the automatic OAuth login that follows failed withError: No MCP servers configured.—/mcp login//mcp statusfailed the same way afterward, in that same session.AgentLoopwithdefer_heavy_init=True, somcp_registrystaysNoneuntil_ensure_remote_registries()runs once at startup, and that method only creates the registry if servers already existed in the config at that time.refresh_config()(called by/mcp addright after persisting) only synced intomcp_registryif self.mcp_registry is not None— it never called_ensure_remote_registries()to lazily create the registry once the config gained its first server.refresh_config()now callsself._ensure_remote_registries()before the sync check, matching the same lazy-creation call already used at startup (_complete_init) and elsewhere (vibe/core/agent_loop/_loop.py:2401)._ensure_remote_registries()is idempotent (guarded byis Nonechecks), so this is a no-op once the registry already exists.Change
vibe/core/agent_loop/_loop.py: one-line addition torefresh_config().tests/core/config/test_agent_loop_refresh_config.py: new regression testtest_refresh_config_creates_mcp_registry_for_first_server, constructing anAgentLoopthe same way the TUI does (defer_heavy_init=True, zero initial servers) and assertingmcp_registryis created and populated afterrefresh_config()adds the first server.Test plan
uv run pytest tests/core/config/test_agent_loop_refresh_config.py— all 5 tests pass (including the new regression test), verified with--import-mode=prepend(this machine's--import-mode=importlibdefault fails to resolve the editable install for unrelated reasons — confirmed identical failure on unmodifiedmain, not introduced by this change).uv run pytest --ignore tests/snapshots) diffed branch vs.main: byte-identical set of 52 pre-existing failures on both (all environment-specific: missingripgreplocally, subprocess env resolution, etc.) — zero new failures from this change.uv run pre-commit run --files vibe/core/agent_loop/_loop.py tests/core/config/test_agent_loop_refresh_config.py— pyright, ruff check, ruff format, typos all pass.