diff --git a/core/Microsoft.Mcp.Core/src/Commands/BaseCommand.cs b/core/Microsoft.Mcp.Core/src/Commands/BaseCommand.cs index 80a33df534..dca50c35b9 100644 --- a/core/Microsoft.Mcp.Core/src/Commands/BaseCommand.cs +++ b/core/Microsoft.Mcp.Core/src/Commands/BaseCommand.cs @@ -110,6 +110,7 @@ protected virtual void HandleException(CommandContext context, Exception ex) { ArgumentException => HttpStatusCode.BadRequest, // Bad Request for invalid arguments InvalidOperationException => HttpStatusCode.UnprocessableEntity, // Unprocessable Entity for configuration errors + HttpRequestException httpEx => httpEx.StatusCode ?? HttpStatusCode.ServiceUnavailable, _ => HttpStatusCode.InternalServerError // Internal Server Error for unexpected errors }; diff --git a/core/Microsoft.Mcp.Core/src/Commands/GlobalCommand.cs b/core/Microsoft.Mcp.Core/src/Commands/GlobalCommand.cs index c5a20680b5..881ac19108 100644 --- a/core/Microsoft.Mcp.Core/src/Commands/GlobalCommand.cs +++ b/core/Microsoft.Mcp.Core/src/Commands/GlobalCommand.cs @@ -121,7 +121,7 @@ protected override TOptions BindOptions(ParseResult parseResult) KeyNotFoundException => HttpStatusCode.NotFound, AuthenticationFailedException => HttpStatusCode.Unauthorized, RequestFailedException rfEx => (HttpStatusCode)rfEx.Status, - HttpRequestException => HttpStatusCode.ServiceUnavailable, + HttpRequestException httpEx => httpEx.StatusCode ?? HttpStatusCode.ServiceUnavailable, _ => HttpStatusCode.InternalServerError }; diff --git a/servers/Azure.Mcp.Server/changelog-entries/1774379055021.yaml b/servers/Azure.Mcp.Server/changelog-entries/1774379055021.yaml new file mode 100644 index 0000000000..959e060310 --- /dev/null +++ b/servers/Azure.Mcp.Server/changelog-entries/1774379055021.yaml @@ -0,0 +1,3 @@ +changes: + - section: "Other Changes" + description: "Update HttpRequestException to attempt to return a more specific status code for better troubleshooting" \ No newline at end of file diff --git a/servers/Fabric.Mcp.Server/changelog-entries/1774379067978.yaml b/servers/Fabric.Mcp.Server/changelog-entries/1774379067978.yaml new file mode 100644 index 0000000000..959e060310 --- /dev/null +++ b/servers/Fabric.Mcp.Server/changelog-entries/1774379067978.yaml @@ -0,0 +1,3 @@ +changes: + - section: "Other Changes" + description: "Update HttpRequestException to attempt to return a more specific status code for better troubleshooting" \ No newline at end of file