Microsoft.Agents.Mcp.Server.AspNet
0.2.162-alpha
Prefix Reserved
dotnet add package Microsoft.Agents.Mcp.Server.AspNet --version 0.2.162-alpha
NuGet\Install-Package Microsoft.Agents.Mcp.Server.AspNet -Version 0.2.162-alpha
<PackageReference Include="Microsoft.Agents.Mcp.Server.AspNet" Version="0.2.162-alpha" />
<PackageVersion Include="Microsoft.Agents.Mcp.Server.AspNet" Version="0.2.162-alpha" />
<PackageReference Include="Microsoft.Agents.Mcp.Server.AspNet" />
paket add Microsoft.Agents.Mcp.Server.AspNet --version 0.2.162-alpha
#r "nuget: Microsoft.Agents.Mcp.Server.AspNet, 0.2.162-alpha"
#:package Microsoft.Agents.Mcp.Server.AspNet@0.2.162-alpha
#addin nuget:?package=Microsoft.Agents.Mcp.Server.AspNet&version=0.2.162-alpha&prerelease
#tool nuget:?package=Microsoft.Agents.Mcp.Server.AspNet&version=0.2.162-alpha&prerelease
Microsoft.Agents.Mcp.Server.AspNet
Overview
The Microsoft Agents MCP (Model Context Protocol) Transport Module provides robust communication transport mechanisms for distributed systems, supporting different communication paradigms and protocols.
Installation
Install the MCP Server SDK via NuGet:
dotnet add package Microsoft.Agents.Mcp.Server.AspNet
Key Features
- Multiple transport implementations
- Flexible message handling
- Support for various communication patterns
- Logging and error handling
- Cancellation and resource management
Transport Implementations
1. StdioServerTransport
Description
A transport mechanism using standard input/output streams for communication.
Key Characteristics
- Reads and writes messages using UTF-8 encoded streams
- Supports JSON-RPC payload processing
- Provides thread-safe message handling
- Implements
IDisposablefor proper resource management
Usage Example
var transport = new StdioServerTransport(inputStream, outputStream);
await transport.Connect(sessionId,
ingestMessage: ProcessIncomingMessage,
close: HandleTransportClosure);
2. HttpSseServerTransport
Description
A Server-Sent Events (SSE) based HTTP transport for real-time, server-to-client communication.
Key Characteristics
- Implements Server-Sent Events (SSE)
- Supports session-based communication
- Provides endpoint discovery
- Integrated with ASP.NET Core
- Comprehensive logging
- Supports graceful connection closure
Usage Example
var transport = new HttpSseServerTransport(
transportManager,
getMessageEndpoint,
httpResponse,
cancellationToken,
logger);
await transport.Connect(sessionId,
ingestMessage: ProcessIncomingMessage,
close: HandleTransportClosure);
3. HttpCallbackServerTransport
Description
A Bi-directional HTTP based transport for long-running, server-to-client communication, focussed on Server to Server application patterns
Key Characteristics
- Implements a Bi-directional HTTP (webhook) based protocol
- Supports long-running sessions
- Integrated with ASP.NET Core
- Comprehensive logging
- Supports graceful connection closure
Usage Example
var transport = new HttpSseServerTransport(
transportManager,
httpClientFactory,
callbackUri);
await transport.Connect(sessionId,
ingestMessage: ProcessIncomingMessage,
close: HandleTransportClosure);
Core Interfaces
IMcpTransport
The primary interface for transport implementations, defining core methods:
Connect: Establish a transport connectionSendOutgoingAsync: Send messages to the clientProcessPayloadAsync: Process incoming messagesCloseAsync: Close the transport connection
Serialization
Uses System.Text.Json with custom serialization options for consistent JSON handling across transports.
Error Handling and Logging
- Comprehensive logging using
Microsoft.Extensions.Logging - Detailed error tracking
- Graceful error and connection management
Configuration
Serialization Options
Custom serialization is managed through Serialization.GetDefaultMcpSerializationOptions(), which provides consistent JSON serialization across the module.
Best Practices
- Always use cancellation tokens
- Handle potential exceptions
- Properly dispose and close transport resources
Extensibility
The modular design allows for easy addition of new transport mechanisms by implementing the IMcpTransport interface.
License
This project is licensed under the MIT License�see the LICENSE file for details.
Sample Configuration
// Example configuration in ASP.NET Core startup
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddHttpClient();
builder.Services.AddModelContextProtocolHandlers();
builder.Services.AddDefaultOperationFactory();
builder.Services.AddDefaultPayloadExecutionFactory();
builder.Services.AddDefaultPayloadResolver();
builder.Services.AddDefaultServerExecutors();
builder.Services.AddMemorySessionManager();
builder.Services.AddTransportManager();
builder.Services.AddToolExecutor<MathAddOperationExecutor>();
builder.Services.AddToolExecutor<WeatherOperationExecutor>();
builder.Services.AddLogging();
builder.Logging.AddConsole();
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.0
- Microsoft.Agents.Mcp.Core (>= 0.2.162-alpha)
- Microsoft.Agents.Mcp.Server (>= 0.2.162-alpha)
- Microsoft.Extensions.Http (>= 8.0.0)
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 |
|---|