OAuth 2.1认证演示

一个展示如何使用ASP.NET Core和Duende IdentityServer为Model Context Protocol (MCP)服务器实现OAuth 2.1认证的演示项目。

  • by 1saeedsalehi
  • C#
  • 本地部署
  • 更新于
在 GitHub 查看 1saeedsalehi/mcp-auth-demo

使用说明

MCP身份验证演示

一个演示项目,展示了如何使用ASP.NET为模型上下文协议(MCP)服务器实现OAuth 2.1身份验证。NET核心和Duende身份服务器。

概述

此项目演示了MCP服务器的完整身份验证流程,包括:

  • 身份服务器:OAuth 2.1/OpenID使用Duende IdentityServer连接授权服务器
  • 受保护的MCP服务器:具有JWT承载令牌身份验证的MCP服务器,暴露了数学工具(加法、乘法)
  • 用于客户端发现的OAuth资源元数据
  • 与VS代码和游标IDE集成

建筑

┌─────────────────┐         ┌──────────────────┐         ┌─────────────────┐
│   VS Code /     │────────>│  IdentityServer  │────────>│  Protected MCP  │
│     Cursor      │  Auth   │  (OAuth Server)  │  Token  │     Server      │
│     Client      │<────────│  Port: 5001      │<────────│  Port: 3007     │
└─────────────────┘         └──────────────────┘         └─────────────────┘

在VS代码/光标中配置

将以下配置添加到MCP设置文件中:

对于VS代码:

  • 打开设置: Ctrl+Shift+P (Windows/Linux)或 Cmd+Shift+P (Mac)
  • 搜索“MCP设置”或编辑 settings.json

对于光标:

  • 转到“设置”→ MCP设置
  • 或编辑 ~/.cursor/mcp.json (Mac/Linux)或 %APPDATA%\Cursor\mcp.json (Windows)

添加此配置:

{
  "mcpServers": {
    "my-mcp-server-test-saeed5": {
      "type": "http",
      "url": "http://localhost:3007"
    }
  }
}