Skip to content

Add MCP command tests#14283

Merged
davidfowl merged 8 commits intomainfrom
jamesnk/cli-mcp-tests
Feb 2, 2026
Merged

Add MCP command tests#14283
davidfowl merged 8 commits intomainfrom
jamesnk/cli-mcp-tests

Conversation

@JamesNK
Copy link
Member

@JamesNK JamesNK commented Feb 2, 2026

Description

Adds unit tests for important CLI MCP functionality:

  • MCP server started
  • Listing tools from server
  • Calling tools from server
  • Non-known tools are returned

Notably, this PR adds IAppHostAuxiliaryBackchannel. Without this abstraction we'd have to spin up an RPC server for the implementation to call.

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?

Copilot AI review requested due to automatic review settings February 2, 2026 07:58
@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

🚀 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 -- 14283

Or

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

Copy link
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

Adds in-process unit test coverage for the CLI’s MCP server behavior by introducing test-friendly abstractions and DI overrides, enabling MCP server/client communication without spinning up external RPC infrastructure.

Changes:

  • Introduces IAppHostAuxiliaryBackchannel and updates backchannel monitor/command plumbing to depend on the interface.
  • Adds DI-provided MCP server transport (ITransport) so tests can inject an in-memory transport while production uses stdio.
  • Adds new MCP-focused test infrastructure and an in-process AgentMcpCommand test suite.

Reviewed changes

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

Show a summary per file
File Description
tests/Aspire.Cli.Tests/Utils/CliTestHelper.cs Adds DI factories for MCP transport and docs indexing to support test overrides.
tests/Aspire.Cli.Tests/TestServices/TestAuxiliaryBackchannelMonitor.cs Updates test monitor to store/return IAppHostAuxiliaryBackchannel.
tests/Aspire.Cli.Tests/TestServices/TestAppHostAuxiliaryBackchannel.cs New test double implementing IAppHostAuxiliaryBackchannel.
tests/Aspire.Cli.Tests/Mcp/TestMcpServerTransportFactory.cs New in-memory pipe transport helper for MCP server/client tests.
tests/Aspire.Cli.Tests/Mcp/TestDocsIndexService.cs New docs index test double to avoid network calls.
tests/Aspire.Cli.Tests/Mcp/MockPackagingService.cs Updates mock monitor signatures to use IAppHostAuxiliaryBackchannel.
tests/Aspire.Cli.Tests/Commands/AgentMcpCommandTests.cs New in-process tests for listing tools and calling select MCP tools via an injected transport.
src/Aspire.Cli/Program.cs Registers MCP ITransport (stdio) and adds MCP subcommands to DI.
src/Aspire.Cli/Mcp/KnownMcpTools.cs Minor cleanup of pattern matching for tool classification.
src/Aspire.Cli/Commands/RunCommand.cs Switches detached run backchannel handling to IAppHostAuxiliaryBackchannel.
src/Aspire.Cli/Commands/ResourcesCommand.cs Uses IAppHostAuxiliaryBackchannel for snapshot/watch operations.
src/Aspire.Cli/Commands/PsCommand.cs Uses IAppHostAuxiliaryBackchannel for listing AppHosts.
src/Aspire.Cli/Commands/McpStartCommand.cs Delegates via injected AgentMcpCommand instead of manual construction.
src/Aspire.Cli/Commands/McpCommand.cs Uses injected McpStartCommand/McpInitCommand instead of manual construction.
src/Aspire.Cli/Commands/LogsCommand.cs Uses IAppHostAuxiliaryBackchannel for log streaming operations.
src/Aspire.Cli/Commands/AgentMcpCommand.cs Accepts injected ITransport, exposes KnownTools for tests, and uses injected transport for server creation.
src/Aspire.Cli/Backchannel/IAuxiliaryBackchannelMonitor.cs Updates monitor contract to return IAppHostAuxiliaryBackchannel.
src/Aspire.Cli/Backchannel/IAppHostAuxiliaryBackchannel.cs New interface enabling test doubles for AppHost backchannel behavior.
src/Aspire.Cli/Backchannel/AuxiliaryBackchannelMonitor.cs Returns IAppHostAuxiliaryBackchannel while continuing to manage concrete connections internally.
src/Aspire.Cli/Backchannel/AppHostConnectionResolver.cs Returns interface-typed connection results.
src/Aspire.Cli/Backchannel/AppHostConnectionHelper.cs Returns selected connection as IAppHostAuxiliaryBackchannel.
src/Aspire.Cli/Backchannel/AppHostAuxiliaryBackchannel.cs Implements IAppHostAuxiliaryBackchannel.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

🎬 CLI E2E Test Recordings

The following terminal recordings are available for commit aa39385:

Test Recording
CreateAndDeployToDockerCompose ▶️ View Recording
CreateAndDeployToDockerComposeInteractive ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateEmptyAppHostProject ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording

📹 Recordings uploaded automatically from CI run #21593317652

@JamesNK JamesNK force-pushed the jamesnk/cli-mcp-tests branch from 4662a4d to 29d2c73 Compare February 2, 2026 08:50
}, _cts.Token);

// Wait a brief moment for the server to start
await Task.Delay(100, _cts.Token);
Copy link
Contributor

Choose a reason for hiding this comment

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

smell

@davidfowl davidfowl merged commit 42cd6dc into main Feb 2, 2026
660 of 663 checks passed
@davidfowl davidfowl deleted the jamesnk/cli-mcp-tests branch February 2, 2026 19:25
@davidfowl
Copy link
Contributor

We should probably add an e2e as well with a real mcp client.

@dotnet-policy-service dotnet-policy-service bot added this to the 13.2 milestone Feb 2, 2026
@github-actions github-actions bot locked and limited conversation to collaborators Mar 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants