{"record":{"id":"de7beb1094edb023","repo":"microsoft/aspire","slug":"internalerror","errorCode":"InternalError","errorMessage":"Multiple Aspire AppHosts are running in the scope of the MCP server's working directory. Use the 'select_apphost' tool to specify which AppHost to use.\n\nRunning AppHosts:\n{pathsList}","messagePattern":"Multiple Aspire AppHosts are running in the scope of the MCP server's working directory\\. Use the 'select_apphost' tool to specify which AppHost to use\\.\n\nRunning AppHosts:\n(.+?)","errorType":"error_code","errorClass":"McpProtocolException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Backchannel/AppHostConnectionHelper.cs","lineNumber":88,"sourceCode":"        // Get in-scope connections\n        var inScopeConnections = connections.Where(c => c.IsInScope).ToList();\n\n        if (inScopeConnections.Count == 1)\n        {\n            logger.LogDebug(\"Using single in-scope AppHost: {AppHostPath}\", inScopeConnections[0].AppHostInfo?.AppHostPath ?? \"N/A\");\n            return inScopeConnections[0];\n        }\n\n        if (inScopeConnections.Count > 1)\n        {\n            var paths = inScopeConnections\n                .Where(c => c.AppHostInfo?.AppHostPath != null)\n                .Select(c => c.AppHostInfo!.AppHostPath)\n                .ToList();\n\n            var pathsList = string.Join(\"\\n\", paths.Select(p => $\"  - {p}\"));\n\n            throw new McpProtocolException(\n                $\"Multiple Aspire AppHosts are running in the scope of the MCP server's working directory. \" +\n                $\"Use the 'select_apphost' tool to specify which AppHost to use.\\n\\nRunning AppHosts:\\n{pathsList}\",\n                McpErrorCode.InternalError);\n        }\n\n        var fallback = connections\n            .OrderBy(c => c.AppHostInfo?.AppHostPath ?? string.Empty, StringComparer.OrdinalIgnoreCase)\n            .ThenBy(c => c.AppHostInfo?.ProcessId ?? int.MaxValue)\n            .FirstOrDefault();\n\n        logger.LogDebug(\n            \"No in-scope AppHosts found. Falling back to first available AppHost: {AppHostPath}\",\n            fallback?.AppHostInfo?.AppHostPath ?? \"N/A\");\n\n        return fallback;\n    }\n}\n","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Backchannel/AppHostConnectionHelper.cs#L70-L106","documentation":"GetSelectedConnectionAsync resolves which running AppHost the MCP server should talk to. When more than one AppHost with a known AppHostPath is running within the MCP server's working directory scope and no explicit selection has been made, it throws an McpProtocolException (InternalError) listing all running AppHost paths so the caller can disambiguate.","triggerScenarios":"Calling any MCP tool backed by GetSelectedConnectionAsync while two or more AppHosts are running in the working-directory scope and 'select_apphost' has not been used to pick one.","commonSituations":"Developers running multiple Aspire AppHosts simultaneously (e.g., two solutions open) and issuing MCP commands from an editor agent without selecting the target AppHost first.","solutions":["Call the 'select_apphost' MCP tool to explicitly choose which AppHost to use, then retry the operation.","Stop or close the extra running AppHosts so only one remains in the working-directory scope.","Run the MCP server / agent from a working directory that unambiguously scopes to a single AppHost."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"var running = await mcp.ListRunningAppHostsAsync(); // if such a listing exists\nif (running.Count > 1) await mcp.CallToolAsync(\"select_apphost\", new { appHostPath = running[0].AppHostPath });","typeGuard":null,"tryCatchPattern":"try { await helper.GetSelectedConnectionAsync(); }\ncatch (McpProtocolException ex) when (ex.Code == McpErrorCode.InternalError && ex.Message.Contains(\"select_apphost\"))\n{ /* prompt user to pick an AppHost, then retry */ }","preventionTips":["Run only one AppHost per working-directory scope, or always select one via 'select_apphost' first.","Stop leftover AppHost processes before starting MCP-driven workflows.","Launch the MCP server from a directory that scopes to a single AppHost."],"tags":["mcp","apphost","ambiguity","cli"],"backgroundTag":"mutually-exclusive-options","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"}