mcp-graph-loop
Enables AI agents to orchestrate tasks as a DAG with automated validation loops, executing validation commands, tracking statuses, and allowing iterative code fixes until tasks pass.
README
BRD Graph Loop MCP Server
A specialized MCP (Model Context Protocol) server for graph-based task orchestration with automated validation and self-healing retry loops.
🎯 How It Works: High-Level Architecture
flowchart TD
subgraph AI["🤖 AI Agent (Claude / Cursor / IDE)"]
A1[1. Initialize Graph] --> A2[2. Query Ready Tasks]
A2 --> A3[3. Start Task & Write Code]
A3 --> A4[4. Call validate_task_loop]
end
subgraph MCP["⚙️ BRD Graph Loop MCP Server"]
M1[(State Management: nodes, dependencies, status)]
M2[Dependency Resolver & DAG Engine]
M3[Command Executor & Output Capture]
M4[Loop Controller: Retries, Max Attempts, Error Logging]
end
A1 -->|init_project_graph| M1
A2 -->|get_ready_tasks| M2
A3 -->|start_task| M1
A4 -->|validate_task_loop| M3
M3 -->|Pass: exitCode 0| M4
M3 -->|Fail: exitCode != 0| M4
M4 -->|Unlock Next Tasks| M2
M4 -->|Return Error Context| AI
🔄 Node Lifecycle & State Transitions
Each task node moves through deterministic states based on its prerequisites and validation results:
stateDiagram-v2
[*] --> PENDING : Initial state with unresolved dependencies
PENDING --> READY : All 'depends_on' tasks reach COMPLETED
READY --> IN_PROGRESS : AI calls 'start_task'
state "Validation Loop" as Loop {
IN_PROGRESS --> VALIDATING : AI calls 'validate_task_loop'
VALIDATING --> RETRYING : Command fails (exitCode != 0 & attempts < max)
RETRYING --> IN_PROGRESS : AI reads error logs and fixes code
}
VALIDATING --> COMPLETED : Command passes (exitCode 0)
VALIDATING --> FAILED : Command fails & max_attempts exceeded
COMPLETED --> [*] : Unlocks downstream PENDING nodes
FAILED --> [*] : Can be reset with 'reset_task_node'
💡 Key Concepts
1. Directed Acyclic Graph (DAG)
Tasks have explicit dependencies (depends_on: ["task_a", "task_b"]). The server automatically ensures tasks only become READY when all their prerequisite tasks are COMPLETED.
2. The Iterative Validation Loop
Instead of hoping code works, each node specifies a validation_command (e.g., npm test, tsc --noEmit, pytest, eslint):
- Pass (
exitCode: 0): Loop status becomesPASSED, node becomesCOMPLETED, and dependent nodes automatically switch toREADY. - Fail (
exitCode != 0): The server logs fullstdout/stderrand exit codes inerror_logs, incrementscurrent_attempt, and returns the error output to the AI. - Self-Correction: The AI analyzes the error, modifies code, and calls
validate_task_loopagain until it passes or hitsmax_attempts.
🛠️ Complete Step-by-Step Flow
Step 0: Scaffold Project Planning Docs (scaffold_project_docs)
Before initializing the graph, the AI agent can generate standard project documentation (Architecture, Phase-wise Tasks, and Test Cases) based on the user's requirements:
{
"targetDirectory": "./",
"architectureContent": "# Project Architecture\n...",
"phaseTasks": [
{ "fileName": "PHASE_1.md", "content": "# Phase 1 Tasks\n..." }
],
"testCasesContent": "# Integration Tests\n..."
}
Step 1: Initialize Workflow (init_project_graph)
The AI agent creates a task graph for a project:
{
"projectName": "Auth Feature",
"projectRoot": "/path/to/your/project/dir",
"nodes": [
{
"id": "schema",
"title": "Define User Database Schema",
"description": "Create Prisma schema and migration scripts",
"depends_on": [],
"validation_command": "npx prisma validate",
"max_attempts": 3
},
{
"id": "jwt_service",
"title": "Build JWT Token Service",
"description": "Implement sign, verify, and refresh token functions",
"depends_on": ["schema"],
"validation_command": "npm run test -- jwt.test.ts",
"max_attempts": 3
},
{
"id": "login_route",
"title": "Build API Login Endpoint",
"description": "Express POST /api/login endpoint with validation",
"depends_on": ["jwt_service"],
"validation_command": "npm run test -- auth.test.ts",
"max_attempts": 3
}
]
}
Step 2: Fetch Ready Tasks (get_ready_tasks)
The agent asks what to work on next:
{
"ready_count": 1,
"ready_tasks": [
{
"id": "schema",
"title": "Define User Database Schema",
"status": "READY"
}
]
}
(Notice jwt_service and login_route remain PENDING because their dependencies aren't done yet).
Step 3: Start the Task (start_task)
The agent claims the task:
{ "nodeId": "schema" }
Node status transitions to IN_PROGRESS.
Step 4: Validate the Code (validate_task_loop)
After the agent writes the schema files, it triggers the validation loop:
{ "nodeId": "schema" }
- If it passes:
schemastatus becomesCOMPLETED.jwt_serviceautomatically becomesREADY!
- If it fails:
- MCP returns:
{ "validation_passed": false, "message": "Validation failed on attempt 1/3. Node 'schema' is in RETRYING status.", "result": { "exitCode": 1, "error": "Syntax error at line 14: invalid relation syntax" } } - The AI reviews the error, fixes line 14, and re-calls
validate_task_loop.
- MCP returns:
📦 MCP Configuration
Add this to your MCP settings file (~/.cursor/mcp.json, Claude Desktop config, or .gemini/config/mcp_config.json):
{
"mcpServers": {
"brd-graph-loop": {
"command": "node",
"args": [
"/Volumes/DATA/html work/mcp-graph-loop-server/build/index.js"
]
}
}
}
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。