模型上下文协议服务器

一个基础的.NET 10 MCP(模型上下文协议)服务器,用于向AI助手如Claude Desktop、Cursor和VS Code Continue等提供工具支持。

  • by jamiemaguiredotnet
  • C#
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 jamiemaguiredotnet/McpServerDemo

使用说明

MCP服务器演示

光秃秃的。NET 10 MCP(模型上下文协议)服务器,演示如何为人工智能助手公开工具,如Claude Desktop、Cursor和VS Code Continue。

先决条件

  • .NET 10 SDK
  • Node.js(用于MCP检查器测试)

运行服务器

cd src/McpServerDemo.WebApi
dotnet run

服务器将于启动 http://localhost:5125 SSE端点位于 http://localhost:5125/sse.

测试

选项1:MCP检查器(浏览器)

npx @modelcontextprotocol/inspector

打开 http://localhost:6274 并连接到 http://localhost:5125/sse.

选项2:MCP资源管理器(Windows)

下载自 https://mcp-explorer.com 并连接到 http://localhost:5125/sse.

客户端配置

克劳德桌面版

编辑 %APPDATA%\Claude\claude_desktop_config.json:

{
  "mcpServers": {
    "demo-docs": {
      "command": "npx",
      "args": ["mcp-remote", "http://localhost:5125/sse"]
    }
  }
}

光标

在设置中→ MCP:

{
  "mcpServers": {
    "demo-docs": {
      "url": "http://localhost:5125/sse",
      "transport": "sse"
    }
  }
}

VS代码继续

创建 ~/.continue/mcpServers/demo-docs.yaml:

name: Demo Docs
version: 0.0.1
schema: v1
mcpServers:
  - name: demo-docs
    type: sse
    url: http://localhost:5125/sse

项目结构

McpServerDemo/
├── McpServerDemo.sln
└── src/
    └── McpServerDemo.WebApi/
        ├── Program.cs              # MCP server configuration
        ├── Tools/
        │   └── SearchDocs.cs       # MCP tool implementation
        ├── Services/
        │   ├── IDocumentSearchService.cs
        │   ├── DocumentSearchService.cs
        │   ├── ILlmService.cs
        │   └── LlmService.cs
        └── Properties/
            └── launchSettings.json

延伸

要添加更多工具,请在 Tools 文件夹与 [McpServerToolType] 装饰的属性和方法 [McpServerTool].

[McpServerToolType]
public class MyNewTool
{
    [McpServerTool]
    [Description("Does something useful")]
    public async Task<string> DoSomething(
        [Description("Input parameter")] string input)
    {
        // Implementation
    }
}

许可证

麻省理工学院