You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add a connect command per resource to aspire describe and MCP list_resources - #22633
An agent (or a person) confirming a diagnosis at a dependency needs the container, the credential variables, the port that speaks the plain protocol, and the client tool. Today aspire describe --format Json gives the container ID and variable names, but whether the vendor's client works depends on the integration (TLS on the default port, no client in the image, renamed clients, HTTPS on a documented HTTP port...), so every skill carries per-integration workarounds.
This PR adds a connect entry per resource to aspire describe --format json (and --follow NDJSON) and to the MCP list_resources output: the command that reaches the resource with its own client. Each hosting integration declares its own entry, because only it knows its client, ports, TLS setup and credential variables. Resources without a declaration have no connect.
Output from a local run of an AppHost with these integrations (container names are the real DCP names; commands were executed successfully with the appended arguments shown below):
"connect": {
"command": "env AZURE_STORAGE_CONNECTION_STRING='DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8...GMGw==;BlobEndpoint=http://127.0.0.1:15974/devstoreaccount1;QueueEndpoint=http://127.0.0.1:15975/devstoreaccount1;TableEndpoint=http://127.0.0.1:15976/devstoreaccount1;' az storage",
"runs": "host",
"tool": "az",
"append": "<command group and options>, for example container list",
"note": "Requires the Azure CLI on the host. The account key is Azurite's well-known development key."
}
Integration
runs
tool
Verified locally with
PostgreSQL
container
psql
-c 'SELECT 1'
MySQL
container
mysql
-e 'SELECT 1'
Redis (plain port; switches to the non-TLS secondary endpoint when TLS is enabled)
container
redis-cli
PING, and SET/GET with WithPassword(null)
Valkey
container
valkey-cli
PING
SQL Server (follows the WithRepl sqlcmd path)
container
sqlcmd
-Q 'SELECT 1'
MongoDB (adds --tls + CA bundle when TLS is on)
container
mongosh
--eval 'db.runCommand({ ping: 1 })' (over TLS)
RabbitMQ
container
rabbitmqctl
list_queues
Azure Storage emulator (Azurite)
host
az
container list -o table
Azure Cosmos DB emulator (vNext)
host
curl
-i (HTTP gateway, WithoutHttpsCertificate())
Custom resources can declare their own entry. C# AppHost:
varnats=builder.AddContainer("nats","nats").WithEndpoint(targetPort:4222,name:"tcp");nats.WithConnectCommand("nats",ConnectCommandLocation.Host,ReferenceExpression.Create($"nats --server nats://localhost:{nats.GetEndpoint("tcp").Property(EndpointProperty.Port)}"),append:"<command>, for example server info");
TypeScript AppHost:
awaitcontainer.withConnectCommand("nginx",ConnectCommandLocation.Container,refExpr`exec nginx`);awaitdockerContainer.withConnectCommand("curl",ConnectCommandLocation.Host,refExpr`curl -sS http://localhost:${endpointPort}/`,{append: "<curl options>",note: "Requires curl on the host."});
Design
Hosting API (experimental, ASPIRECONNECT001): ConnectCommandAnnotation, ConnectCommandLocation { Container, Host }, and WithConnectCommand(tool, location, command, append?, note?) (ATS-exported; last call wins). command is a ReferenceExpression that ends where the client's own arguments go.
Container: the command is a shell script. Tooling renders <docker|podman> exec <container-name> sh -c '<script> "$@"' sh, using the configured container runtime and the container name (not the 64-char ID), single-quote-escaping the script so appended arguments are forwarded to the client. Credentials are read from the container's own environment variables.
Host: the command is a host command line, usually using the published endpoint port.
Resolution in the AppHost (ConnectCommandResolver, called when building backchannel resource snapshots): adds ResourceSnapshot.Connect. The CLI maps it to ResourceJson.Connect (describe) and McpResourceJson.Connect (MCP; omitted rather than truncated when the command exceeds 2048 characters). Older CLIs ignore the new field; newer CLIs with older AppHosts see no connect.
Scope: container-backed integrations, including local Azure emulators (same container case). Designed for, not implemented: provisioned Azure cloud resources (no container, Entra ID/connection-string auth, az-style host tools); runs: host with endpoint references can express them. Follow-ups: NATS, Qdrant, Garnet (no client in image → host), Kafka (renamed client, unreachable advertised listener), Keycloak, Seq, Service Bus/Event Hubs emulators, and Azure cloud resources.
The audit's SQL Server SSL_CERT_DIR failure did not reproduce with sqlcmd -C on the current image (the in-container SSL_CERT_DIR list is set and SELECT 1 succeeds), so no workaround is included.
The AppHost generates shell command lines that tooling prints and agents execute. To keep secrets out of them, the resolver only accepts commands whose ReferenceExpression references literals and endpoint values (recursively, including conditional branches); any parameter (secret or not), connection string or other value provider causes the entry to be omitted. Credentials are referenced by in-container variable name only. Scripts are single-quote escaped when wrapped in sh -c; integration scripts are authored by the integration and treated as trusted. The Azurite entry prints Azurite's publicly documented development account key. Endpoint values are resolved only when already allocated, so snapshot streaming never blocks on allocation.
Validation
dotnet test --project tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj --no-launch-profile -- --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true": 2855 passed, 2 failed (PipelineOutputSelectionTests.GitMetadataOutsideConfiguredWorktreeUsesNonWorktreePolicy, git exit code 128 in this worktree environment; unrelated).
New connect tests in Aspire.Hosting.{PostgreSQL,MySql,Redis,Valkey,SqlServer,MongoDB,RabbitMQ,Azure}.Tests (--filter-method per test): all passed.
Aspire.Hosting.CodeGeneration.{TypeScript,Go,Java,Python,Rust}.Tests (full): all passed after updating the generated-SDK snapshots for the new export.
Polyglot validation apphosts (tests/PolyglotAppHosts/Aspire.Hosting/*): aspire restore with the local CLI, then tsc --noEmit (TypeScript), pyright (Python), go build/go vet (Go), javac --enable-preview --source 25 (Java): all passed.
Manual end-to-end with Docker: started an AppHost with all integrations above via the local CLI, ran aspire describe --format json, and executed every connect.command with the appended arguments in the table: all succeeded. The Cosmos emulator with HTTPS could not start on this machine (macOS keychain refused exporting the dev-cert key), so HTTPS Cosmos was not validated end to end; the HTTP gateway was.
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?
Hosting integrations can declare how to reach their resource with the
vendor's own client (ConnectCommandAnnotation / WithConnectCommand,
experimental ASPIRECONNECT001). The AppHost resolves the declaration into
the backchannel resource snapshot (container runtime, container name,
endpoint ports; parameters and connection strings are rejected so no
secret can appear) and the CLI surfaces it as 'connect' in
'aspire describe --format json' and MCP list_resources.
Declared for PostgreSQL, MySQL, Redis, Valkey, SQL Server, MongoDB,
RabbitMQ (in container) and the Azurite and Cosmos DB emulators (on host).
Relates to #22505 and #22511.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
Focused review — problems only. The overall design (integration-owned declarations, endpoint-only allow-list, container name via DCP instance name, omission until allocation) is sound; I verified custom WithContainerName and the WSLc/Podman runtime names resolve correctly. Two issues below.
- Integration defaults (Redis/MongoDB TLS refresh, SQL Server WithRepl) no
longer replace a command the app declared with WithConnectCommand.
- Omit connect, rather than failing the snapshot, when the container runtime
cannot be resolved or the command references an undefined endpoint.
- Reject target ports that are not fixed (DCP templates) and browser origins
(which wait on URL callbacks).
Co-authored-by: Copilot App <[email protected]>
Calling AddAzureStorage(...).WithConnectCommand(...).RunAsEmulator() replaces the caller's command with this integration default, contrary to the documented guarantee that defaults preserve AppHost declarations. Use the shared default-command helper and add regression coverage for a custom declaration before RunAsEmulator. The same issue occurs in src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBExtensions.cs:223.
Unquoted CA-file path breaks TLS when the path contains spaces
The CA-file expansion is unquoted. With a supported CustomCertificatesDestination such as /custom certs, ContainerCreator supplies /custom certs/cert.pem, but this script passes /custom and certs/cert.pem as separate arguments to mongosh, so the TLS connection fails. Quote the inner CA-file variable while keeping --tlsCAFile a separate argument, and update the TLS command expectation to cover a path containing spaces.
Referenced endpoint changes are not published in --follow mode
In --follow, a host command referencing another resource's endpoint can stay absent after allocation or retain an old port after reallocation, because only the referenced resource publishes an update. Track those endpoint changes and publish updated connect metadata for the command's owner, ensuring snapshot equality does not suppress the update. Add a watch regression test covering allocation and reallocation.
…oints
- Azurite and Cosmos DB emulators declare their connect command with the
shared default helper, so RunAsEmulator keeps an app-declared command.
- Quote the MongoDB CA bundle path so destinations with spaces stay one
argument to mongosh.
- Only allow the resource's own endpoints in connect commands. The command is
re-resolved when its own resource publishes a snapshot, so another
resource's endpoint could otherwise stay missing or stale in watch streams.
Co-authored-by: Copilot App <[email protected]>
RunAsEmulator overwrites custom connect commands: confirmed. Azurite and the Cosmos DB emulator now declare their command through the shared default helper, so a WithConnectCommand made before RunAsEmulator is kept. Tests: AzureStorageEmulatorKeepsAppDeclaredConnectCommand, CosmosDBEmulatorKeepsAppDeclaredConnectCommand.
Unquoted MongoDB CA-file path: confirmed (CustomCertificatesDestination flows into the bundle path). Now ${ASPIRE_MONGODB_REPL_CA_FILE:+--tlsCAFile "$ASPIRE_MONGODB_REPL_CA_FILE"}. Verified in the mongo image's /bin/sh (dash): CA='/custom certs/cert.pem' yields the two arguments --tlsCAFile and /custom certs/cert.pem, and nothing when unset. Updated the TLS expectation in MongoDBWithCertificateConnectCommandUsesTls.
Referenced endpoint changes not published in --follow: confirmed for endpoints of other resources. Instead of tracking cross-resource endpoint changes, connect commands may now reference only the resource's own endpoints. A connect command describes how to reach that resource, every in-repo declaration already uses only its own endpoints, and the owner republishes its snapshot when its endpoints change. Names are compared, so Azure emulator surrogate builders still work. Tests: OmitsCommandThatReferencesAnotherResourcesEndpoint, and WatchResourceSnapshotsAsync_RefreshesConnectCommandWhenOwnEndpointIsReallocated for a reallocation through the watch stream. The not-yet-allocated case is covered by OmitsCommandUntilEndpointIsAllocated. The docs and spec now state the rule.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The generated Docker command lacks exec -i, causing psql to exit instead of accepting queries and preventing piped SQL input; stdin support and corresponding snapshot coverage are needed.
Render container connect commands as 'exec -i' (without a TTY) so interactive
clients stay open and piped input reaches the client.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because custom self-signed certificates can cause the advertised HTTPS connect command to fail host verification, despite trust being configured inside the emulator.
…ficate
The host-side curl command verifies the gateway certificate against the host's
trust store. Keep verification on and tell users to append --cacert for a
certificate the host does not trust, such as a custom self-signed one.
Co-authored-by: Copilot App <[email protected]>
Re this review: the concern is valid. The Cosmos emulator's curl command runs on the host, so it checks the gateway certificate against the host's trust store, not the trust configured inside the container. The default Aspire dev certificate is normally trusted on the host, but a custom self-signed certificate from WithHttpsCertificate is not.
I kept certificate verification on instead of adding -k, because the advertised command is meant to be copied as-is by agents and people. The Cosmos connect.note now says to append --cacert <certificate file> when the host doesn't trust the certificate. CosmosDBEmulatorDeclaresHostCurlConnectCommandForGateway checks the note.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Faulted endpoint allocation can throw during validation outside the existing exception boundary, aborting resource listing or watch streams instead of omitting connect; validation needs to be covered by the catch and a regression test.
The orchestrator allocates custom resource endpoints asynchronously after
StartAsync returns, so reading AllocatedEndpoint directly raced on Windows CI.
Co-authored-by: Copilot App <[email protected]>
A faulted allocation completes its snapshot, so inspecting it during
validation rethrew outside the resolver's exception boundary and aborted the
resource listing and watch stream. Validate inside that boundary.
Co-authored-by: Copilot App <[email protected]>
…DB, notes
- Drop the absolute no-secrets claim from MCP guidance; document connect
fields as public and omit an entry that contains a known secret value.
- State that connect.command is a POSIX sh command line.
- Reject endpoint references bound to networks other than localhost.
- Treat cancellation of the shared runtime probe by another caller as an
optional-entry failure, retrying once.
- MongoDB reads credentials inside mongosh's --eval script, so they stay out
of argv and dash-prefixed passwords work.
- Shorten the Cosmos note to fit the MCP text limit.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Critical secret-filtering gaps allow apostrophe-containing credentials and secrets updated during runtime resolution to leak through published commands or notes.
Re-read the redaction history after connect resolution, which can await
container runtime detection, and also match secrets as they appear inside
the single-quoted container script.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because omitted findings identify critical host-side shell evaluation of custom container names and ineffective cancellation while awaiting a shared runtime probe.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
An agent (or a person) confirming a diagnosis at a dependency needs the container, the credential variables, the port that speaks the plain protocol, and the client tool. Today
aspire describe --format Jsongives the container ID and variable names, but whether the vendor's client works depends on the integration (TLS on the default port, no client in the image, renamed clients, HTTPS on a documented HTTP port...), so every skill carries per-integration workarounds.This PR adds a
connectentry per resource toaspire describe --format json(and--followNDJSON) and to the MCPlist_resourcesoutput: the command that reaches the resource with its own client. Each hosting integration declares its own entry, because only it knows its client, ports, TLS setup and credential variables. Resources without a declaration have noconnect.Fixes #22505
Part of #22511
User-facing usage
Output from a local run of an AppHost with these integrations (container names are the real DCP names; commands were executed successfully with the appended arguments shown below):
runstoolpsql-c 'SELECT 1'mysql-e 'SELECT 1'redis-cliPING, andSET/GETwithWithPassword(null)valkey-cliPINGWithReplsqlcmd path)sqlcmd-Q 'SELECT 1'--tls+ CA bundle when TLS is on)mongosh--eval 'db.runCommand({ ping: 1 })'(over TLS)rabbitmqctllist_queuesazcontainer list -o tablecurl-i(HTTP gateway,WithoutHttpsCertificate())Custom resources can declare their own entry. C# AppHost:
TypeScript AppHost:
Design
ASPIRECONNECT001):ConnectCommandAnnotation,ConnectCommandLocation { Container, Host }, andWithConnectCommand(tool, location, command, append?, note?)(ATS-exported; last call wins).commandis aReferenceExpressionthat ends where the client's own arguments go.Container: the command is a shell script. Tooling renders<docker|podman> exec <container-name> sh -c '<script> "$@"' sh, using the configured container runtime and the container name (not the 64-char ID), single-quote-escaping the script so appended arguments are forwarded to the client. Credentials are read from the container's own environment variables.Host: the command is a host command line, usually using the published endpoint port.ConnectCommandResolver, called when building backchannel resource snapshots): addsResourceSnapshot.Connect. The CLI maps it toResourceJson.Connect(describe) andMcpResourceJson.Connect(MCP; omitted rather than truncated when the command exceeds 2048 characters). Older CLIs ignore the new field; newer CLIs with older AppHosts see noconnect.az-style host tools);runs: hostwith endpoint references can express them. Follow-ups: NATS, Qdrant, Garnet (no client in image →host), Kafka (renamed client, unreachable advertised listener), Keycloak, Seq, Service Bus/Event Hubs emulators, and Azure cloud resources.SSL_CERT_DIRfailure did not reproduce withsqlcmd -Con the current image (the in-containerSSL_CERT_DIRlist is set andSELECT 1succeeds), so no workaround is included.telemetryReceivedin describe JSON /list_resources) and MCP: compact default responses for list_traces, list_structured_logs, list_console_logs and list_resources #22580 (compact MCPlist_resources); this PR only appends a field and a one-line preamble, so conflicts should be trivial.Security considerations
The AppHost generates shell command lines that tooling prints and agents execute. To keep secrets out of them, the resolver only accepts commands whose
ReferenceExpressionreferences literals and endpoint values (recursively, including conditional branches); any parameter (secret or not), connection string or other value provider causes the entry to be omitted. Credentials are referenced by in-container variable name only. Scripts are single-quote escaped when wrapped insh -c; integration scripts are authored by the integration and treated as trusted. The Azurite entry prints Azurite's publicly documented development account key. Endpoint values are resolved only when already allocated, so snapshot streaming never blocks on allocation.Validation
dotnet test --project tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj --no-launch-profile -- --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true": 2855 passed, 2 failed (PipelineOutputSelectionTests.GitMetadataOutsideConfiguredWorktreeUsesNonWorktreePolicy, git exit code 128 in this worktree environment; unrelated).dotnet test --project tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj --no-launch-profile -- --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true": 10600 passed, 2 failed (NuGetPackageOperationConfigurationTests.AllWritersMaterializeTheComposedSourceRestriction,PrebuiltAppHostServerTests.PrepareAsync_WithProjectReferencesAndExplicitChannel_...; machine-levelnuget.orgsource leaking into expected source lists; unrelated).Aspire.Hosting.{PostgreSQL,MySql,Redis,Valkey,SqlServer,MongoDB,RabbitMQ,Azure}.Tests(--filter-methodper test): all passed.Aspire.Hosting.CodeGeneration.{TypeScript,Go,Java,Python,Rust}.Tests(full): all passed after updating the generated-SDK snapshots for the new export.tests/PolyglotAppHosts/Aspire.Hosting/*):aspire restorewith the local CLI, thentsc --noEmit(TypeScript),pyright(Python),go build/go vet(Go),javac --enable-preview --source 25(Java): all passed.aspire describe --format json, and executed everyconnect.commandwith the appended arguments in the table: all succeeded. The Cosmos emulator with HTTPS could not start on this machine (macOS keychain refused exporting the dev-cert key), so HTTPS Cosmos was not validated end to end; the HTTP gateway was.Checklist
<remarks />and<code />elements on your triple slash comments?