Skip to content

More detailed error message #816

@EelcoKoster

Description

@EelcoKoster

Is your feature request related to a problem? Please describe.
From my C# project I try to connect to a MCP server in Python.

I successfully connected from C# to a streaming-http mcp server. So the code works and looks like this:

try
{
    var mcpClient = await McpClientFactory.CreateAsync(new SseClientTransport(new()
    {
        Endpoint = new Uri("http://localhost:7071/mcp/"),
        TransportMode = HttpTransportMode.StreamableHttp,
    }, factory), new()
    {
        ProtocolVersion = "2025-06-18",
        ClientInfo = new() { Name = "AI Test client", Version = "1.0" }
    },
    factory);
    var tools = await mcpClient.ListToolsAsync();
    kernel.Plugins.AddFromFunctions("Hello", tools.Select(t => t.AsKernelFunction()));
}
catch (Exception e)
{
    Console.WriteLine($"ERROR Connecting to MCP server: {e.Message}");
}

I created a python MCP server. And tested it with MCP Inspector and Postman succesfully.
But when I try to connect to the MCP server with the above C# code. I get the error message "Response status code does not indicate success: 400 (Bad Request)". This is not very helpfull. There is probably a response text with the reason for the bad request. But I can not see it.

Errorlog is:
[2025-09-24T14:01:17.309Z] fail: ModelContextProtocol.Client.McpClient[1155727496]
[2025-09-24T14:01:17.313Z] http://localhost:7071/mcp/ client initialization error.
[2025-09-24T14:01:17.325Z] System.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request).
[2025-09-24T14:01:17.327Z] at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
[2025-09-24T14:01:17.329Z] at ModelContextProtocol.Client.StreamableHttpClientSessionTransport.SendMessageAsync(JsonRpcMessage message, CancellationToken cancellationToken)
[2025-09-24T14:01:17.330Z] at ModelContextProtocol.McpSession.SendRequestAsync(JsonRpcRequest request, CancellationToken cancellationToken)
[2025-09-24T14:01:17.334Z] at ModelContextProtocol.McpEndpointExtensions.SendRequestAsync[TParameters,TResult](IMcpEndpoint endpoint, String method, TParameters parameters, JsonTypeInfo1 parametersTypeInfo, JsonTypeInfo1 resultTypeInfo, RequestId requestId, CancellationToken cancellationToken)
[2025-09-24T14:01:17.343Z] at ModelContextProtocol.Client.McpClient.ConnectAsync(CancellationToken cancellationToken)
[2025-09-24T14:01:17.347Z] info: ModelContextProtocol.Client.McpClient[2081236114]
[2025-09-24T14:01:17.350Z] http://localhost:7071/mcp/ shutting down.
[2025-09-24T14:01:17.351Z] info: ModelContextProtocol.Client.McpClient[2103773711]
[2025-09-24T14:01:17.353Z] http://localhost:7071/mcp/ message processing canceled.
[2025-09-24T14:01:17.354Z] info: ModelContextProtocol.Client.McpClient[613617602]
[2025-09-24T14:01:17.356Z] http://localhost:7071/mcp/ shut down.

Describe the solution you'd like
When an error happens. I would like to also see the http response text so I can find the reason of the faulty http status.

Extra context
Python code (simplified) of MCP server (this is a functionapp with FastAPI and timertrigger + MCP):

import azure.functions as func
from fastapi import FastAPI
from mcp.server.fastmcp import FastMCP

mcp = FastMCP("Hello MCP", streamable_http_path = "/mcp/", json_response=True)

@mcp.tool()
async def hello(name: str) -> str:
    """Says hello to the user."""
    logging.info(f"Hello function called with name: {name}")
    return f"Hello, {name}!"

fast_app = FastAPI(title = "Hello API")

@fast_app.get("/hello")
async def root():
    return {"message": "Hello World"}

mcp_app = mcp.streamable_http_app()
mcp_app.mount("/", app=fast_app)

app = func.AsgiFunctionApp(app=mcp_app, http_auth_level=func.AuthLevel.ANONYMOUS)

@app.timer_trigger(arg_name="timer", schedule="0 0 8 * * *")
async def hello_timer(timer: func.TimerRequest):
    logging.info(f"Hello timer triggered!")

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions