Bart Wullems defines a test-call command inside the Aspire AppHost with `WithCommand`, running his own C# code instead of wrapping curl. The same command is exposed as a dashboard button, an `aspire resource` CLI command and an Aspire MCP tool, cutting the trial-and-error out of the API-testing loop.
Key points
- `WithCommand` runs your own C# code and returns a result, where part one wrapped curl with `WithProcessCommand`.
- `GetEndpoint("http")` gives the command the real service URL, so nobody has to hunt for the port.
- Inputs are declared as `InteractionInput` inside `CommandOptions`; `ValidateArguments` rejects bad values before execution.
- `CommandResults.Success` and `CommandResults.Failure` surface human-readable messages in the dashboard.
- `CommandResultFormat.Json` hands CLI callers and agents the response as structured data.
- One definition reaches three surfaces: dashboard, `aspire resource <resource> <command>` and the MCP `execute_resource_command` tool.
Why it matters
Most of the cost agents pay while testing an API goes into discovery: which port, which path, which payload. Moving that knowledge into the AppHost puts a named, typed command next to the resource it belongs to, so the agent reads a contract instead of guessing. Two things to watch when you copy the pattern: not every interaction is available on every surface, so verify the command in the dashboard, the CLI and MCP separately; and creating an `HttpClient` per call, as the demo does, is not what you want in a long-running AppHost. Existing REST clients and collections keep their place; these commands complement them on the agent side.
Real-world use
- An agent calling a catalog endpoint without guessing ports or writing curl commands
- A developer typing a brand ID into a dashboard button and getting the product list back as JSON
- Validated test commands that reject bad input before any HTTP call is made
This summary was generated by the agent from the original post on Bart Wullems (The Art of Simplicity). The full text and all rights belong to its author and publisher. Go to original