{"record":{"id":"64c1b3f09aa17df8","repo":"microsoft/aspire","slug":"internalerror-no-aspire-apphost-is-currently-running-to-use","errorCode":"InternalError","errorMessage":"No Aspire AppHost is currently running. To use resource MCP tools, start an Aspire application (e.g. 'aspire run') and then retry.","messagePattern":"No Aspire AppHost is currently running\\. To use resource MCP tools, start an Aspire application \\(e\\.g\\. 'aspire run'\\) and then retry\\.","errorType":"error_code","errorClass":"McpProtocolException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Commands/AgentMcpCommand.cs","lineNumber":265,"sourceCode":"        // Refresh resource tools if needed (e.g., AppHost selection changed or invalidated)\n        if (!_resourceToolRefreshService.TryGetResourceToolMap(out var resourceToolMap))\n        {\n            bool changed;\n            (resourceToolMap, changed) = await _resourceToolRefreshService.RefreshResourceToolMapAsync(cancellationToken);\n            if (changed)\n            {\n                await _resourceToolRefreshService.SendToolsListChangedNotificationAsync(cancellationToken).ConfigureAwait(false);\n            }\n            toolsRefreshed = true;\n        }\n\n        // Resource MCP tools are invoked via the AppHost backchannel (AppHost proxies to the resource MCP endpoint).\n        if (resourceToolMap.TryGetValue(toolName, out var resourceAndTool))\n        {\n            var connection = await GetSelectedConnectionAsync(cancellationToken).ConfigureAwait(false);\n            if (connection == null)\n            {\n                throw new McpProtocolException(\n                    \"No Aspire AppHost is currently running. To use resource MCP tools, start an Aspire application (e.g. 'aspire run') and then retry.\",\n                    McpErrorCode.InternalError);\n            }\n\n            var args = request.Params?.Arguments is { } a\n                ? new Dictionary<string, JsonElement>(a)\n                : null;\n\n            if (_logger.IsEnabled(LogLevel.Debug))\n            {\n                _logger.LogDebug(\"Invoking tool {Name} with arguments {Arguments}\", toolName, JsonSerializer.Serialize(args, BackchannelJsonSerializerContext.Default.DictionaryStringJsonElement));\n            }\n\n            var result = await connection.CallResourceMcpToolAsync(resourceAndTool.ResourceName, resourceAndTool.Tool.Name, args, cancellationToken).ConfigureAwait(false);\n\n            if (result is null)\n            {\n                throw new McpProtocolException($\"Failed to get MCP tool result for '{toolName}'. Try refreshing the tools with 'refresh_tools'.\", McpErrorCode.InternalError);","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Commands/AgentMcpCommand.cs#L247-L283","documentation":"Resource MCP tools are proxied through the AppHost auxiliary backchannel. When HandleCallToolAsync resolves a resource tool but GetSelectedConnectionAsync returns no active AppHost connection, the CLI throws McpProtocolException with InternalError explaining that no Aspire AppHost is running.","triggerScenarios":"Calling any resource MCP tool (mapped in resourceToolMap) while no AppHost is connected — the selection step found zero candidate backchannel connections (no 'aspire run' session, AppHost stopped/crashed, or backchannel not established).","commonSituations":"Agent invokes resource tools before 'aspire run' was started; the AppHost exited or was terminated mid-session; CLI was launched in a directory/session without a live run.","solutions":["Start an Aspire AppHost with 'aspire run' and retry the tool call","Verify the AppHost is still running and its backchannel is alive; restart it if it exited","Call 'refresh_tools' after the AppHost starts so the client picks up the now-available tools"],"exampleFix":"// before\nvar resources = await mcpClient.CallToolAsync(\"list_resources\");\n// after\nif (!await IsAppHostRunningAsync())\n{\n    Console.Error.WriteLine(\"Start the AppHost with 'aspire run' first.\");\n    return;\n}\nvar resources = await mcpClient.CallToolAsync(\"list_resources\");","handlingStrategy":"retry","validationCode":"// check for a live run/backchannel before calling resource tools\nvar conns = await backchannelMonitor.GetCurrentConnectionsAsync();\nif (conns.Count == 0) { Console.Error.WriteLine(\"Start the AppHost with 'aspire run' first.\"); return; }","typeGuard":"bool hasAppHost = connections.Count > 0;","tryCatchPattern":"try\n{\n    result = await client.CallToolAsync(toolName, args);\n}\ncatch (McpProtocolException ex) when (ex.Message.Contains(\"No Aspire AppHost is currently running\"))\n{\n    await StartAppHostAsync();\n    result = await client.CallToolAsync(toolName, args); // retry after starting\n}","preventionTips":["Start 'aspire run' before invoking resource tools","Monitor AppHost liveness and re-run refresh_tools after restarts","Avoid long-lived MCP sessions outliving the AppHost process"],"tags":["mcp","cli","apphost"],"backgroundTag":"connection-refused","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}