MCPSharp
by afrise·★ 369·综合分 47
MCPSharp 是一个用于构建 MCP 服务器和客户端的 .NET 库。
developer-toolsai-llm
43
Forks
12
活跃 Issue
7 个月前
最近提交
2 天前
收录于
概述
MCPSharp 是 Model Context Protocol 的完整 .NET 实现,为开发人员提供了构建 MCP 服务器和客户端的工具。它提供基于属性的 API,简化了将 .NET 方法作为 MCP 工具和资源暴露的过程,在后台无缝处理 JSON-RPC 通信。该库支持 Microsoft.Extensions.AI 集成和 Semantic Kernel,适用于不同的 AI 应用场景。
试试问 AI
装完之后,这里有 5 个你可以让 AI 做的事:
你:为 Claude Desktop 等 AI 助手构建兼容 MCP 的 API
你:将现有 .NET 代码作为 MCP 端点暴露,只需最少的配置
你:与 Microsoft.Extensions.AI 和 Semantic Kernel 生态系统集成
你:[McpTool] 和 [McpFunction] 有什么区别?
你:我可以将 MCPSharp 与 Microsoft.Extensions.AI 一起使用吗?
什么时候选它
在 .NET 环境中工作,需要将现有 .NET 代码作为 MCP 工具暴露而不实现协议细节的团队。
什么时候不要选它
如果您不在 .NET 生态系统中工作,或需要 MCPSharp 尚不支持的高级 MCP 功能。
此 server 暴露的工具
从 README 抽取出 3 个工具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
可对比工具
mcp-jsmcp-pythonmcp-server-template
安装
安装
dotnet add package MCPSharp快速开始
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 配置
添加到 claude_desktop_config.json:
{
"mcpServers": {
"mcpsharp-example": {
"command": "dotnet",
"args": ["run", "--project", "/path/to/your/project.csproj"],
"env": {}
}
}
}FAQ
- [McpTool] 和 [McpFunction] 有什么区别?
- [McpFunction] 已被弃用,并由 [McpTool] 取代,以便更好地与 MCP 标准保持一致。您应该在所有新实现中使用 [McpTool]。
- 我可以将 MCPSharp 与 Microsoft.Extensions.AI 一起使用吗?
- 是的,MCPSharp 与 Microsoft.Extensions.AI 集成,允许将工具作为 AIFunctions 暴露。您可以使用 MCPClient.GetFunctionsAsync() 方法将检索到的工具作为 AIFunctions 使用。
MCPSharp 对比
最后更新于 · 由 README + GitHub 公开数据自动生成。