microsoft/aspire · error · McpProtocolException

InternalError

InternalError

Error message

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.

Running AppHosts:
{pathsList}

What it means

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.

Solutions

  1. Call the 'select_apphost' MCP tool to explicitly choose which AppHost to use, then retry the operation.
  2. Stop or close the extra running AppHosts so only one remains in the working-directory scope.
  3. Run the MCP server / agent from a working directory that unambiguously scopes to a single AppHost.
Defensive patterns

Strategy: validation

Validate before calling

var running = await mcp.ListRunningAppHostsAsync(); // if such a listing exists
if (running.Count > 1) await mcp.CallToolAsync("select_apphost", new { appHostPath = running[0].AppHostPath });

Try / catch

try { await helper.GetSelectedConnectionAsync(); }
catch (McpProtocolException ex) when (ex.Code == McpErrorCode.InternalError && ex.Message.Contains("select_apphost"))
{ /* prompt user to pick an AppHost, then retry */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/de7beb1094edb023. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Cli/Backchannel/AppHostConnectionHelper.cs:88

        // Get in-scope connections
        var inScopeConnections = connections.Where(c => c.IsInScope).ToList();

        if (inScopeConnections.Count == 1)
        {
            logger.LogDebug("Using single in-scope AppHost: {AppHostPath}", inScopeConnections[0].AppHostInfo?.AppHostPath ?? "N/A");
            return inScopeConnections[0];
        }

        if (inScopeConnections.Count > 1)
        {
            var paths = inScopeConnections
                .Where(c => c.AppHostInfo?.AppHostPath != null)
                .Select(c => c.AppHostInfo!.AppHostPath)
                .ToList();

            var pathsList = string.Join("\n", paths.Select(p => $"  - {p}"));

            throw new McpProtocolException(
                $"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}",
                McpErrorCode.InternalError);
        }

        var fallback = connections
            .OrderBy(c => c.AppHostInfo?.AppHostPath ?? string.Empty, StringComparer.OrdinalIgnoreCase)
            .ThenBy(c => c.AppHostInfo?.ProcessId ?? int.MaxValue)
            .FirstOrDefault();

        logger.LogDebug(
            "No in-scope AppHosts found. Falling back to first available AppHost: {AppHostPath}",
            fallback?.AppHostInfo?.AppHostPath ?? "N/A");

        return fallback;
    }
}

View on GitHub (pinned to 25830f84bd)