Skip to content

fix(cli): reload MCP config after project selection - #966

Open
luantaraschi wants to merge 2 commits into
CodebuffAI:mainfrom
luantaraschi:fix/reload-mcp-after-project-change
Open

fix(cli): reload MCP config after project selection#966
luantaraschi wants to merge 2 commits into
CodebuffAI:mainfrom
luantaraschi:fix/reload-mcp-after-project-change

Conversation

@luantaraschi

Copy link
Copy Markdown

Summary

  • Reload the local agent registry after the project picker changes the working directory, so the selected project's .agents/mcp.json is loaded before the client is recreated.
  • Preserve the existing --agent override behavior.
  • Add a regression test that verifies a project MCP server reaches the base agent definition after project selection.

Fixes #957

Testing

  • Project picker and local agent registry tests: 41 passed
  • CLI typecheck
  • SDK build
  • Freebuff Windows binary build
  • Freebuff version and help E2E tests: 5 passed

Copilot AI lite review requested due to automatic review settings August 10, 2026 17:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chrismindpower369

Copy link
Copy Markdown

This looks like the stronger fix for #957 because the regression test exercises the actual activateProject() flow and verifies that the selected project's MCP server reaches the base agent definition.

PR #973 appears to address the same root cause with overlapping changes. Before merging, could we confirm that this PR also clears every derived local-agent cache that depends on the previous cwd/project root? If yes, I would suggest merging #966 and closing #973 as a duplicate to avoid two competing fixes.

@luantaraschi

Copy link
Copy Markdown
Author

Thanks for catching this. The local agent registry has two derived caches that depend on the previous working directory: cachedAgentsByMode and cachedAgentsDir. The new reloadLocalAgentRegistry() helper clears both before initializeAgentRegistry() refreshes the agent definitions, file paths, and MCP configuration.

I also expanded the regression test to warm the caches in the launch project, switch projects through activateProject(), and verify that the selected project supplies the agent directory, local agent list, MCP server, and base agent definition. The old project's agent must no longer be present.

Validation on the new head (2f246ab):

  • 41 related tests passed
  • CLI typecheck passed
  • Freebuff Windows binary build passed
  • 5 --version and --help E2E tests passed
  • Prettier and git diff --check passed

This incorporates the cache-reset part of #973 while keeping the project-picker coverage in this PR.

@chrismindpower369

Copy link
Copy Markdown

Perfect, thanks for the thorough follow-up. Clearing both cwd-dependent caches and testing the full activateProject() transition addresses the concern. The added assertion that the old project's agent is absent is especially valuable.

This now seems like the right PR to merge for #957. I’d suggest closing #973 as a duplicate once a maintainer has reviewed this update.

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 servers from .agents/mcp.json are not loaded when the project is selected via the project picker (CLI started from an ancestor directory)

3 participants