MCPSharp
MCPSharp is a .NET library that helps you build Model Context Protocol (MCP) servers and clients - the standardized API protocol used by AI assistants and models.
claude mcp add --transport stdio afrise-mcpsharp docker run -i afrise/mcpsharp
How to use
MCPSharp is a .NET library that helps you build MCP (Model Context Protocol) servers and clients. It provides attribute-based tooling to expose your .NET methods as MCP endpoints, automatic JSON-RPC handling, and client utilities to discover and invoke these tools. With MCPSharp you can integrate your existing C# codebases into MCP ecosystems, enable AI assistants to discover and call your tools, and optionally connect with semantic kernel or Microsoft.Extensions.AI for richer tool usage. To use it, create your server project, annotate methods with [McpTool] (and optionally [McpParameter] and [McpResource]), then start the MCP server using the provided API. On the client side, you can construct an MCPClient to query available tools, call them with parameters, or retrieve them as AIFunctions for use with AI chains.
How to install
Prerequisites:
- .NET 6.0+ SDK or newer installed on your development machine
- Basic familiarity with NuGet package management
Step-by-step installation:
-
Create a new .NET project (console, web, or worker) where your MCP server will run: dotnet new console -n MyMcpServer cd MyMcpServer
-
Add the MCPSharp package from NuGet: dotnet add package MCPSharp
-
Build and run your server code. Example minimal usage (in your Program.cs): using MCPSharp;
// Define your tools as methods with [McpTool] public class Calculator { [McpTool("add", "Adds two numbers")] public static int Add([McpParameter(true)] int a, [McpParameter(true)] int b) => a + b; }
public class Program { public static async Task Main(string[] args) { // Start the MCP server (example usage) await MCPServer.StartAsync("CalculatorServer", "1.0.0"); } }
-
Run the project: dotnet run
Note: The MCPSharp library will scan for methods annotated with [McpTool] in the loaded assemblies and expose them as MCP endpoints. You can also register tool classes explicitly with MCPServer.Register<T>().
Additional notes
Tips and common considerations:
- Ensure your project targets a .NET version compatible with MCPSharp (as noted, .NET Standard 2.0 compatibility is mentioned for prerequisites).
- Use XML documentation comments to enrich tool descriptions; enable XML docs in your project file to automatically include descriptions in MCP tooling metadata.
- If you need dynamic tool registration, MCPServer.AddToolHandler allows adding tools at runtime with custom input schemas.
- When integrating with Microsoft.Extensions.AI or Semantic Kernel, tools can be surfaced as AIFunctions or Kernel functions, enabling seamless use from AI workflows.
- If you later update tool definitions, the server can notify clients of tool changes via change notifications when supported by the client.
- This documentation assumes a library-first approach; the MCPSharp project is designed to be embedded into your own host applications rather than as a standalone executable server.
Related MCP Servers
mcp-language
mcp-language-server gives MCP enabled clients access semantic tools like get definition, references, rename, and diagnostics.
Remote
A type-safe solution to remote MCP communication, enabling effortless integration for centralized management of Model Context.
mcp-typescript-sdk
A TypeScript SDK for implementing Model Context Protocol (MCP) over MQTT, supporting both browser and Node.js environments.
pluggedin-app
The Crossroads for AI Data Exchanges. A unified, self-hostable web interface for discovering, configuring, and managing Model Context Protocol (MCP) servers—bringing together AI tools, workspaces, prompts, and logs from multiple MCP sources (Claude, Cursor, etc.) under one roof.
mcp-framework
Rust MCP framework for building AI agents
mcp
Official MCP server for Paper's trading platform - enables AI assistants to interact with Paper's API