Mcp.Gateway.Client 1.8.7

dotnet add package Mcp.Gateway.Client --version 1.8.7
                    
NuGet\Install-Package Mcp.Gateway.Client -Version 1.8.7
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Mcp.Gateway.Client" Version="1.8.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mcp.Gateway.Client" Version="1.8.7" />
                    
Directory.Packages.props
<PackageReference Include="Mcp.Gateway.Client" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Mcp.Gateway.Client --version 1.8.7
                    
#r "nuget: Mcp.Gateway.Client, 1.8.7"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Mcp.Gateway.Client@1.8.7
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Mcp.Gateway.Client&version=1.8.7
                    
Install as a Cake Addin
#tool nuget:?package=Mcp.Gateway.Client&version=1.8.7
                    
Install as a Cake Tool

Mcp.Gateway.Client

Mcp.Gateway.Client is a robust .NET client library for the Model Context Protocol (MCP). It provides a unified interface to communicate with MCP servers over various transports, including HTTP (with SSE), WebSockets, and Standard Input/Output (stdio).

🚀 Features

  • Multiple Transports:
    • HTTP: Standard JSON-RPC over HTTP POST.
    • HTTP + SSE: Server-Sent Events for server-to-client notifications (MCP v1.7.0+ session support).
    • WebSocket: Full bidirectional communication.
    • Stdio: Standard Input/Output for local process communication.
  • Type-Safe Tool Invocation: Call tools with strongly-typed request and response models.
  • Notification Support: Listen for server-initiated events (e.g., logs, resource updates).
  • Async/Await: Fully asynchronous API designed for modern .NET applications.
  • .NET 10 Support: Built for the latest .NET ecosystem.

📦 Installation

Install the NuGet package:

dotnet add package Mcp.Gateway.Client

Or via the Package Manager Console:

Install-Package Mcp.Gateway.Client

🛠️ Usage

1. Choose a Transport

HTTP Transport (Basic RPC)

Best for stateless request/response patterns.

using Mcp.Gateway.Client;

// Connect to an MCP server over HTTP
await using var transport = new HttpMcpTransport("http://localhost:5000", "/mcp");
HTTP Transport with SSE (Notifications)

Enables server-to-client notifications using Server-Sent Events and Session Management.

// Enable SSE for notifications
await using var transport = new HttpMcpTransport("http://localhost:5000", "/mcp", enableSse: true);
WebSocket Transport

Ideal for persistent, bidirectional connections.

// Connect via WebSocket
await using var transport = new WebSocketMcpTransport("ws://localhost:5000/ws");
Stdio Transport

Used for communicating with local MCP servers running as subprocesses.

// Use Console.In and Console.Out (default)
await using var transport = new StdioMcpTransport();

// Or use custom streams (e.g., from a Process)
// await using var transport = new StdioMcpTransport(process.StandardOutput.BaseStream, process.StandardInput.BaseStream);

2. Initialize the Client

Wrap the transport in an McpClient and connect.

using Mcp.Gateway.Client;

// Create client
await using var client = new McpClient(transport);

// Handle notifications (optional)
client.NotificationReceived += (sender, e) =>
{
    Console.WriteLine($"Notification received: {e.Method}");
};

// Connect (performs handshake if necessary)
await client.ConnectAsync();

3. Call Tools

Invoke tools defined on the MCP server.

// Define response model
public record AddResponse(double Result);

// Call tool
var result = await client.CallToolAsync<AddResponse>(
    "add_numbers", 
    new { number1 = 10, number2 = 20 }
);

Console.WriteLine($"Result: {result.Result}"); // Output: 30

4. List Available Tools

Discover what the server offers.

var tools = await client.ListToolsAsync();

foreach (var tool in tools.Tools)
{
    Console.WriteLine($"Tool: {tool.Name} - {tool.Description}");
}

🧩 Advanced Examples

Using Stdio with a Subprocess

using System.Diagnostics;
using Mcp.Gateway.Client;

// Start the MCP server process
var process = new Process
{
    StartInfo = new ProcessStartInfo
    {
        FileName = "dotnet",
        Arguments = "run --project MyMcpServer -- --stdio",
        RedirectStandardInput = true,
        RedirectStandardOutput = true,
        UseShellExecute = false
    }
};
process.Start();

// Connect via Stdio
await using var transport = new StdioMcpTransport(
    process.StandardOutput.BaseStream, 
    process.StandardInput.BaseStream
);

await using var client = new McpClient(transport);
await client.ConnectAsync();

// ... use client ...

📄 License

MIT

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.8.7 208 1/11/2026
1.8.6 134 1/10/2026
1.8.5 145 1/9/2026
1.8.4 152 1/9/2026
1.8.3 140 1/3/2026
1.8.2 143 1/3/2026
1.0.0 141 1/3/2026

v1.8.7: Resource API Refinements and Ping Compliance. BREAKING: Client ReadResourceAsync now returns ReadResourceResult. Added Client UnsubscribeResourceAsync. Moved system/ping to ping for spec compliance. Added resource metadata support.