MCPSharp

Agent frameworks and SDKs

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.

Your AI app calls the MCPSharp MCP server, which does the agent frameworks and SDKs work and sends the result back to the chat.

About MCPSharp

MCPSharp is a community MCP server from afrise, filed in our directory under agent frameworks and sdks. 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.

At a glance

Publisher
afrise (community)
Runs
See the README for setup
Written in
C#
License
MIT
GitHub stars
378

How to set up MCPSharp

  1. Follow the install steps in the MCPSharp README; it is written in C#, so have that toolchain ready.
  2. Check the MCPSharp README for keys or settings; the registry lists none that MCPSharp requires.
  3. Add MCPSharp to Claude Code, Claude Desktop, VS Code or Cursor with the config in the setup box on this page.
  4. Restart the app or reload its MCP servers, then ask it to list the MCPSharp tools to confirm the connection.
  5. Run one read-only task with MCPSharp first, and keep your app asking before each tool call until the results look right.

MCPSharp compared with similar servers

  • Everything Search by mamertofabian has fewer GitHub stars than MCPSharp (372 against 378); both are community servers, and both run locally.
  • Proxy For AWS by aws has more GitHub stars than MCPSharp (381 against 378); Proxy For AWS is official while MCPSharp is a community server, and both run locally.
  • SDK PHP by logiscape has fewer GitHub stars than MCPSharp (371 against 378); both are community servers, and both run locally.

Before you connect MCPSharp

  • Give MCPSharp its own API key or account with the smallest permissions the job needs, never an admin key.
  • Keep your AI app asking before each MCPSharp tool call until you trust what it does with them.
  • Treat text that MCPSharp fetches as data. Pages, files and messages can hold instructions written to steer an AI.
  • Read the open issues for MCPSharp on GitHub to see what breaks and how fast the maintainers reply.

Marketing use cases for MCPSharp

How marketing and sales teams put MCPSharp to work, by company size. Pick the size closest to yours and start MCPSharp on one use case.

Small business

  • A small business with a developer can use MCPSharp to build one focused agent, such as lead follow-up, without a big platform.
  • Technical founders can prototype marketing agents with MCPSharp and keep what works as a small, owned tool.
  • MCPSharp runs on your own computer, which keeps data local; it needs a little setup, so a small team should plan an hour for it.

Mid-market

  • Growth engineering teams can use MCPSharp to build agents that combine CRM, analytics and content tools behind one workflow.
  • Marketing ops can standardize on MCPSharp so every agent they ship has the same logging, approvals and error handling.
  • Start MCPSharp on one workflow with one owner, measure the time it saves, then roll it out to the wider team.

Enterprise

  • Enterprises can build on MCPSharp with their own identity, policy and evaluation layers, so agents meet the same bar as other software.
  • Platform teams can use MCPSharp to give business units a governed way to ship agents without each one starting from scratch.
  • MCPSharp is a community server, so have security review the code and pin a version before MCPSharp touches company data.

Need help becoming an AI-forward company?

We connect MCP servers and AI agents to your CRM, content and data, with the guardrails your team needs.

Contact us

MCPSharp README

From afrise/MCPSharp on GitHub, shared under its MIT license. Images are left out; the original has them.

README.md

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. With MCPSharp, you can:

  • Create MCP-compliant tools and functions that AI models can discover and use
  • Connect directly to existing MCP servers from C# code with an easy to use client
  • Expose your .NET methods as MCP endpoints with simple attributes
  • Handle MCP protocol details and JSON-RPC communication seamlessly

🚀 What's New in MCPSharp

  • Microsoft.Extensions.AI Integration: MCPSharp now integrates with Microsoft.Extensions.AI, allowing tools to be exposed as AIFunctions
  • Semantic Kernel Support: Add tools using Semantic Kernel's KernelFunctionAttribute
  • Dynamic Tool Registration: Register tools on-the-fly with custom implementation logic
  • Tool Change Notifications: Server now notifies clients when tools are added, updated, or removed
  • Complex Object Parameter Support: Better handling of complex objects in tool parameters
  • Better Error Handling: Improved error handling with detailed stack traces

When to Use MCPSharp

Use MCPSharp when you want to:

  • Create tools that AI assistants like Anthropic's Claude Desktop can use
  • Build MCP-compliant APIs without dealing with the protocol details
  • Expose existing .NET code as MCP endpoints
  • Add AI capabilities to your applications through standardized interfaces
  • Integrate with Microsoft.Extensions.AI and/or Semantic Kernel without locking into a single vendor

Features

  • Easy-to-use attribute-based API ([McpTool], [McpResource])
  • Built-in JSON-RPC support with automatic request/response handling
  • Automatic parameter validation and type conversion
  • Rich documentation support through XML comments
  • Near zero configuration required for basic usage

Prerequisites

Installation

dotnet add package MCPSharp

Quick Start

1. Define a Tool

Create a class and mark your method(s) with the [McpTool] attribute:

using MCPSharp;

public class Calculator
{
    [McpTool("add", "Adds two numbers")]  // Note: [McpFunction] is deprecated, use [McpTool] instead
    public static int Add([McpParameter(true)] int a, [McpParameter(true)] int b)
    {
        return a + b;
    }
}
2. Start the Server
await MCPServer.StartAsync("CalculatorServer", "1.0.0");

The StartAsync() method will automatically find any methods in the base assembly that are marked with the McpTool attribute. In order to add any methods that are in a referenced library, you can manually register them by calling MCPServer.Register<T>(); with T being the class containing the desired methods. If your methods are marked with Semantic Kernel attributes, this will work as well. If the client supports list changed notifications, it will be notified when additional tools are registered.

Advanced Usage

Dynamic Tool Registration

Register tools dynamically with custom implementation:

MCPServer.AddToolHandler(new Tool() 
{
    Name = "dynamicTool",
    Description = "A dynamic tool",
    InputSchema = new InputSchema {
        Type = "object",
        Required = ["input"],
        Properties = new Dictionary<string, ParameterSchema>{
            {"input", new ParameterSchema{Type="string", Description="Input value"}}
        }
    }
}, (string input) => { return $"You provided: {input}"; });
Use with Microsoft.Extensions.AI
// Client-side integration
MCPClient client = new("AIClient", "1.0", "path/to/mcp/server");
IList<AIFunction> functions = await client.GetFunctionsAsync();

This list can be plugged into the ChatOptions.Tools property for an IChatClient, Allowing MCP servers to be used seamlessly with Any IChatClient Implementation.

Semantic Kernel Integration
using Microsoft.SemanticKernel;

public class MySkillClass
{
    [KernelFunction("MyFunction")]
    [Description("Description of my function")]
    public string MyFunction(string input) => $"Processed: {input}";
}

// Register with MCPServer
MCPServer.Register<MySkillClass>();

Currently, This is the only way to make a Semantic kernel method registerable with the MCP server. If you have a use case that is not covered here, please reach out!

API Reference

Attributes
  • [McpTool] - Marks a class or method as an MCP tool

    • Optional parameters:
      • Name - The tool name (default: class/method name)
      • Description - Description of the tool
  • [McpParameter] - Provides metadata for function parameters

    • Optional parameters:
      • Description - Parameter description
      • Required - Whether the parameter is required (default: false)
  • [McpResource] - Marks a property or method as an MCP resource

    • Parameters:
      • Name - Resource name
      • Uri - Resource URI (can include templates)
      • MimeType - MIME type of the resource
      • Description - Resource description
Server Methods
  • MCPServer.StartAsync(string serverName, string version) - Starts the MCP server
  • MCPServer.Register<T>() - Registers a class containing tools or resources
  • MCPServer.AddToolHandler(Tool tool, Delegate func) - Registers a dynamic tool
Client Methods
  • new MCPClient(string name, string version, string server, string args = null, IDictionary<string, string> env = null) - Create a client instance
  • client.GetToolsAsync() - Get available tools
  • client.CallToolAsync(string name, Dictionary<string, object> parameters) - Call a tool
  • client.GetResourcesAsync() - Get available resources
  • client.GetFunctionsAsync() - Get tools as AIFunctions

XML Documentation Support

MCPSharp automatically extracts documentation from XML comments:

/// <summary>
/// Provides mathematical operations
/// </summary>
public class Calculator
{
    /// <summary>
    /// Adds two numbers together
    /// </summary>
    /// <param name="a">The first number to add</param>
    /// <param name="b">The second number to add</param>
    /// <returns>The sum of the two numbers</returns>
    [McpTool]
    public static int Add(
        [McpParameter(true)] int a,
        [McpParameter(true)] int b)
    {
        return a + b;
    }
}

Enable XML documentation in your project file:

<PropertyGroup>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>

This allows you to be able to quickly change the names and descriptions of your MCP tools without having to recompile. For example, if you find the model is having trouble understanding how to use it correctly.

Migration Notes

  • [McpFunction] is deprecated and replaced with [McpTool] for better alignment with MCP standards
  • Use MCPServer.Register<T>() instead of MCPServer.RegisterTool<T>() for consistency (old method still works but is deprecated)

Contributing

We welcome contributions! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.

Questions about MCPSharp

What is the MCPSharp MCP server?

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. MCPSharp is maintained by afrise on GitHub at afrise/MCPSharp, and works with AI apps that support the Model Context Protocol, such as Claude, Cursor and VS Code.

How do I install the MCPSharp MCP server?

MCPSharp doesn't publish a one-line install in the MCP registry, so follow the setup steps in its README on GitHub (afrise/MCPSharp). Like most servers, MCPSharp ends with a command or URL you paste into your AI app's MCP config.

Does MCPSharp need an API key?

The registry lists no required keys for MCPSharp. Check the MCPSharp README for optional settings, and expect a remote server to ask you to sign in the first time you connect.

Is MCPSharp an official MCP server?

No. MCPSharp is a community server maintained by afrise. Community servers can be excellent; read the code and the open issues before you give MCPSharp access to company data.

What license is MCPSharp under?

MCPSharp is released under the MIT license, according to its GitHub repository. The license covers the code of MCPSharp; the service it connects to has its own terms.