Skip to content

Connection error at client with McpClientFactory.CreateAsync #385

Closed
@nschuessler

Description

@nschuessler

I've tried this with the latest preview 11 and it still happens.

I've created an mcp server (app service, windows) with the ModelContextProtocol library and am trying to connect the client.
It was working previously, but now the connection hangs connecting the SSE transport. This is on a direct connection between client and hosted azure app service.

The remoteUrl parameter is my app services /sse endpoint which is apparently necessary according to 208 and 330 may have an impact here too.

Ultimately, I'm trying to get secure authentication by using Azure API Management service (we can't have unsecured network endpoints on the network), but the 200 OK
doesn't get back to the client due to a transport connection drop on the response to the middle tier so the client never gets it.
In debugging that issue, I found the hang at the app service.

Any ideas what is wrong here?

Image

// Create the logging handler and wrap it around the default HttpClientHandler
var loggingHandler = new LoggingHandler(new HttpClientHandler() {  CheckCertificateRevocationList = true });

// Create HttpClient with our logging handler
HttpClient httpClient = new HttpClient(loggingHandler);

SseClientTransportOptions sseClientTransportOptions = new SseClientTransportOptions
{
    Endpoint = remoteUrl,
    AdditionalHeaders = new Dictionary<string, string>()
    {
        { "Ocp-Apim-Trace", "true" }
    },
    Name = "MCP"
};

var clientTransport = new SseClientTransport(
    sseClientTransportOptions, httpClient, ownsHttpClient: true);

var client = await McpClientFactory.CreateAsync(clientTransport);

foreach (var tool in await client.ListToolsAsync())
{
    Console.WriteLine($"{tool.Name} ({tool.Description})");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions