MCP Catalogs
Home

MCPSharp

by afrise·369·Score 47

MCPSharp is a .NET library for building MCP servers and clients with tools, resources, and prompts.

developer-toolsai-llm
43
Forks
12
Open issues
7 mo ago
Last commit
2d ago
Indexed

Overview

MCPSharp is a comprehensive .NET implementation of the Model Context Protocol, providing developers with tools to create both MCP servers and clients. It offers attribute-based APIs that simplify exposing .NET methods as MCP tools and resources, handling JSON-RPC communication seamlessly behind the scenes. The library supports Microsoft.Extensions.AI integration and Semantic Kernel, making it versatile for different AI application scenarios.

Try asking AI

After installing, here are 5 things you can ask your AI assistant:

you:Building MCP-compliant APIs for AI assistants like Claude Desktop
you:Exposing existing .NET code as MCP endpoints with minimal configuration
you:Integrating with Microsoft.Extensions.AI and Semantic Kernel ecosystems
you:What's the difference between [McpTool] and [McpFunction]?
you:Can I use MCPSharp with Microsoft.Extensions.AI?

When to choose this

Teams working in .NET environments who need to expose existing .NET code as MCP tools without implementing protocol details.

When NOT to choose this

If you're not working in .NET ecosystems or need advanced MCP features not yet supported by MCPSharp.

Tools this server exposes

3 tools extracted from the README
  • addint Add(int a, int b)

    Adds two numbers together

  • dynamicToolstring dynamicTool(string input)

    A dynamic tool that processes input

  • MyFunctionstring MyFunction(string input)

    Processes input string

Comparable tools

mcp-jsmcp-pythonmcp-server-template

Installation

Installation

dotnet add package MCPSharp

Quick Start

using MCPSharp;

public class Calculator
{
    [McpTool("add", "Adds two numbers")]
    public static int Add([McpParameter(true)] int a, [McpParameter(true)] int b)
    {
        return a + b;
    }
}

await MCPServer.StartAsync("CalculatorServer", "1.0.0");

Claude Desktop Configuration

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "mcpsharp-example": {
      "command": "dotnet",
      "args": ["run", "--project", "/path/to/your/project.csproj"],
      "env": {}
    }
  }
}

FAQ

What's the difference between [McpTool] and [McpFunction]?
[McpFunction] is deprecated and replaced with [McpTool] for better alignment with MCP standards. You should use [McpTool] for all new implementations.
Can I use MCPSharp with Microsoft.Extensions.AI?
Yes, MCPSharp integrates with Microsoft.Extensions.AI, allowing tools to be exposed as AIFunctions. You can use the MCPClient.GetFunctionsAsync() method to retrieve tools as AIFunctions.

Compare MCPSharp with

GitHub →

Last updated · Auto-generated from public README + GitHub signals.