Class McpConnection
Manages a connection to an MCP server. Handles initialization handshake, tool discovery, and tool invocation over a given transport.
public sealed class McpConnection : IAsyncDisposable
- Inheritance
-
McpConnection
- Implements
- Inherited Members
Constructors
McpConnection(IMcpTransport)
public McpConnection(IMcpTransport transport)
Parameters
transportIMcpTransport
Properties
ServerName
The server name reported during initialization.
public string? ServerName { get; }
Property Value
ServerVersion
The server version reported during initialization.
public string? ServerVersion { get; }
Property Value
Tools
Tools discovered from the MCP server after InitializeAsync(CancellationToken).
public IReadOnlyList<McpToolInfo> Tools { get; }
Property Value
Methods
CallToolAsync(string, Dictionary<string, object>?, CancellationToken)
Calls a tool on the MCP server with the given arguments.
public Task<string> CallToolAsync(string toolName, Dictionary<string, object>? arguments = null, CancellationToken cancellationToken = default)
Parameters
toolNamestringargumentsDictionary<string, object>cancellationTokenCancellationToken
Returns
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.
InitializeAsync(CancellationToken)
Performs the MCP initialize handshake and discovers available tools.
public Task InitializeAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
RefreshToolsAsync(CancellationToken)
Re-fetches the tool list from the server.
public Task RefreshToolsAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken