fix(cli): reload .agents MCP servers after project picker selection - #973
Closed
bunnysayzz wants to merge 1 commit into
Closed
fix(cli): reload .agents MCP servers after project picker selection#973bunnysayzz wants to merge 1 commit into
bunnysayzz wants to merge 1 commit into
Conversation
The MCP servers from a project's .agents/mcp.json were only loaded once at CLI startup from the launch cwd. When the CLI is started from an ancestor directory and the project is selected via the project picker, the registry was never re-initialized, so the selected project's MCP servers stayed invisible to the main agent (issue CodebuffAI#957). handleProjectChange now calls reloadLocalAgentRegistry() after chdir + setProjectRoot, which clears the derived caches and re-runs initializeAgentRegistry() so user agents and MCP servers reflect the newly selected working directory. Co-Authored-By: Codebuff <noreply@codebuff.com>
|
Thanks for the clear root-cause analysis and cache-reload approach. PR #966 appears to solve the same #957 bug and tests the project-picker path through activateProject(), including propagation into the base agent definition. It may be best to consolidate the cache-reset details here into #966 and close one PR as a duplicate, rather than merge both. |
Author
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.
Summary
Fixes #957. MCP servers from a project's
.agents/mcp.jsonwere only loaded once at CLI startup from the launch cwd. When the CLI is started from an ancestor directory and the project is selected via the project picker, the registry was never re-initialized, so the selected project's MCP servers stayed invisible to the main agent.Root cause
initializeAgentRegistry()runs once at startup and callsloadMCPConfigSync(), which reads{cwd}/.agents/mcp.json.handleProjectChangeincli/src/index.tsxchanges the working directory and resets the codebuff client, but never re-runs the agent registry, somcpServersCachestays empty andloadAgentDefinitions()merges nothing into the base agents.Changes
cli/src/utils/local-agent-registry.ts: newreloadLocalAgentRegistry()that clears the derived caches (agent listings and the resolved.agentsdirectory) and re-runsinitializeAgentRegistry().cli/src/index.tsx:handleProjectChangenow awaitsreloadLocalAgentRegistry()right afterprocess.chdirandsetProjectRoot.Verification
cli/src/__tests__/integration/local-agents.test.tsreproduces the report exactly: registry initialized in a directory withoutmcp.json, then chdir + setProjectRoot into a project that has one, then reload. It fails on the original code (the export does not exist) and passes with the fix.tsc --noEmitoncli/: no errors in the changed files.