-
Notifications
You must be signed in to change notification settings - Fork 745
Optimize MCP init by consolidating git lookups and eliminating recursive searches #13278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: mitchdenny <[email protected]>
|
@copilot src/Aspire.Cli/Agents/ClaudeCode/ClaudeCodeAgentEnvironmentScanner.cs:40 use the term "workspace root" since that is more generic. It won't always be a git repo. |
…ners Co-authored-by: mitchdenny <[email protected]>
Updated to use "workspace root" terminology throughout all scanners (VsCode, ClaudeCode, OpenCode) in log messages and comments. Commit 5f3220e. |
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 13278Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 13278" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR optimizes the aspire mcp init command by centralizing git repository detection and eliminating redundant operations. Previously, each environment scanner independently called IGitRepository.GetRootAsync() and performed recursive directory searches. The refactoring moves repository detection to a single upfront call in McpInitCommand, with the workspace root passed to scanners via context.
Key Changes
- Centralized git repository lookup in
McpInitCommandwith user confirmation prompt - Updated
DetectAsyncAPI to acceptrepositoryRootparameter viaAgentEnvironmentScanContext - Removed
IGitRepositorydependency from all scanners (VsCode, ClaudeCode, OpenCode)
Reviewed changes
Copilot reviewed 26 out of 27 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Aspire.Cli/Commands/McpInitCommand.cs | Added git repository lookup, user prompt for workspace root, and validation logic |
| src/Aspire.Cli/Commands/McpCommand.cs | Added IGitRepository dependency injection to McpCommand constructor |
| src/Aspire.Cli/Agents/IAgentEnvironmentDetector.cs | Added repositoryRoot parameter to DetectAsync interface |
| src/Aspire.Cli/Agents/AgentEnvironmentDetector.cs | Updated to pass repositoryRoot through context |
| src/Aspire.Cli/Agents/AgentEnvironmentScanContext.cs | Added RepositoryRoot property for scanners to use as search boundary |
| src/Aspire.Cli/Agents/VsCode/VsCodeAgentEnvironmentScanner.cs | Removed IGitRepository dependency, updated to use context.RepositoryRoot |
| src/Aspire.Cli/Agents/ClaudeCode/ClaudeCodeAgentEnvironmentScanner.cs | Removed IGitRepository dependency, updated to use context.RepositoryRoot |
| src/Aspire.Cli/Agents/OpenCode/OpenCodeAgentEnvironmentScanner.cs | Removed IGitRepository dependency, updated to use context.RepositoryRoot |
| src/Aspire.Cli/Resources/McpCommandStrings.resx | Added three new resource strings for workspace root prompts |
| src/Aspire.Cli/Resources/McpCommandStrings.Designer.cs | Auto-generated resource accessor properties for new strings |
| src/Aspire.Cli/Resources/xlf/*.xlf | Localization files updated with state="new" for untranslated strings |
| tests/Aspire.Cli.Tests/Utils/CliTestHelper.cs | Added GitRepositoryFactory for test dependency injection |
| tests/Aspire.Cli.Tests/Agents/VsCodeAgentEnvironmentScannerTests.cs | Removed FakeGitRepository, updated tests to pass RepositoryRoot via context |
| tests/Aspire.Cli.Tests/Agents/CopilotCliAgentEnvironmentScannerTests.cs | Updated test contexts to include RepositoryRoot property |
| tests/Aspire.Cli.Tests/Agents/AgentEnvironmentDetectorTests.cs | Updated DetectAsync calls with repositoryRoot parameter |
Files not reviewed (1)
- src/Aspire.Cli/Resources/McpCommandStrings.Designer.cs: Language not supported
src/Aspire.Cli/Agents/ClaudeCode/ClaudeCodeAgentEnvironmentScanner.cs
Outdated
Show resolved
Hide resolved
src/Aspire.Cli/Agents/ClaudeCode/ClaudeCodeAgentEnvironmentScanner.cs
Outdated
Show resolved
Hide resolved
tests/Aspire.Cli.Tests/Agents/VsCodeAgentEnvironmentScannerTests.cs
Outdated
Show resolved
Hide resolved
src/Aspire.Cli/Agents/ClaudeCode/ClaudeCodeAgentEnvironmentScanner.cs
Outdated
Show resolved
Hide resolved
src/Aspire.Cli/Agents/ClaudeCode/ClaudeCodeAgentEnvironmentScanner.cs
Outdated
Show resolved
Hide resolved
|
@copilot apply changes based on the comments in this thread |
…e consistent terminology Co-authored-by: mitchdenny <[email protected]>
All changes from that review thread have already been applied in commit 868a8ef. The code now includes all the requested improvements: simplified logic, fixed bug making else block reachable, consistent variable naming, and improved comments. |
|
@mitchdenny do we handle relative paths properly? If I run mcp init and I don't enter an absolute path it does not do the expected thing. |

Description
Optimizes
aspire mcp initto reduce redundant git operations and recursive directory traversal. Previously, each environment scanner (VsCode, ClaudeCode, OpenCode) independently calledIGitRepository.GetRootAsync()and performed recursive searches up the directory tree. This PR centralizes repository detection to a single upfront call and provides scanners with the workspace root via context.Changes
Core optimization:
McpInitCommandnow callsIGitRepository.GetRootAsync()once before invoking scannersDetectAsyncto acceptrepositoryRootparameter passed throughAgentEnvironmentScanContextScanner improvements:
IGitRepositorydependency from all scanners (VsCode, ClaudeCode, OpenCode)context.RepositoryRootas search boundary instead of recursively walking directory treeBug fixes and code quality improvements:
ClaudeCodeAgentEnvironmentScannerwhere the else block was unreachable due to always-true conditionMcpInitCommandfor consistency (defaultWorkspaceRoot,workspaceRootPath,workspaceRoot)Result: Git command invocations reduced from 3 to 1, recursive searches eliminated.
Checklist
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.