Microsoft.Agents.Mcp.Core
0.2.162-alpha
Prefix Reserved
dotnet add package Microsoft.Agents.Mcp.Core --version 0.2.162-alpha
NuGet\Install-Package Microsoft.Agents.Mcp.Core -Version 0.2.162-alpha
<PackageReference Include="Microsoft.Agents.Mcp.Core" Version="0.2.162-alpha" />
<PackageVersion Include="Microsoft.Agents.Mcp.Core" Version="0.2.162-alpha" />
<PackageReference Include="Microsoft.Agents.Mcp.Core" />
paket add Microsoft.Agents.Mcp.Core --version 0.2.162-alpha
#r "nuget: Microsoft.Agents.Mcp.Core, 0.2.162-alpha"
#:package Microsoft.Agents.Mcp.Core@0.2.162-alpha
#addin nuget:?package=Microsoft.Agents.Mcp.Core&version=0.2.162-alpha&prerelease
#tool nuget:?package=Microsoft.Agents.Mcp.Core&version=0.2.162-alpha&prerelease
Microsoft.Agents.Mcp.Core
Overview
The Microsoft Agents MCP (Model Context Protocol) Core Module provides a robust framework for handling JSON-RPC based communication, payload processing, and method invocation in a structured and type-safe manner.
Installation
Install the MCP Server SDK via NuGet:
dotnet add package Microsoft.Agents.Mcp.Core
Key Components
Payload Handlers
The module defines several abstract base classes for different types of payload handling:
McpPayloadHandlerBase
- Base interface for payload handlers
- Defines method for creating and executing payloads
McpMethodWithoutInputsPayloadHandlerBase
- Handles methods that don't require input parameters
- Provides a generic way to execute methods and post results
McpMethodPayloadHandlerBase
- Supports methods with specific request and (optionally) response types
- Handles JSON deserialization of method parameters
- Provides type-safe method execution
McpNotificationHandlerBase
- Handles notification-type payloads
- Supports deserialization of notification parameters
Payload Types
- McpRequest: Represents a method call with an ID and parameters
- McpNotification: Represents a notification without an ID
- McpResult: Represents the result of a method call
Serialization
The module uses System.Text.Json for payload serialization and deserialization, with custom serialization options defined in the Serialization utility class.
Example Usage
Creating a Method Handler
public class MyMethodHandler : McpMethodPayloadHandlerBase<MyRequestType, MyResponseType>
{
public override string Method => "my/method";
protected override async Task<MyResponseType> ExecuteMethodAsync(
IMcpContext context,
McpRequest<MyRequestType> payload,
CancellationToken ct)
{
// Implement method logic
var result = ProcessRequest(payload.Parameters);
return result;
}
}
Notification Handling
public class MyNotificationHandler : McpNotificationHandlerBase<MyNotificationType>
{
protected override async Task ExecuteAsync(
IMcpContext context,
McpNotification<MyNotificationType> payload,
CancellationToken ct)
{
// Handle notification
await ProcessNotification(payload.Parameters);
}
}
Key Features
- Type-safe payload handling
- JSON-RPC method and notification support
- Flexible serialization
- Cancellation token support
- Context-based execution
Dependencies
- Microsoft.Extensions.DependencyInjection
Logging and Transport
The module provides basic infrastructure for:
- Log level configuration
- Method and notification dispatching
- Serialization and deserialization of payloads
Best Practices
- Always use the appropriate base handler for your method type
- Implement proper error handling in your method implementations
- Utilize cancellation tokens for long-running operations
- Follow the existing serialization patterns
License
This project is licensed under the MIT License�see the LICENSE file for details.
Support
For issues and questions, please open a GitHub issue in the project repository.
| 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.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 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 |
|---|