Skip to content

fix: create mcp_registry on first /mcp add in a running session - #911

Open
mabaeyens wants to merge 1 commit into
mistralai:mainfrom
mabaeyens:fix/mcp-add-first-server-registry-none
Open

fix: create mcp_registry on first /mcp add in a running session#911
mabaeyens wants to merge 1 commit into
mistralai:mainfrom
mabaeyens:fix/mcp-add-first-server-registry-none

Conversation

@mabaeyens

Copy link
Copy Markdown

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 to config.toml correctly, but the automatic OAuth login that follows failed with Error: No MCP servers configured./mcp login//mcp status failed the same way afterward, in that same session.
  • Root cause: the interactive TUI builds AgentLoop with defer_heavy_init=True, so mcp_registry stays None until _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 add right after persisting) only synced into mcp_registry if self.mcp_registry is not None — it never called _ensure_remote_registries() to lazily create the registry once the config gained its first server.
  • Fix: refresh_config() now calls self._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 by is None checks), so this is a no-op once the registry already exists.

Change

  • vibe/core/agent_loop/_loop.py: one-line addition to refresh_config().
  • tests/core/config/test_agent_loop_refresh_config.py: new regression test test_refresh_config_creates_mcp_registry_for_first_server, constructing an AgentLoop the same way the TUI does (defer_heavy_init=True, zero initial servers) and asserting mcp_registry is created and populated after refresh_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=importlib default fails to resolve the editable install for unrelated reasons — confirmed identical failure on unmodified main, not introduced by this change).
  • Full suite (uv run pytest --ignore tests/snapshots) diffed branch vs. main: byte-identical set of 52 pre-existing failures on both (all environment-specific: missing ripgrep locally, 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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: /mcp add on the first-ever MCP server fails to log in with "No MCP servers configured."

1 participant