Skip to content

Fix GitHub Copilot CLI detection and add separate CopilotCliAgentEnvironmentScanner#13250

Merged
mitchdenny merged 4 commits intomainfrom
copilot/fix-github-copilot-cli-detection
Nov 30, 2025
Merged

Fix GitHub Copilot CLI detection and add separate CopilotCliAgentEnvironmentScanner#13250
mitchdenny merged 4 commits intomainfrom
copilot/fix-github-copilot-cli-detection

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 30, 2025

Description

This PR fixes GitHub Copilot CLI detection and introduces a separate CopilotCliAgentEnvironmentScanner to handle Copilot CLI configuration independently from VS Code.

Changes Made

  1. Fixed Copilot CLI command detection: Changed from github-copilot-cli to copilot when detecting the GitHub Copilot CLI installation.

  2. Created new CopilotCliAgentEnvironmentScanner: Since Copilot CLI uses a global configuration file (not per-workspace like VS Code), a separate scanner was created that:

    • Detects the presence of the copilot CLI
    • Writes configuration to $HOME/.copilot/mcp-config.json
    • Uses the mcpServers format with DOTNET_ROOT environment variable passthrough
  3. Moved Copilot CLI runner to new namespace: Relocated CopilotCliRunner and ICopilotCliRunner from Agents/VsCode to Agents/CopilotCli for better organization.

  4. Updated VsCodeAgentEnvironmentScanner: Removed Copilot CLI detection since it's now handled by the dedicated scanner.

Configuration Format

The new scanner writes configuration in the following format:

{
  "mcpServers": {
    "aspire": {
      "type": "local",
      "command": "aspire",
      "args": ["mcp", "start"],
      "env": {
        "DOTNET_ROOT": "${DOTNET_ROOT}"
      },
      "tools": ["*"]
    }
  }
}

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?
Original prompt

Fix the logic in https://github.com/dotnet/aspire/blob/main/src/Aspire.Cli/Agents/VsCode/CopilotCliRunner.cs to detect the github copilot CLI. It's looking for github-copilot-cli instead of copilot


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…'github-copilot-cli'

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Nov 30, 2025

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 13250

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 13250"

1 similar comment
@github-actions
Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 13250

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 13250"

Copilot AI changed the title [WIP] Fix logic to detect GitHub Copilot CLI correctly Fix GitHub Copilot CLI detection to use 'copilot' command Nov 30, 2025
Copilot AI requested a review from davidfowl November 30, 2025 07:20
@mitchdenny
Copy link
Copy Markdown
Member

@copilot there is an issue with the vscode scanner. At the moment it detects copilot but we've found that the copilot config is actually global only so we need to introduce a new CopolotCliAgentEnvironmentScanner which detects the presence of copilot and updates the copilot global configuration file.

For copilot CLI the configuration file is located at:

$HOME/.copilot/mcp-config.json

It should look like this:

{
  "mcpServers": {
    "aspire": {
      "command": "aspire",
      "args": ["mcp", "start"],
      "env": {
        "DOTNET_ROOT": "${DOTNET_ROOT}"
      }
    }
  }
}

The environment variable passthru is important.

…ation

- Created new Agents/CopilotCli folder with:
  - CopilotCliAgentEnvironmentScanner.cs - scans for Copilot CLI and writes to $HOME/.copilot/mcp-config.json
  - CopilotCliRunner.cs - runs Copilot CLI commands (moved from VsCode folder)
  - ICopilotCliRunner.cs - interface (moved from VsCode folder)
- Added resource files for scanner strings
- Updated VsCodeAgentEnvironmentScanner to only handle VS Code (no longer checks for Copilot CLI)
- Configuration uses mcpServers format with DOTNET_ROOT env passthrough
- Added comprehensive unit tests

Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 30, 2025

@copilot there is an issue with the vscode scanner. At the moment it detects copilot but we've found that the copilot config is actually global only so we need to introduce a new CopolotCliAgentEnviro...

Implemented in commit d5a3785. Created a new CopilotCliAgentEnvironmentScanner that:

  • Detects the presence of the copilot CLI
  • Writes configuration to $HOME/.copilot/mcp-config.json
  • Uses the mcpServers format with DOTNET_ROOT environment variable passthrough

Moved CopilotCliRunner and ICopilotCliRunner to the new Agents/CopilotCli namespace and updated VsCodeAgentEnvironmentScanner to only handle VS Code configuration.

Copilot AI changed the title Fix GitHub Copilot CLI detection to use 'copilot' command Fix GitHub Copilot CLI detection and add separate CopilotCliAgentEnvironmentScanner Nov 30, 2025
Copilot AI requested a review from mitchdenny November 30, 2025 07:51
@mitchdenny
Copy link
Copy Markdown
Member

@copilot to the mcp config for the copilot cli applicator add a "type": "local" and "tools": ["*"].

Added "type": "local" and "tools": ["*"] to the Copilot CLI applicator MCP configuration.

Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 30, 2025

@copilot to the mcp config for the copilot cli applicator add a "type": "local" and "tools": ["*"].

Added in commit 81f0513. The Copilot CLI MCP config now includes "type": "local" and "tools": ["*"].

@mitchdenny mitchdenny marked this pull request as ready for review November 30, 2025 10:56
Copilot AI review requested due to automatic review settings November 30, 2025 10:56
@mitchdenny mitchdenny merged commit 44db7cb into main Nov 30, 2025
580 of 583 checks passed
@mitchdenny mitchdenny deleted the copilot/fix-github-copilot-cli-detection branch November 30, 2025 10:56
@dotnet-policy-service dotnet-policy-service bot added this to the 13.1 milestone Nov 30, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a 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 fixes GitHub Copilot CLI detection and introduces proper separation of concerns between VS Code and Copilot CLI configuration. The main issue was that the CLI command was incorrectly set to github-copilot-cli instead of copilot. Additionally, since Copilot CLI uses a global configuration file at $HOME/.copilot/mcp-config.json (unlike VS Code's workspace-specific .vscode/mcp.json), a dedicated scanner was needed.

Key changes:

  • Fixed Copilot CLI command from github-copilot-cli to copilot in CopilotCliRunner
  • Created new CopilotCliAgentEnvironmentScanner for global Copilot CLI configuration
  • Moved Copilot CLI-related classes to new Agents.CopilotCli namespace for better organization

Reviewed changes

Copilot reviewed 21 out of 22 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
src/Aspire.Cli/Agents/CopilotCli/CopilotCliRunner.cs Fixed CLI command name and moved to new namespace
src/Aspire.Cli/Agents/CopilotCli/ICopilotCliRunner.cs Moved interface to new namespace
src/Aspire.Cli/Agents/CopilotCli/CopilotCliAgentEnvironmentScanner.cs New scanner for global Copilot CLI configuration
src/Aspire.Cli/Agents/VsCode/VsCodeAgentEnvironmentScanner.cs Removed Copilot CLI detection, now VS Code-specific
src/Aspire.Cli/Program.cs Registered new Copilot CLI scanner in DI container
src/Aspire.Cli/Resources/CopilotCliAgentEnvironmentScannerStrings.resx Added localization resources for new scanner
src/Aspire.Cli/Resources/CopilotCliAgentEnvironmentScannerStrings.Designer.cs Generated resource accessor class
src/Aspire.Cli/Resources/xlf/*.xlf Added localization files for supported languages
tests/Aspire.Cli.Tests/Agents/CopilotCliAgentEnvironmentScannerTests.cs Comprehensive tests for new scanner
tests/Aspire.Cli.Tests/Agents/VsCodeAgentEnvironmentScannerTests.cs Updated tests to remove Copilot CLI dependencies
Files not reviewed (1)
  • src/Aspire.Cli/Resources/CopilotCliAgentEnvironmentScannerStrings.Designer.cs: Language not supported
Comments suppressed due to low confidence (1)

src/Aspire.Cli/Agents/CopilotCli/CopilotCliRunner.cs:12

  • According to the custom XML documentation guidelines (CodingGuidelineID 1000002), internal classes should have brief documentation. This summary tag is verbose for an internal class.

Suggested change:

/// <summary>
/// Runs GitHub Copilot CLI commands.
/// </summary>

Comment on lines +63 to +65
/// <summary>
/// Gets the path to the Copilot CLI MCP configuration file.
/// </summary>
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

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

According to the custom XML documentation guidelines (CodingGuidelineID 1000002), internal classes should have brief documentation. This summary is unnecessarily verbose.

Suggested change:

/// <summary>
/// Gets the Copilot CLI MCP configuration file path.
/// </summary>

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +71 to +74
/// <summary>
/// Checks if the Copilot CLI global configuration has an "aspire" MCP server configured.
/// </summary>
/// <returns>True if the aspire server is already configured, false otherwise.</returns>
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

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

According to the custom XML documentation guidelines (CodingGuidelineID 1000002), internal classes should have brief documentation. This summary and return value are overly verbose for internal code.

Suggested change:

/// <summary>
/// Checks if the aspire MCP server is already configured.
/// </summary>
/// <returns>True if configured, false otherwise.</returns>

Copilot generated this review using guidance from repository custom instructions.
/// Initializes a new instance of <see cref="VsCodeAgentEnvironmentScanner"/>.
/// </summary>
/// <param name="gitRepository">The Git repository service for finding repository boundaries.</param>
/// <param name="vsCodeCliRunner">The VS Code CLI runner for checking if VS Code is installed.</param>
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

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

According to the custom XML documentation guidelines (CodingGuidelineID 1000002), internal classes should have concise parameter documentation. This is overly verbose for internal code.

Suggested change:

/// <param name="vsCodeCliRunner">The VS Code CLI runner.</param>

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +176 to +291
private sealed class TestCopilotCliAgentEnvironmentScanner : IAgentEnvironmentScanner
{
private const string McpConfigFileName = "mcp-config.json";
private const string AspireServerName = "aspire";

private readonly ICopilotCliRunner _copilotCliRunner;
private readonly string _configDirectory;

public TestCopilotCliAgentEnvironmentScanner(ICopilotCliRunner copilotCliRunner, string configDirectory)
{
_copilotCliRunner = copilotCliRunner;
_configDirectory = configDirectory;
}

public async Task ScanAsync(AgentEnvironmentScanContext context, CancellationToken cancellationToken)
{
var copilotVersion = await _copilotCliRunner.GetVersionAsync(cancellationToken).ConfigureAwait(false);

if (copilotVersion is null)
{
return;
}

if (HasAspireServerConfigured())
{
return;
}

context.AddApplicator(CreateApplicator());
}

private string GetMcpConfigFilePath() => Path.Combine(_configDirectory, McpConfigFileName);

private bool HasAspireServerConfigured()
{
var configFilePath = GetMcpConfigFilePath();

if (!File.Exists(configFilePath))
{
return false;
}

try
{
var content = File.ReadAllText(configFilePath);
var config = JsonNode.Parse(content)?.AsObject();

if (config is null)
{
return false;
}

if (config.TryGetPropertyValue("mcpServers", out var serversNode) && serversNode is JsonObject servers)
{
return servers.ContainsKey(AspireServerName);
}

return false;
}
catch (JsonException)
{
return false;
}
}

private AgentEnvironmentApplicator CreateApplicator()
{
return new AgentEnvironmentApplicator(
"Configure GitHub Copilot CLI to use the Aspire MCP server",
ApplyMcpConfigurationAsync);
}

private async Task ApplyMcpConfigurationAsync(CancellationToken cancellationToken)
{
var configFilePath = GetMcpConfigFilePath();

if (!Directory.Exists(_configDirectory))
{
Directory.CreateDirectory(_configDirectory);
}

JsonObject config;

if (File.Exists(configFilePath))
{
var existingContent = await File.ReadAllTextAsync(configFilePath, cancellationToken);
config = JsonNode.Parse(existingContent)?.AsObject() ?? new JsonObject();
}
else
{
config = new JsonObject();
}

if (!config.ContainsKey("mcpServers") || config["mcpServers"] is not JsonObject)
{
config["mcpServers"] = new JsonObject();
}

var servers = config["mcpServers"]!.AsObject();

servers[AspireServerName] = new JsonObject
{
["type"] = "local",
["command"] = "aspire",
["args"] = new JsonArray("mcp", "start"),
["env"] = new JsonObject
{
["DOTNET_ROOT"] = "${DOTNET_ROOT}"
},
["tools"] = new JsonArray("*")
};

var jsonContent = System.Text.Json.JsonSerializer.Serialize(config, JsonSourceGenerationContext.Default.JsonObject);
await File.WriteAllTextAsync(configFilePath, jsonContent, cancellationToken);
}
}
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

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

The test class TestCopilotCliAgentEnvironmentScanner contains a significant amount of duplicated logic from the actual CopilotCliAgentEnvironmentScanner class. This duplication makes maintenance difficult - if the production implementation changes, tests may continue passing with the old behavior.

Consider using the actual CopilotCliAgentEnvironmentScanner in tests by making the configuration directory path injectable through a constructor parameter or a protected virtual method that can be overridden in a test-specific subclass. This would reduce code duplication and ensure tests validate the actual production code.

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +12
/// <summary>
/// Scans for GitHub Copilot CLI environments and provides an applicator to configure the Aspire MCP server.
/// </summary>
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

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

According to the custom XML documentation guidelines (CodingGuidelineID 1000002), internal classes should have minimal documentation with brief <summary> tags only. This internal class has a detailed summary that should be shortened.

Suggested change:

/// <summary>
/// Scans for GitHub Copilot CLI and configures the Aspire MCP server.
/// </summary>

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +108 to +110
/// <summary>
/// Creates an applicator for configuring the MCP server in the Copilot CLI global configuration.
/// </summary>
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

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

According to the custom XML documentation guidelines (CodingGuidelineID 1000002), internal classes should have brief documentation. This summary is unnecessarily verbose.

Suggested change:

/// <summary>
/// Creates an applicator for configuring the Copilot CLI MCP server.
/// </summary>

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +118 to +120
/// <summary>
/// Creates or updates the mcp-config.json file in the Copilot CLI global configuration directory.
/// </summary>
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

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

According to the custom XML documentation guidelines (CodingGuidelineID 1000002), internal classes should have brief documentation. This summary is unnecessarily verbose.

Suggested change:

/// <summary>
/// Creates or updates the mcp-config.json file.
/// </summary>

Copilot generated this review using guidance from repository custom instructions.
/// <summary>
/// Initializes a new instance of <see cref="CopilotCliAgentEnvironmentScanner"/>.
/// </summary>
/// <param name="copilotCliRunner">The Copilot CLI runner for checking if Copilot CLI is installed.</param>
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

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

According to the custom XML documentation guidelines (CodingGuidelineID 1000002), internal classes should have concise parameter documentation without verbose descriptions. This description is more detailed than necessary for internal APIs.

Suggested change:

/// <param name="copilotCliRunner">The Copilot CLI runner.</param>

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +54 to +56
/// <summary>
/// Gets the path to the Copilot CLI global configuration directory.
/// </summary>
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

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

According to the custom XML documentation guidelines (CodingGuidelineID 1000002), internal classes should have brief documentation. This summary tag is unnecessarily verbose for an internal method.

Suggested change:

/// <summary>
/// Gets the Copilot CLI configuration directory path.
/// </summary>

Copilot generated this review using guidance from repository custom instructions.
sebastienros pushed a commit that referenced this pull request Dec 1, 2025
…ronmentScanner (#13250)

* Initial plan

* Fix GitHub Copilot CLI detection to use 'copilot' command instead of 'github-copilot-cli'

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>

* Add CopilotCliAgentEnvironmentScanner for global Copilot CLI configuration

- Created new Agents/CopilotCli folder with:
  - CopilotCliAgentEnvironmentScanner.cs - scans for Copilot CLI and writes to $HOME/.copilot/mcp-config.json
  - CopilotCliRunner.cs - runs Copilot CLI commands (moved from VsCode folder)
  - ICopilotCliRunner.cs - interface (moved from VsCode folder)
- Added resource files for scanner strings
- Updated VsCodeAgentEnvironmentScanner to only handle VS Code (no longer checks for Copilot CLI)
- Configuration uses mcpServers format with DOTNET_ROOT env passthrough
- Added comprehensive unit tests

Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com>

* Add type and tools properties to Copilot CLI MCP config

Added "type": "local" and "tools": ["*"] to the Copilot CLI applicator MCP configuration.

Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators Dec 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants