Get the FREE Ultimate OpenClaw Setup Guide →

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.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
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:

  1. Create a new .NET project (console, web, or worker) where your MCP server will run: dotnet new console -n MyMcpServer cd MyMcpServer

  2. Add the MCPSharp package from NuGet: dotnet add package MCPSharp

  3. 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"); } }

  4. 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

Sponsor this space

Reach thousands of developers