Refactor CLI MCP to get resources from app host#14252
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 14252Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 14252" |
There was a problem hiding this comment.
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.Commandsproperty (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.
|
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. |
🎬 CLI E2E Test RecordingsThe following terminal recordings are available for commit
📹 Recordings uploaded automatically from CI run #21577958528 |
src/Aspire.Hosting/Backchannel/AuxiliaryBackchannelRpcTarget.cs
Outdated
Show resolved
Hide resolved
864567d to
e334013
Compare
|
This PR changed |
Description
Aspire CLI MCP gets resource data via the dashboard. This is more steps than nessessary.
PR changes:
This is the first PR to remove dependency on dashboard MCP.
Checklist
<remarks />and<code />elements on your triple slash comments?doc-ideatemplatebreaking-changetemplatediagnostictemplate