Avro MCP 服务编排器
一个模型上下文协议(MCP)服务器编排器,用于管理和将请求路由到其他MCP服务器。此服务允许您注册多个MCP服务器,并在它们之间协调调用,提供集中化的管理和发现功能。
特点/特性
- 服务器注册注册并管理多个MCP服务器
- 请求转发将MCP调用转发到已注册的服务器
- 工具发现发现所有已注册服务器上的可用工具
- 健康监测监控已注册服务器的健康状态
- 多租户支持处理租户特定的路由和隔离
- RESTful API(Representational State Transfer(表述性状态转移)应用程序编程接口)用于管理操作的标准REST端点
- MCP协议原生MCP服务器功能,支持HTTP传输
快速入门
1. 构建并运行
cd src/Avro.Mcp.Orchestrator
dotnet restore
dotnet build
dotnet run调度器将开始运行 https://localhost:7234 (或类似表述)。
2. 注册MCP服务器
将您的MCP服务器注册到编排器中:
curl -X POST "https://localhost:7234/servers/register" \
-H "Content-Type: application/json" \
-d '{
"name": "users-service",
"description": "User management MCP server",
"baseUrl": "https://localhost:7001",
"version": "1.0.0",
"capabilities": ["tools", "resources"],
"metadata": {
"category": "user-management"
}
}'3. 发现可用工具
获取所有已注册服务器上的可用工具:
curl -X POST "https://localhost:7234/forward/tools/discover" \
-H "Content-Type: application/json" \
-d '{
"searchTerm": "user",
"category": "management"
}'4. 转发MCP调用
将MCP方法调用转发到已注册的服务器:
curl -X POST "https://localhost:7234/forward" \
-H "Content-Type: application/json" \
-d '{
"serverId": "your-server-id",
"method": "get_paged_list_users",
"parameters": {
"page": 1,
"pageSize": 20
},
"tenantId": "tenant-123"
}'API终端点
服务器管理
| 方法 | 结束点 | 描述 | ||
|---|---|---|---|---|
| 帖子 | /servers/register | 注册一个新的MCP服务器 | ||
| GET | (中文可译为:“获取”或“请求获取”,具体根据上下文确定) /servers | 获取已注册服务器列表 | ||
| GET | (可翻译为) | 获取 | /servers/{serverId} | 获取特定服务器的详细信息 |
| 删除 | /servers/{serverId} | 注销服务器 | ||
| 帖子 | /servers/{serverId}/health | 检查服务器健康状况 | ||
| POST | (在中文中,这通常直接保留为“POST”,因为它是HTTP方法名,无需翻译) /servers/health/all | 检查所有服务器的健康状况 |
请求转发
| 方法 | 终点 | 描述 |
|---|---|---|
| 帖子 | /forward | 将MCP调用转发到已注册的服务器 |
| 帖子 | /forward/tools/discover | 发现跨服务器的工具 |
MCP协议
| 端点 | 描述 |
|---|---|
/api/orchestrator/mcp | MCP HTTP传输端点 |
效用
| 方法 | 终点 | 描述 |
|---|---|---|
| GET | (HTTP方法,用于请求访问服务器上的资源) / | 服务信息 |
| GET | /health | 健康检查 |
| GET | (中文可译为“获取”或保持原样,因为“GET”在HTTP方法中常直接使用,不需翻译) /swagger API文档 |
MCP 工具
协调器提供了以下MCP工具:
服务器管理工具
register_mcp_server注册一个新的MCP服务器unregister_mcp_server注销MCP服务器get_mcp_servers获取已注册服务器的列表get_mcp_server获取特定服务器的详细信息health_check_mcp_server检查服务器健康状况health_check_all_servers检查所有服务器的健康状况
转发工具
forward_mcp_call将MCP方法调用转发到服务器discover_mcp_tools发现跨服务器可用的工具
配置
多租户支持
调度器通过(某种方式)支持多租户场景 ITenantProvider 接口。租户ID可通过以下方式提供:
- 查询参数:
?tenantId=tenant-123 - 路由参数:
/{tenantId}/... - HTTP头部:
X-Tenant-Id: tenant-123
认证
默认情况下,身份验证是可选的。要为所有端点启用身份验证,请取消注释以下行: Program.cs:
options.FallbackPolicy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();示例使用场景
1. 微服务编排
注册多个暴露MCP端点的微服务:
{
"name": "user-service",
"baseUrl": "https://user-service.example.com"
}{
"name": "order-service",
"baseUrl": "https://order-service.example.com"
}2. 工具发现
查找跨服务中所有与用户相关的工具:
{
"searchTerm": "user",
"serverIds": ["user-service-id", "auth-service-id"]
}3. 跨服务运营
将包含租户上下文的请求转发:
{
"serverId": "user-service-id",
"method": "get_user_profile",
"parameters": {"userId": "123"},
"tenantId": "company-abc"
}发展
项目结构
src/Avro.Mcp.Orchestrator/
├── Endpoints/ # API endpoints and MCP tools
├── Infrastructure/ # Cross-cutting concerns
├── Models/ # Data models and DTOs
├── Services/ # Business logic services
├── Validators/ # Request validation
└── Program.cs # Application startup添加新功能
- 在(某处/某系统中)定义模型
Models/Models.cs - 添加验证到
Validators/Validators.cs - 在(系统/程序中)实现业务逻辑
Services/ - 创建端点在
Endpoints/ - 在(系统/平台中)注册服务
Program.cs
测试
使用MCP检查器测试MCP功能:
- https://modelcontextprotocol.io/legacy/tools/inspector 翻译为中文是:“https://modelcontextprotocol.io/旧版/工具/检查器”
连接至: http://localhost:5234/api/orchestrator/mcp
健康监测
协调器自动监控已注册服务器的健康状况。服务器检查内容包括:
- 在注册时
- 对于明确的健康检查请求
- 在转发操作期间(如果服务器状态不佳)
依赖项
- .NET 8.0
- ModelContextProtocol(>= 0.5.0)
- ModelContextProtocol.AspNetCore(>= 0.5.0)
- FluentValidation(>= 11.9.2)
- Microsoft.AspNetCore.OpenApi 翻译为中文是:“Microsoft.AspNetCore 的 OpenApi(开放API)组件”或简化为“Microsoft 开放API(针对 ASP.NET Core)”。不过,通常在中文语境下,我们可能会直接说“ASP.NET Core 的 OpenApi 支持”或“Microsoft.AspNetCore 中的 OpenApi 功能”,以更简洁地表达其含义
- Swashbuckle.AspNetCore
做出贡献
- 为仓库创建分支
- 创建一个特性分支
- 按照现有模式进行更改
- 为新功能添加测试
- 提交拉取请求
Avro Git MCP 服务器
Git MCP服务器通过模型上下文协议提供了全面的Git自动化功能。该服务器使AI助手和其他客户端能够以编程方式执行Git操作。
Git MCP 功能
- 仓库管理克隆、初始化和管理Git仓库
- 提交操作阶段文件,创建带有完整元数据的提交
- 分支机构管理创建、切换、合并和删除分支
- 远程操作向远程仓库推送和拉取更改
- 状态与历史获取仓库状态、提交历史和分支信息
- 多租户支持按租户隔离Git操作
Git MCP 快速入门
1. 运行 Git MCP 服务器
cd src/Avro.Mcp.Git
dotnet restore
dotnet build
dotnet runGit MCP 服务器将在 https://localhost:7235 (或类似表述)。
2. 在Orchestrator中注册
将Git服务器注册到编排器中:
curl -X POST "https://localhost:7234/servers/register" \
-H "Content-Type: application/json" \
-d '{
"name": "git-server",
"description": "Git operations MCP server",
"baseUrl": "https://localhost:7235",
"version": "1.0.0",
"capabilities": ["git", "repository", "version-control"],
"metadata": {
"category": "git-automation"
}
}'3. Git 操作示例
克隆仓库
curl -X POST "https://localhost:7235/git/repository/clone" \
-H "Content-Type: application/json" \
-d '{
"remoteUrl": "https://github.com/user/repo.git",
"localPath": "/path/to/local/repo",
"branch": "main",
"username": "your-username",
"password": "your-token"
}'创建提交
curl -X POST "https://localhost:7235/git/commits" \
-H "Content-Type: application/json" \
-d '{
"repositoryPath": "/path/to/repo",
"message": "Add new feature",
"authorName": "Developer",
"authorEmail": "dev@example.com",
"addAll": true
}'创建分支
curl -X POST "https://localhost:7235/git/branches" \
-H "Content-Type: application/json" \
-d '{
"repositoryPath": "/path/to/repo",
"branchName": "feature/new-feature",
"checkout": true
}'Git MCP 工具
存储库工具
git_clone_repository克隆远程仓库git_init_repository初始化新仓库git_get_repository_info获取仓库元数据git_get_status获取工作目录状态
提交工具
git_commit_changes暂存并提交更改git_get_commits获取带过滤条件的提交历史
分支工具
git_create_branch创建新分支git_get_branches列出所有分支git_checkout_branch切换分支git_delete_branch移除分支git_merge_branch合并分支
远程工具
git_push_changes推送到远程仓库git_pull_changes从远程仓库拉取
Git MCP API 接口
仓库操作
| 方法 | 结束点 | 描述 |
|---|---|---|
| POST | (注:在中文语境中,"POST"通常不直接翻译,而是根据上下文可能指“帖子”、“发布”或保持原样作为技术术语使用,此处为保持原样) /git/repository/clone | 克隆一个仓库 |
| 帖子 | /git/repository/init | 初始化仓库 |
| GET | (可译为:“获取”或“请求”) /git/repository/info | 获取仓库信息 |
| GET | (HTTP方法:获取) /git/repository/status | 获取仓库状态 |
提交操作
| 方法 | 结束点 | 描述 |
|---|---|---|
| POST | (可翻译为“帖子”或根据上下文具体翻译为“发布”、“提交”等,但在此直接保留原英文以保持表格或列表的格式) /git/commits | 创建一个提交 |
| GET | (中文可译为“获取”或保持原样作为HTTP方法名,根据上下文确定) /git/commits | 获取提交历史 |
分支机构运营
| 方法 | 终点 | 描述 | ||
|---|---|---|---|---|
| POST | (在中文中,这个标签通常用于表示HTTP请求方法中的“POST”方法,直接翻译可能无具体含义,但可理解为“发布”或“提交”的意思,具体翻译需结合上下文) /git/branches | 创建一个分支 | ||
| GET | (中文可译为:“获取”或“请求获取”,但通常在描述HTTP方法时直接保留“GET”) /git/branches | 列出分支 | ||
| POST | (可翻译为) | 发布 | 或根据上下文具体翻译为“发帖”、“提交”等,但“POST”在编程或网络术语中常指“POST请求”,具体翻译需结合语境 /git/branches/checkout | 切换分支 |
| 删除 | /git/branches/{name} | 删除分支 | ||
| POST | (翻译为中文可保持原样,因为“POST”在中文网络语境中常直接使用,表示“帖子”或“发布”的意思,但在这里作为标题或分类时,通常不翻译,以保持原样) /git/branches/merge | 合并分支 |
远程操作
| 方法 | 结束点 | 描述 | ||||
|---|---|---|---|---|---|---|
| 帖子 | /git/remote/push | 推送更改 | ||||
| POST | (译文: | 发布 | 或 | 投稿 | ,具体根据上下文确定) /git/remote/pull | 拉取更改 |
Git 工作流示例
1. 完成特性开发
# 1. Clone repository
curl -X POST "localhost:7235/git/repository/clone" \
-d '{"remoteUrl": "https://github.com/user/repo.git", "localPath": "/work/repo"}'
# 2. Create feature branch
curl -X POST "localhost:7235/git/branches" \
-d '{"repositoryPath": "/work/repo", "branchName": "feature/auth", "checkout": true}'
# 3. Make changes and commit
curl -X POST "localhost:7235/git/commits" \
-d '{"repositoryPath": "/work/repo", "message": "Add authentication", "authorName": "Dev", "authorEmail": "dev@example.com", "addAll": true}'
# 4. Push changes
curl -X POST "localhost:7235/git/remote/push" \
-d '{"repositoryPath": "/work/repo", "branch": "feature/auth"}'2. 发布管理
# 1. Create release branch
curl -X POST "localhost:7235/git/branches" \
-d '{"repositoryPath": "/work/repo", "branchName": "release/v1.0", "checkout": true}'
# 2. Merge feature branches
curl -X POST "localhost:7235/git/branches/merge" \
-d '{"repositoryPath": "/work/repo", "sourceBranch": "feature/auth", "committerName": "Release Manager", "committerEmail": "rm@example.com"}'
# 3. Tag and push
curl -X POST "localhost:7235/git/commits" \
-d '{"repositoryPath": "/work/repo", "message": "Release v1.0", "authorName": "Release Manager", "authorEmail": "rm@example.com"}'
curl -X POST "localhost:7235/git/remote/push" \
-d '{"repositoryPath": "/work/repo", "branch": "release/v1.0"}'与Orchestrator配合使用
一旦在编排器中注册,您就可以通过MCP调用来执行Git操作:
# Forward Git operation through orchestrator
curl -X POST "https://localhost:7234/forward" \
-H "Content-Type: application/json" \
-d '{
"serverId": "git-server-id",
"method": "git_clone_repository",
"parameters": {
"remoteUrl": "https://github.com/user/repo.git",
"localPath": "/path/to/repo"
},
"tenantId": "team-alpha"
}'配置
Git服务器设置
{
"Git": {
"ServiceName": "git",
"DefaultTimeout": "00:05:00",
"MaxRepositorySize": "1073741824"
}
}认证
Git 服务器支持与编排器相同的认证模式:
- 可选的JWT认证
- 多租户隔离
- 请求验证
在本地测试 Git MCP 服务器
1. 先决条件
确保你已准备好:
- 已安装 .NET 8.0 SDK
- 您的系统上已安装Git
- 一个测试仓库(本地或远程)
2. 启动Git MCP服务器
# Navigate to Git MCP project
cd src/Avro.Mcp.Git
# Restore dependencies
dotnet restore
# Run the server
dotnet run服务器将在 https://localhost:5001 或类似内容(请查看控制台输出)。
3. 使用MCP Inspector进行测试
选项A:使用MCP检查器工具
- 打开 https://modelcontextprotocol.io/legacy/tools/inspector
- 连接到:
https://localhost:5001/api/git/mcp - 探索可用的工具并进行交互式测试
选项B:使用curl命令(详细示例见下文)
4. 本地测试场景
测试1:仓库信息
# Create a test repository first
mkdir /tmp/test-repo
cd /tmp/test-repo
git init
echo "# Test Repo" > README.md
git add README.md
git config user.name "Test User"
git config user.email "test@example.com"
git commit -m "Initial commit"
# Test getting repository info
curl -X GET "https://localhost:5001/git/repository/info?repositoryPath=/tmp/test-repo" \
-H "Accept: application/json" \
-k测试2:仓库状态
# Make some changes to test status
echo "Some changes" >> /tmp/test-repo/README.md
echo "New file" > /tmp/test-repo/newfile.txt
# Check status via MCP
curl -X GET "https://localhost:5001/git/repository/status?repositoryPath=/tmp/test-repo" \
-H "Accept: application/json" \
-k测试3:创建并提交更改
# Commit changes via MCP
curl -X POST "https://localhost:5001/git/commits" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-k \
-d '{
"repositoryPath": "/tmp/test-repo",
"message": "Add new content via MCP",
"authorName": "MCP Test",
"authorEmail": "mcp@test.com",
"addAll": true
}'测试4:分支操作
# Create a new branch
curl -X POST "https://localhost:5001/git/branches" \
-H "Content-Type: application/json" \
-k \
-d '{
"repositoryPath": "/tmp/test-repo",
"branchName": "feature/test-branch",
"checkout": true
}'
# List all branches
curl -X GET "https://localhost:5001/git/branches?repositoryPath=/tmp/test-repo" \
-H "Accept: application/json" \
-k
# Switch back to main
curl -X POST "https://localhost:5001/git/branches/checkout" \
-H "Content-Type: application/json" \
-k \
-d '{
"repositoryPath": "/tmp/test-repo",
"branchName": "main"
}'测试5:克隆仓库
# Clone a public repository
curl -X POST "https://localhost:5001/git/repository/clone" \
-H "Content-Type: application/json" \
-k \
-d '{
"remoteUrl": "https://github.com/octocat/Hello-World.git",
"localPath": "/tmp/cloned-repo"
}'测试6:获取提交历史
# Get recent commits
curl -X GET "https://localhost:5001/git/commits?repositoryPath=/tmp/test-repo&take=5" \
-H "Accept: application/json" \
-k5. 使用Orchestrator进行测试
步骤1:启动两个服务
# Terminal 1: Start Git MCP Server
cd src/Avro.Mcp.Git
dotnet run
# Terminal 2: Start Orchestrator
cd src/Avro.Mcp.Orchestrator
dotnet run步骤2:将Git服务器注册到Orchestrator
# Register the Git server
curl -X POST "https://localhost:7234/servers/register" \
-H "Content-Type: application/json" \
-d '{
"name": "git-server",
"description": "Local Git MCP server for testing",
"baseUrl": "https://localhost:5001",
"version": "1.0.0",
"capabilities": ["git", "repository", "version-control"],
"metadata": {
"category": "git-automation"
}
}'步骤3:通过编排器测试Git操作
# Get the server ID from registration response, then test forwarding
curl -X POST "https://localhost:7234/forward" \
-H "Content-Type: application/json" \
-d '{
"serverId": "YOUR_SERVER_ID_HERE",
"method": "git_get_repository_info",
"parameters": {
"repositoryPath": "/tmp/test-repo"
}
}'步骤4:通过Orchestrator发现Git工具
# Discover all Git tools
curl -X POST "https://localhost:7234/forward/tools/discover" \
-H "Content-Type: application/json" \
-d '{
"searchTerm": "git",
"serverIds": ["YOUR_SERVER_ID_HERE"]
}'6. 直接测试MCP协议
您也可以直接使用MCP JSON-RPC格式来测试MCP协议:
# Test tools/list MCP method
curl -X POST "https://localhost:5001/api/git/mcp" \
-H "Content-Type: application/json" \
-k \
-d '{
"jsonrpc": "2.0",
"id": "test-1",
"method": "tools/list"
}'
# Test tools/call MCP method
curl -X POST "https://localhost:5001/api/git/mcp" \
-H "Content-Type: application/json" \
-k \
-d '{
"jsonrpc": "2.0",
"id": "test-2",
"method": "tools/call",
"params": {
"name": "git_get_repository_info",
"arguments": {
"repositoryPath": "/tmp/test-repo"
}
}
}'7. 调试技巧
启用详细日志记录
添加到 appsettings.Development.json:
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"Avro.Mcp.Git": "Trace",
"Microsoft.AspNetCore": "Information"
}
}
}检查服务器健康状况
curl -X GET "https://localhost:5001/health" -k查看API文档
开放 https://localhost:5001/swagger 在您的浏览器中,以交互方式探索API。
8. 常见问题及解决方案
问题SSL证书错误 解决方案使用 -k 使用curl时添加标志或配置适当的证书
问题未找到存储库 解决方案确保仓库路径存在且是一个有效的Git仓库
问题权限被拒绝 解决方案检查仓库目录的文件权限
问题LibGit2Sharp 错误 解决方案确保已安装Git且仓库未损坏
9. 自动化测试脚本
创建一个测试脚本 test-git-mcp.sh:
#!/bin/bash
set -e
BASE_URL="https://localhost:5001"
TEST_REPO="/tmp/mcp-test-repo"
echo "🧪 Testing Git MCP Server..."
# Cleanup previous test
rm -rf $TEST_REPO
# Initialize test repository
echo "📁 Setting up test repository..."
curl -X POST "$BASE_URL/git/repository/init" \
-H "Content-Type: application/json" \
-k -s \
-d "{\"localPath\": \"$TEST_REPO\"}"
# Check repository info
echo "ℹ️ Getting repository info..."
curl -X GET "$BASE_URL/git/repository/info?repositoryPath=$TEST_REPO" \
-H "Accept: application/json" \
-k -s | jq .
# Create initial commit
echo "📝 Creating initial commit..."
echo "# Test Repository" > "$TEST_REPO/README.md"
curl -X POST "$BASE_URL/git/commits" \
-H "Content-Type: application/json" \
-k -s \
-d "{
\"repositoryPath\": \"$TEST_REPO\",
\"message\": \"Initial commit\",
\"authorName\": \"Test User\",
\"authorEmail\": \"test@example.com\",
\"addAll\": true
}" | jq .
echo "✅ Git MCP Server tests completed!"运行于: chmod +x test-git-mcp.sh && ./test-git-mcp.sh
依赖项
- .NET 8.0
- LibGit2Sharp (>= 0.30.0) - 原生 Git 操作
- ModelContextProtocol 包
- FluentValidation(流畅验证)
许可证
此项目采用MIT许可证授权。
