Token导航 LogoToken导航TokenDH.com
Dot Net Campus MCP logo
AI代理未说明官方级别未说明来源级核验

Dot Net Campus MCP

MCP Server

一个轻量级、零依赖且功能完整的MCP协议实现,适用于任何架构的应用程序集成。

工具数

2

提示词数

0

GitHub Stars

4

资源数

0
轻量级C#高性能

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

dotnet-campus

提供方

dotnet-campus

最后核验

2026/5/17 20:22

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

DotNetCampus。模型上下文协议

一个轻量级、零依赖但功能齐全的MCP协议实现。网。它可以很容易地集成到您的应用程序中,而不管其架构如何。

特性

  • 🚀 轻质高性能
  • 📦 零外部依赖
  • 🔌 易于集成
  • 🎯 完全支持MCP协议

入门指南

安装

dotnet add package DotNetCampus.ModelContextProtocol

快速开始

典型的MCP服务器程序如下:

internal class Program
{
    private static async Task Main(string[] args)
    {
        // The server name and version will be sent to clients via the MCP protocol
        var mcpServer = new McpServerBuilder("Sample Server", "1.0.0")
            // If your MCP tool parameters and return values use custom types, you need to provide a JSON serialization context
            .WithJsonSerializer(McpToolJsonContext.Default)
            .WithTools(t => t
                // Register various MCP tools
                .WithTool(() => new SampleTools())
                .WithTool(() => new SampleTools2())
            )
            // Use Streamable HTTP transport, listening on http://localhost:5943/mcp
            // Also compatible with SSE, listening on http://localhost:5943/mcp/sse
            .WithLocalHostHttp(5943, "mcp")
            // You can also use stdio (standard input/output) transport, which is recommended by the MCP protocol for all MCP servers
            // However, it's generally not recommended to enable both http and stdio simultaneously,
            // as the former typically requires singleton execution while the latter must support multiple instances
            // .WithStdio()
            .Build();
#if DEBUG
        // Enable debug mode so that when the MCP server encounters exceptions, it returns exception information to clients for easier debugging
        // It's generally not recommended to enable this mode in production, as it would expose internal implementation details of the server
        mcpServer.EnableDebugMode();
#endif
        // Run the MCP server
        await mcpServer.RunAsync();
    }
}

[JsonSerializable(typeof(Foo))]
[JsonSerializable(typeof(Bar))]
[JsonSourceGenerationOptions(
    // Recommended: Most MCP protocol implementations use camelCase naming
    PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
    // Recommended: Most MCP protocol implementations use string enums
    UseStringEnumConverter = true,
    // Recommended: Cannot guarantee AI will always put metadata properties first
    AllowOutOfOrderMetadataProperties = true
    // If you plan to use less capable models, you can also enable the following options
    // PropertyNameCaseInsensitive = true,
    // NumberHandling = JsonNumberHandling.AllowReadingFromString
    )]
internal partial class McpToolJsonContext : JsonSerializerContext;

声明MCP工具方法

public class SampleTools
{
    /// 
    /// A tool for AI debugging that echoes back information as-is
    /// 
    /// 
The string to echo back

    /// The echoed string
    [McpServerTool(ReadOnly = true)]
    public string Echo(string text)
    {
        return text;
    }
}

高级用法

有关高级用法,包括支持的参数和返回值类型、类型多态性等,请参阅 快速入门指南

贡献

欢迎投稿!请随时提交拉取请求。

许可证

此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。

关于.net校园

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

目录标签

目录标签

轻量级C#高性能本地部署零依赖MCP协议.NET

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

2

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明none部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP