AI助手协议实现

SpendPlan的模型上下文协议实现,使AI助手能够通过标准化的MCP工具与SpendPlan API交互。

  • by whiteflags26
  • C#
  • 本地部署
  • 更新于
在 GitHub 查看 whiteflags26/SpendPlanMCP

使用说明

SpendPlan MCP(模型上下文协议)

SpendPlan的模型上下文协议实现,使人工智能助手能够通过标准化MCP工具与SpendPlan API交互。

项目结构

该解决方案由两个主要项目组成:

  • 支出计划。MCP。客户端 -使用Gemini和Contoso的具有AI聊天界面的Web客户端
  • 支出计划。MCP。服务器 -为SpendPlan API操作提供工具的MCP服务器

安装说明

项目安置

放置 SpendPlan.MCP.Client 和 SpendPlan.MCP.Server 同一目录中的文件夹(不是根目录) src SpendPlan后端项目的文件夹。

预期结构:

src/
├── SpendPlan.API
├── SpendPlan.MCP.Client/
└── SpendPlan.MCP.Server/

运行完整应用程序

  1. 构建解决方案:

    dotnet build
    
  2. 运行Spend Plan。MCP。客户:

    cd SpendPlan.MCP.Client
    dotnet run
    
  3. 访问应用程序: 打开浏览器并导航到 https://localhost:44383

客户端将自动启动MCP服务器作为子进程。

使用带有外部MCP客户端的MCP服务器

如果您只想运行MCP服务器并将其与其他MCP客户端(如Claude Desktop、VS Code Copilot等)连接:

配置

  1. 创建 .vscode/mcp.json 在您的工作区根目录中:
{
  "mcpServers": {
    "spendplan": {
      "command": "dotnet",
      "args": ["run", "--project", "src/SpendPlan.MCP.Server/SpendPlan.MCP.Server.csproj"],
      "cwd": "src/SpendPlan.MCP.Server"
    }
  }
}
  1. 在中配置身份验证 appsettings.json:

更新 SpendPlan.MCP.Server/appsettings.json:

{
  "SpendPlanApi": {
    "BaseUrl": "https://localhost:7254/api/v1",
    "Mode": "apikey",
    "ApiKey": "your-jwt-bearer-token-here"
  }
}

身份验证模式:

  • "authenticate" -使用Auth0 OAuth2/JWT令牌流(web客户端的默认值)
  • "apikey" -在API密钥头中使用JWT承载令牌(建议用于外部MCP客户端)

使用MCP客户端运行

配置后,您的MCP客户端(VS Code Copilot、Claude Desktop等)将自动检测并连接到SpendPlan MCP服务器。

配置文件

客户端配置(SpendPlan.MCP.Client/appsettings.json)

看 appsettings.README.md 在客户端项目中查看详细的配置选项:

  • Gemini API设置
  • Auth0身份验证
  • MCP服务器连接设置

服务器配置(SpendPlan.MCP.Server/appsettings.json)

看 appsettings.README.md 在Server项目中查看详细的配置选项:

  • SpendPlan API端点
  • 身份验证模式(authenticate/apikey)
  • JWT承载令牌配置

Auth0配置

客户端前端需要包含您的Auth0配置,以便身份验证正常工作。将以下内容(以及您自己的值)添加到 SpendPlan.MCP.Client/wwwroot/app.js --通常在应用程序初始化之前,位于文件顶部附近:

// Auth0 configuration - replace placeholders with your Auth0 values
const authConfig = {
  domain: "<YOUR_AUTH0_DOMAIN>",
  clientId: "<YOUR_CLIENT_ID>",
  audience: "<YOUR_API_AUDIENCE>", 
  redirectUri: ""
};