ModelContextProtocol.NET.Server 0.1.0-alpha

This is a prerelease version of ModelContextProtocol.NET.Server.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package ModelContextProtocol.NET.Server --version 0.1.0-alpha                
NuGet\Install-Package ModelContextProtocol.NET.Server -Version 0.1.0-alpha                
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="ModelContextProtocol.NET.Server" Version="0.1.0-alpha" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ModelContextProtocol.NET.Server --version 0.1.0-alpha                
#r "nuget: ModelContextProtocol.NET.Server, 0.1.0-alpha"                
#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.
// Install ModelContextProtocol.NET.Server as a Cake Addin
#addin nuget:?package=ModelContextProtocol.NET.Server&version=0.1.0-alpha&prerelease

// Install ModelContextProtocol.NET.Server as a Cake Tool
#tool nuget:?package=ModelContextProtocol.NET.Server&version=0.1.0-alpha&prerelease                

ModelContextProtocol.NET

A C# SDK implementation of the Model Context Protocol (MCP), enabling seamless integration between AI models and development environments.

Overview

ModelContextProtocol.NET is a native .NET implementation of the Model Context Protocol, designed to facilitate communication between AI models and development environments. This SDK provides a robust foundation for building AI-powered tools and applications in the .NET ecosystem.

Features

Ready to Use

  • ✅ Standard I/O Communication
  • ✅ Tool Integration Framework
  • ✅ Native AOT Compatible
  • ✅ Calculator Demo Implementation

Under Development

  • 🚧 WebSocket Support
  • 🚧 Resource Management
  • 🚧 Prompt System

Demo

The repository includes a fully functional calculator demo that showcases the basic capabilities of the MCP implementation. This demo serves as a practical example of how to integrate and use the protocol in your applications.

Technical Details

Architecture

The project is structured into multiple components:

  • Core Library: Contains the fundamental protocol implementation
  • Server Components: Handles communication and request processing
  • Demo Implementation: Provides a working example with a calculator application

Key Benefits

  • Native AOT Support: Fully compatible with .NET Native AOT compilation for optimal performance
  • Modular Design: Clean separation of concerns allowing for flexible implementation
  • Standard Compliance: Implements the Model Context Protocol specification

Getting Started

The easiest way to get started is to look at the calculator demo in src/ModelContextProtocol.NET.Demo.Calculator. Here's a quick example of how to set up an MCP server:

// Create server info
var serverInfo = new Implementation { Name = "Calculator Demo Server", Version = "1.0.0" };

// Configure and build server
var server = new McpServerBuilder(serverInfo)
    .AddStdioTransport()
    // see below for logging configuration
    .ConfigureLogging(logging => ...)
    .ConfigureTools(tools => tools.AddHandler<CalculatorToolHandler>())
    .Build();

// Start the server
server.Start();

Logging Configuration

McpServerBuilder uses Microsoft.Extensions.Logging.ILogger as the logging interface. Since stdio transport is used, logs can't be sent to the console. You need to configure a logging provider that can write to a file or other logging destination.

If no logging provider is configured, a null logger will be used, resulting in no logs being written.

// Using Serilog
.ConfigureLogging(logging => logging.AddSerilog(yourSerilogLogger))

// Using NLog
.ConfigureLogging(logging => logging.AddNLog())

Implementing Tools

Tools are implemented as handlers. Here's a simplified example from the calculator demo:

public class CalculatorParameters
{
    public required CalculatorOperation Operation { get; init; }
    public required double A { get; init; }
    public required double B { get; init; }
}

public enum CalculatorOperation { Add, Subtract, Multiply, Divide }

Check out the complete calculator demo for a full working example including:

  • Tool handler implementation
  • Request/response handling
  • Error management
  • Logging setup

More documentation and implementation guide coming soon.

Development Status

This project is under active development. While core features like stdio communication and tool integration are complete and usable, some advanced features are still being implemented.

Contributing

Contributions are welcome! Please feel free to submit pull requests or create issues for bugs and feature requests.

License

Apache 2.0

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ModelContextProtocol.NET.Server:

Package Downloads
ModelContextProtocol.NET.Server.Hosting

Hosting extensions for the Model Context Protocol (MCP) Server

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.3.2-alpha 48 1/25/2025
0.3.1-alpha 38 1/18/2025
0.1.0-alpha 54 12/18/2024