afrise/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.

374 ★42 forksC#Updated 9mo ago

What you need to know

A .NET library for building MCP servers and clients — expose your .NET methods as MCP tools with simple attributes ([McpTool]), with Microsoft.Extensions.AI and Semantic Kernel integration. Requires .NET Standard 2.0.

Install

dotnet add package MCPSharp

Usage

  • Mark methods with [McpTool("name", "description")] and [McpParameter(true)] for required params
  • await MCPServer.StartAsync("CalculatorServer", "1.0.0"); // auto-discovers [McpTool] methods in base assembly
  • Register referenced-library classes: MCPServer.Register<T>(); // also works with Semantic Kernel KernelFunctionAttribute
  • Client use: MCPClient client = new("AI", "1.0", "path/to/server"); IList<AIFunction> fns = await client.GetFunctionsAsync();

Key features

  • Attribute-based API: [McpTool], [McpParameter], [McpResource] (name, uri with templates, mimeType)
  • Built-in JSON-RPC request/response handling, automatic parameter validation and type conversion
  • Microsoft.Extensions.AI integration (tools exposed as AIFunctions usable with any IChatClient) and Semantic Kernel support
  • Dynamic tool registration (MCPServer.AddToolHandler), tool change notifications to clients, complex object parameter support
  • XML documentation auto-extracted into tool docs (change names/descriptions without recompiling)

Best for

.NET/C# developers who want to expose existing methods as MCP endpoints or connect to MCP servers from C# code without dealing with protocol details.

Caveats

  • [McpFunction] is deprecated — use [McpTool]; MCPServer.RegisterTool<T>() deprecated in favor of MCPServer.Register<T>()
  • Semantic Kernel integration currently only via MCPServer.Register<T>() (no kernel-wide introspection)

Reviewed 2026-08-07

Topics

aiaifunctionsdotnetdotnet-standardmcpmcp-clientmcp-servermicrosoft-extensions-aimodel-context-protocolsdksemantic-kernel
View on GitHub ↗
Stars
374★
Forks
42
Language
C#
License
MIT
Created
2025-02-17
Last push
2025-10-20