Skip to content

Repository files navigation

DotNetCampus.ModelContextProtocol

.NET Build and Test NuGet NuGet NuGet

English 简体中文 繁體中文

A lightweight, zero-dependency yet full-featured MCP protocol implementation built with .NET. It can be easily integrated into your application, regardless of its architecture.

Features

  • 🚀 Lightweight and high-performance
  • 📦 Zero external dependencies
  • 🔌 Easy to integrate
  • 🎯 Full MCP protocol support

Getting Started

Installation

dotnet add package DotNetCampus.ModelContextProtocol

Quick Start

Server

var mcpServer = new McpServerBuilder("Sample Mcp Server", "1.0.0")
    .WithTools(tools => tools.WithTool(() => new SampleTools()))
    .WithLocalHostHttp(5943, "mcp")
    .Build();

await mcpServer.RunAsync();

public class SampleTools
{
    /// <summary>
    /// 原样返回输入文本。
    /// </summary>
    /// <param name="text">要原样返回的字符串</param>
    [McpServerTool(ReadOnly = true)]
    public string EchoTool(string text)
    {
        return text;
    }
}

Client

var client = new McpClientBuilder("Sample Mcp Client", "1.0.0")
    .WithHttp("http://localhost:5943/mcp")
    .Build();

var arguments = JsonSerializer.SerializeToElement(new { text = "Hello, MCP!" });
var result = await client.CallToolAsync("echo_tool", arguments);

Console.WriteLine(result.Content);

Documentation

See docs/en/README.md for the full documentation index.

Contributing

Contributions are welcome. Please feel free to submit a pull request.

License

This project is licensed under the MIT License. See LICENSE for details.

About dotnet-campus

dotnet-campus(.NET 职业技术学院)

About

A lightweight, zero-dependency yet full-featured MCP protocol implementation built with .NET. It can be easily integrated into your application, regardless of its architecture.

Topics

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages