使用说明
MCP客户端服务器后端
FastAPI后端,带有Anthropic Claude+Taiga进程内MCP工具注册表。
建筑
- 快速API HTTP服务器
- Anthropic Claude 使用工具的消息API
- 过程中MCP 工具注册表(没有单独的服务器)
- 有界多步循环 有预算和重复数据消除
- 基于角色的工具曝光 来自Taiga权限
设置
先决条件
- Python 3.11+
- 无烟煤API键
- 具有API访问权限的Taiga帐户
安装
# Install dependencies
pip install -r requirements.txt
# Configure .env file with your API key and model
在本地运行
# From repo root
uvicorn backend.main:app --reload --host 0.0.0.0 --port 8000
这 .env 文件会自动加载。服务器运行于 http://localhost:8000
使用Docker运行
# Build
docker build -t mcp-backend .
# Run
docker run -p 8000:8000 -e ANTHROPIC_API_KEY=your_key_here mcp-backend
API终点
GET/健康
健康检查。
答复:
{"status": "ok"}
POST/代理/运行
执行代理任务。
请求:
{
"project_ref": "my-project",
"sprint_ref": "Sprint 6",
"prompt": "MEETING MINUTES...\n\nCreate user stories and tasks for Sprint 6.",
"auth_token": "your_taiga_bearer_token",
"refresh": "your_refresh_token",
"user_context": {
"id": 738718,
"username": "jdlafond",
"email": "jdlafond@asu.edu",
"roles": ["Back", "Product Owner"]
}
}
答复:
{
"summary": "Created 3 user stories and 9 tasks in Sprint 6.",
"artifacts": {
"milestone_id": 12345,
"user_stories": [
{
"id": 111,
"subject": "As a user, I can log workouts",
"tasks": [
{"id": 9001, "subject": "Create workout log screen"}
]
}
]
},
"warnings": []
}
cURL示例
curl -X POST http://localhost:8000/agent/run \
-H "Content-Type: application/json" \
-d '{
"project_ref": "my-project",
"sprint_ref": "Sprint 6",
"prompt": "Create a user story for login feature with 2 tasks",
"auth_token": "YOUR_TAIGA_TOKEN",
"refresh": "YOUR_REFRESH_TOKEN",
"user_context": {
"id": 1,
"username": "test",
"email": "test@example.com",
"roles": ["Back"]
}
}'
工具注册表
工具根据Taiga角色权限公开:
阅读工具:
taiga_get_project(要求view_project)taiga_list_milestones(要求view_milestones)taiga_get_milestone_by_name(要求view_milestones)taiga_list_user_stories(要求view_us)
写入工具:
taiga_create_user_story(要求add_us)taiga_create_task(要求add_task)
预算
deadline_seconds: 30max_steps: 10max_total_tool_calls: 25max_write_calls: 15max_repeated_call_hash: 2
项目结构
backend/
├── main.py # FastAPI app
├── agent.py # Orchestrator loop
├── models/
│ ├── agent_models.py # Request/response types
│ └── taiga_models.py # Taiga DTOs
├── services/
│ ├── anthropic_client.py
│ └── http_client.py
├── tools/
│ ├── registry.py # Tool registration + gating
│ └── taiga.py # Taiga API client
├── permissions/
│ └── permissions.py # Role → permission mapping
└── utils/
├── errors.py
├── hashing.py
└── logging.py
发展
运行测试(实施时):
pytest
格式代码:
black backend/
备注
- 从不记录身份验证令牌
- Idempotency防止重复写入
- 循环检测停止无限递归
- 预算用尽后返回部分结果
