- Explore MCP Servers
- MCPServerExample
Mcpserverexample
What is Mcpserverexample
MCPServerExample is an official C# SDK for the Model Context Protocol (MCP), designed to enable .NET applications, services, and libraries to implement and interact with MCP clients and servers.
Use cases
Use cases for MCPServerExample include creating chatbots that leverage LLMs, developing data analysis tools that require contextual understanding, and building applications that need to interact with multiple data sources securely.
How to use
To use MCPServerExample, you need to add the ModelContextProtocol package to your .NET project using the command ‘dotnet add package ModelContextProtocol --prerelease’. Then, you can create an MCP server and register tools by following the provided example code.
Key features
Key features of MCPServerExample include support for the Model Context Protocol, the ability to register tools dynamically from the current assembly, and integration with .NET applications, enhancing interaction with Large Language Models (LLMs).
Where to use
MCPServerExample can be used in various fields that require integration with Large Language Models, such as AI development, data processing applications, and any .NET-based services that need to provide context to LLMs.
Clients Supporting MCP
The following are the main client software that supports the Model Context Protocol. Click the link to visit the official website for more information.
Overview
What is Mcpserverexample
MCPServerExample is an official C# SDK for the Model Context Protocol (MCP), designed to enable .NET applications, services, and libraries to implement and interact with MCP clients and servers.
Use cases
Use cases for MCPServerExample include creating chatbots that leverage LLMs, developing data analysis tools that require contextual understanding, and building applications that need to interact with multiple data sources securely.
How to use
To use MCPServerExample, you need to add the ModelContextProtocol package to your .NET project using the command ‘dotnet add package ModelContextProtocol --prerelease’. Then, you can create an MCP server and register tools by following the provided example code.
Key features
Key features of MCPServerExample include support for the Model Context Protocol, the ability to register tools dynamically from the current assembly, and integration with .NET applications, enhancing interaction with Large Language Models (LLMs).
Where to use
MCPServerExample can be used in various fields that require integration with Large Language Models, such as AI development, data processing applications, and any .NET-based services that need to provide context to LLMs.
Clients Supporting MCP
The following are the main client software that supports the Model Context Protocol. Click the link to visit the official website for more information.
Content
MCPServerExample
MCP C# SDK
The official C# SDK for the Model Context Protocol, enabling .NET applications, services, and libraries to implement and interact with MCP clients and servers. Please visit our API documentation for more details on available functionality.
[!NOTE]
This project is in preview; breaking changes can be introduced without prior notice.
About MCP
The Model Context Protocol (MCP) is an open protocol that standardizes how applications provide context to Large Language Models (LLMs). It enables secure integration between LLMs and various data sources and tools.
For more information about MCP:
Getting Started (Server)
Here is an example of how to create an MCP server and register all tools from the current application.
It includes a simple echo tool as an example (this is included in the same file here for easy of copy and paste, but it needn’t be in the same file…
the employed overload of WithTools examines the current assembly for classes with the McpServerToolType attribute, and registers all methods with the
McpTool attribute as tools.)
dotnet add package ModelContextProtocol --prerelease dotnet add package Microsoft.Extensions.Hosting
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using ModelContextProtocol.Server;
using System.ComponentModel;
var builder = Host.CreateApplicationBuilder(args);
builder.Logging.AddConsole(consoleLogOptions =>
{
// Configure all logs to go to stderr
consoleLogOptions.LogToStandardErrorThreshold = LogLevel.Trace;
});
builder.Services
.AddMcpServer()
.WithStdioServerTransport()
.WithToolsFromAssembly();
await builder.Build().RunAsync();
[McpServerToolType]
public static class EchoTool
{
[McpServerTool, Description("Echoes the message back to the client.")]
public static string Echo(string message) => $"hello {message}";
}
Visual Studio Code Screenshots
Dev Tools Supporting MCP
The following are the main code editors that support the Model Context Protocol. Click the link to visit the official website for more information.










