MyPlatform MCP服务器
  ](https://www.docker.com/)
MyPlatform的模型上下文协议(MCP)服务器实现,为AI代理提供对公司信息、绩效统计、图表生成和文件管理功能的结构化访问。
特性
- 模型上下文协议(MCP)支持:全面实施人工智能代理集成的MCP规范
- 公司信息工具:检索和导航公司/家族/产品层次结构
- 性能统计:查询和分析产品的性能指标
- 图表生成:使用自动颜色分配创建条形图、折线图和饼图
- 文件服务器集成:上传和管理包含元数据的文件
- ACL(访问控制列表):权限管理和验证
- JWT身份验证:可选的基于JWT的身份验证,支持Keycloak
- Docker就绪:使用Kubernetes健康探测器进行容器化部署
- AutoMapper集成:DTO和域模型之间的清晰分离
建筑
该解决方案遵循分层架构,实现了清晰的关注点分离:
MyPlatformMcpServer/
??? MyPlatform.Models/ # Domain models, interfaces, and business logic
??? MyPlatform.Infrastructure/ # Repository and external service implementations
??? MyPlatform.McpServer/ # MCP server, tools, DTOs, and API endpoints关键组件
- 服务层:具有域模型和服务接口的核心业务逻辑
- 数据层:数据访问的存储库模式实现
- MCP工具层:符合MCP的AI代理交互工具定义
- 基础设施层:外部服务客户端(ACL、文件服务器)
??入门
先决条件
- .NET 8 SDK
- 码头工人 (可选,用于容器化部署)
- MongoDB(用于持久性存储库)
安装
- 克隆存储库:
git clone https://github.com/demetrio-marra/MyPlatformMcpServer.git
cd MyPlatformMcpServer- 配置应用程序设置:
cd MyPlatform.McpServer
cp appsettings.json appsettings.Development.json- 更新
appsettings.Development.json根据您的配置:
{
"Jwt": {
"Issuer": "your-keycloak-issuer",
"Audience": "your-audience",
"Enabled": false
},
"AclConfiguration": {
"Endpoint": "https://your-acl-backend",
"ApiKeyHeaderName": "X-API-Key",
"ApiKeyValue": "your-api-key"
},
"FileServerConfiguration": {
"Endpoint": "https://your-file-server",
"ApiKeyHeaderName": "X-API-Key",
"ApiKeyValue": "your-api-key"
},
"PerformanceStatisticsRepository": {
"ConnectionString": "your-mongodb-connection-string"
},
"CompanyInfoRepository": {
"ConnectionString": "your-mongodb-connection-string"
}
}- 构建并运行:
dotnet build
dotnet run --project MyPlatform.McpServer服务器将于启动 http://localhost:5000 (或launchSettings.json中指定的端口)。
Docker部署
使用Docker构建和运行:
docker build -t myplatform-mcp-server -f MyPlatform.McpServer/Dockerfile .
docker run -p 8080:8080 myplatform-mcp-server或者与Kubernetes健康探测器一起使用:
- 存活探针:
GET /health/liveness - 准备就绪探针:
GET /health/readiness
??配置
JWT身份验证
为生产环境启用JWT身份验证:
{
"Jwt": {
"Issuer": "https://your-keycloak.com/realms/your-realm",
"Audience": "your-client-id",
"Enabled": true
}
}启用后,所有MCP端点都需要有效的JWT承载令牌。
日志记录
在中配置日志记录级别 appsettings.json:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"ModelContextProtocol": "Debug"
}
}
}MCP工具
服务器为AI代理提供以下MCP工具:
公司信息工具
MyPlatform_CompanyInfo_GetProductsHierarchy:检索扁平的公司/家族/产品层次结构MyPlatform_CompanyInfo_FindProductHierarchy:查找特定产品属于哪个公司和家族MyCompany_CompanyInfo_GetAllProductNames:列出所有可用的产品名称
统计工具
MyPlatform_Statistics_GetPerformanceStatistics:通过过滤和分组查询性能指标MyPlatform_Statistics_GetStatisticsRates:计算统计率和趋势MyPlatform_Statistics_GetStatistics:检索一般统计数据
图表工具
MyPlatform_Chart_GenerateChart:从数据生成条形图、折线图或饼图
- 支持自定义标题、轴标签和数据点 - 自动将生成的图表上传到文件服务器 - 返回文件元数据以供进一步使用
权限工具
MyPlatform_Permissions_GetMyPermissions:检索当前代理的权限
??发展
项目结构
MyPlatform.McpServer/
??? Configuration/ # Configuration classes (JWT, ACL, FileServer)
??? DTOs/ # Data Transfer Objects
??? Extensions/ # Extension methods
??? Mapping/ # AutoMapper profiles
??? Services/ # Application services
??? Tools/ # MCP tool implementations
? ??? Statistics/ # Statistics-related tools
??? Program.cs # Application entry point
??? appsettings.json # Configuration files添加新工具
- 在中创建新的工具类
Tools/目录 - 用…装饰
[McpServerToolType]属性 - 实施方法
[McpServerTool]属性 - 注册于
Program.cs:
builder.Services.AddMcpServer()
.WithHttpTransport()
.WithTools();编码指南
遵循中的指示 .github/copilot-instructions.md:
- 服务层:包含模型、接口和域异常
- 日志记录规则:
- 使用 LogInformation 公共服务方法的成功运作 - 使用 LogDebug 用于详细跟踪 - 使用 LogWarning 用于控制器中的域异常 - 使用 LogError 仅适用于未处理的异常
- 异常处理:服务层抛出域异常;控制器层处理它们
- 自动映射器:用于实体和DTO之间的映射
??测试
使用以下方式运行测试:
dotnet test依赖关系
关键的NuGet包:
- 模型上下文协议 (0.3.0-preview.4):MCP服务器实现
- 模型上下文协议。AspNetCore (0.3.0-preview.4):ASP。NET核心集成
- 自动映射器 (13.0.1):对象到对象映射
- 微软。AspNetCore。身份验证。JwtBearer:JWT身份验证
- 斯科特普劳:图表生成库
- MongoDB。驾驶员:MongoDB数据库访问
??贡献
欢迎投稿!请按照以下步骤操作:
- 克隆该仓库
- 创建要素分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m 'Add amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
请确保您的代码遵循项目的编码指南,并包含适当的测试。
??许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
??链接
??联系方式
如有疑问或支持,请在GitHub上发布问题。
______________________________________________________________________
用??使用。NET 8与模型上下文协议
