Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 14, 2025

McpClient.CreateAsync throws HttpRequestException when HTTP connection issues occur (e.g., authentication failures), but this was undocumented.

Changes

Added XML documentation to McpClient.CreateAsync:

  • Exception tag: Documents HttpRequestException for HTTP transport connection errors
  • Remarks section: Explains HTTP 401 Unauthorized scenario and references HttpClientTransportOptions.OAuth for credential configuration

Example

// Server requiring authentication without credentials - will throw HttpRequestException (401 Unauthorized)
await using var transport = new HttpClientTransport(new()
{
    Endpoint = new("https://protected-server.example.com"),
});
var client = await McpClient.CreateAsync(transport); // Throws HttpRequestException

// Configure OAuth to authenticate
await using var authenticatedTransport = new HttpClientTransport(new()
{
    Endpoint = new("https://protected-server.example.com"),
    OAuth = new()
    {
        ClientId = "client-id",
        ClientSecret = "client-secret",
        // ... other OAuth configuration
    },
});
var authenticatedClient = await McpClient.CreateAsync(authenticatedTransport); // Succeeds
Original prompt

This section details on the original issue you should resolve

<issue_title>The CreateAsync method of McpClient should document HttpRequestException</issue_title>
<issue_description>Describe the bug

CreateAsync will throw an HttpRequestException if there is a problem connecting to the MCP server over an HTTP transport. This should be documented.

To Reproduce

Attempt to connect to an MCP server that requires authentication but do not supply credentials.

Expected behavior

The expected behavior is an HttpRequestException, so this should be documented on CreateAsync.

Logs
If applicable, add logs to help explain your problem.

Additional context

In addition to simply documenting that CreateAsync may throw this exception, further explanation should be provided in the remarks for the Unauthorized case, that the server requires authorization and that credentials must be supplied in the Oauth property of the Transport.
</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Document HttpRequestException in CreateAsync method Document HttpRequestException thrown by McpClient.CreateAsync Dec 14, 2025
Copilot AI requested a review from stephentoub December 14, 2025 15:43
@stephentoub stephentoub marked this pull request as ready for review December 14, 2025 15:54
@stephentoub stephentoub enabled auto-merge (squash) December 14, 2025 15:54
Copy link
Contributor

@mikekistler mikekistler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 👍

@stephentoub stephentoub merged commit 5b74ee2 into main Dec 15, 2025
16 of 17 checks passed
@stephentoub stephentoub deleted the copilot/document-httprequestexception branch December 15, 2025 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The CreateAsync method of McpClient should document HttpRequestException

3 participants