Skip to content

Refactor CLI MCP to get resources from app host#14252

Merged
JamesNK merged 11 commits intomainfrom
jamesnk/cli-list-resouces
Feb 2, 2026
Merged

Refactor CLI MCP to get resources from app host#14252
JamesNK merged 11 commits intomainfrom
jamesnk/cli-list-resouces

Conversation

@JamesNK
Copy link
Member

@JamesNK JamesNK commented Jan 30, 2026

Description

Aspire CLI MCP gets resource data via the dashboard. This is more steps than nessessary.

PR changes:

  • Get MCP tool gets resource data from the app host
  • Improve resource data from the app host. Rename properties/types to match what we use elsewhere. Add missing env vars
  • Avoiding duplicate logic. A number of types have been moved to shared source.
  • Tests.

This is the first PR to remove dependency on dashboard MCP.

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?

@github-actions
Copy link
Contributor

github-actions bot commented Jan 30, 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 -- 14252

Or

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

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

This PR refactors the CLI MCP (Model Context Protocol) implementation to obtain resource data directly from the AppHost backchannel instead of forwarding requests to the dashboard. This is the first step in removing the dependency on dashboard MCP, streamlining the architecture and reducing unnecessary communication hops.

Changes:

  • Refactored ListResourcesTool to query resources directly from AppHost backchannel instead of forwarding to dashboard MCP
  • Created shared utilities (ResourceSourceViewModel, DashboardUrls, ResourceSnapshotMapper) to enable code reuse between CLI and Dashboard
  • Added new properties to ResourceJson (Source, DashboardUrl, Commands) and ResourceSnapshot (DisplayName, Commands) to support richer resource information
  • Updated Dashboard code to use the new shared utilities and removed the showHiddenResources parameter from GetResourceName (now filtering is handled upstream)

Reviewed changes

Copilot reviewed 31 out of 33 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Shared/Model/Serialization/ResourceJson.cs Added Source, DashboardUrl, and Commands properties
src/Shared/Model/ResourceSourceViewModel.cs New shared file extracting resource source logic for reuse
src/Shared/DashboardUrls.cs Added CombineUrl and AddQueryString helper methods for URL manipulation
src/Aspire.Hosting/Backchannel/BackchannelDataTypes.cs Added DisplayName property to ResourceSnapshot and new ResourceSnapshotCommand type
src/Aspire.Hosting/Backchannel/AuxiliaryBackchannelRpcTarget.cs Updated to handle replica resources and map DisplayName/Name correctly
src/Aspire.Cli/Backchannel/ResourceSnapshotMapper.cs New mapper to convert ResourceSnapshot to ResourceJson with relationship resolution
src/Aspire.Cli/Backchannel/AppHostConnectionHelper.cs Extracted connection selection logic from AgentMcpCommand for reuse
src/Aspire.Cli/Mcp/Tools/ListResourcesTool.cs Refactored to get resources from backchannel instead of forwarding to dashboard
src/Aspire.Cli/Mcp/McpErrorMessages.cs New file with centralized error messages
src/Aspire.Cli/Mcp/KnownMcpTools.cs Moved ListResources from dashboard tools to CLI tools
src/Aspire.Cli/Commands/ResourcesCommand.cs Updated to use ResourceSnapshotMapper
src/Aspire.Cli/Commands/AgentMcpCommand.cs Simplified by using AppHostConnectionHelper
src/Aspire.Dashboard/Model/TelemetryExportService.cs Updated to resolve relationships by matching DisplayName
src/Aspire.Dashboard/Model/ResourceViewModel.cs Removed showHiddenResources parameter from GetResourceName
src/Aspire.Dashboard/Model/ResourceSourceViewModel.cs Refactored to use shared ResourceSource model
src/Aspire.Dashboard/Model/ExportHelpers.cs Updated signature to accept resourceByName dictionary
src/Aspire.Dashboard/Model/ResourceMenuBuilder.cs Changed parameter from Func to dictionary
src/Aspire.Dashboard/Components/Pages/Resources.razor.cs Updated to pass resourceByName dictionary
src/Aspire.Dashboard/Components/Pages/ConsoleLogs.razor.cs Updated to pass resourceByName dictionary
src/Aspire.Dashboard/Components/Controls/ResourceDetails.razor.cs Updated to pass ResourceByName instead of FormatName
src/Aspire.Dashboard/Components/Controls/ResourceActions.razor.cs Removed GetResourceName parameter
tests/Aspire.Dashboard.Tests/Model/*.cs Updated tests for new signatures and added proper assertions
src/Aspire.Cli/Aspire.Cli.csproj Added shared file links
src/Aspire.Dashboard/Aspire.Dashboard.csproj Added shared file links
Comments suppressed due to low confidence (1)

src/Aspire.Hosting/Backchannel/AuxiliaryBackchannelRpcTarget.cs:509

  • The Commands property from the resource snapshot is not being mapped to the ResourceSnapshot object. The Commands collection exists in the snapshot.Commands property (as seen in other parts of the codebase), but it's not being included in the returned ResourceSnapshot object. This will result in no commands being available when resources are queried through the backchannel.

The Commands should be mapped similar to how Endpoints, Relationships, HealthReports, and Volumes are mapped.

        return new ResourceSnapshot
        {
            Name = resourceEvent.ResourceId,
            DisplayName = resource.Name,
            ResourceType = snapshot.ResourceType,
            State = snapshot.State?.Text,
            StateStyle = snapshot.State?.Style,
            HealthStatus = snapshot.HealthStatus?.ToString(),
            ExitCode = snapshot.ExitCode,
            CreatedAt = snapshot.CreationTimeStamp,
            StartedAt = snapshot.StartTimeStamp,
            StoppedAt = snapshot.StopTimeStamp,
            Endpoints = endpoints,
            Relationships = relationships,
            HealthReports = healthReports,
            Volumes = volumes,
            Properties = properties,
            McpServer = mcpServer
        };

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sebastienros
Copy link
Member

Was it an oversight from me to use the new method in the mcp? I only refactored the resource mcp proxing. Also possible that we decided to postpone the rest of the migration to focus on the initial task.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 30, 2026

🎬 CLI E2E Test Recordings

The following terminal recordings are available for commit 050f566:

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 #21577958528

@JamesNK JamesNK force-pushed the jamesnk/cli-list-resouces branch from 864567d to e334013 Compare February 2, 2026 04:52
@JamesNK JamesNK merged commit 9c031a8 into main Feb 2, 2026
335 checks passed
@JamesNK JamesNK deleted the jamesnk/cli-list-resouces branch February 2, 2026 05:35
@dotnet-policy-service dotnet-policy-service bot added this to the 13.2 milestone Feb 2, 2026
@sebastienros
Copy link
Member

This PR changed ResourceSnapshot.Name from the app-model name to the DCP runtime ID and added a separate DisplayName field for the app-model name. The MCP tool routing code was not updated to use DisplayName, so it started passing the DCP runtime ID (e.g., db1-mcp-ypnvhwvw) to CallResourceMcpToolAsync, which looks up by app-model name. I am fixing it as part of #14494

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants