Skip to main content
Glama

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

Related MCP server: Orchestrator Python MCP Server

🔄 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):

  1. Pass (exitCode: 0): Loop status becomes PASSED, node becomes COMPLETED, and dependent nodes automatically switch to READY.

  2. Fail (exitCode != 0): The server logs full stdout/stderr and exit codes in error_logs, increments current_attempt, and returns the error output to the AI.

  3. Self-Correction: The AI analyzes the error, modifies code, and calls validate_task_loop again until it passes or hits max_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:

    • schema status becomes COMPLETED.

    • jwt_service automatically becomes READY!

  • 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 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"
      ]
    }
  }
}

Available Tools

16 tools
add_task_nodeA

Add a new task node dynamically into the active workflow graph with optional phase and category. Validates dependency references and checks for cycles before inserting.

Inputs: id (required), title (required), description (required), validation_command (required), +9 more.

bulk_reset_phaseA

Reset all FAILED (and optionally IN_PROGRESS) nodes in a phase back to PENDING, skipping COMPLETED nodes.

Inputs: phase (required), includeInProgress.

get_graph_stateA

Retrieve current workflow graph state, including visual ASCII progress table, Mermaid diagram, phase progress, nodes, error logs, and execution timeline.

Inputs: includeMermaid, includeAsciiTable.

get_node_timelineA

Get chronological execution timeline for a node, including timestamped attempts, exit codes, error logs, and duration in milliseconds.

Inputs: nodeId (required).

get_phase_statusA

Get phase progress summary, completion percentages, phase gate statuses (BLOCKED, IN_PROGRESS, COMPLETED), and blocking reasons.

Inputs: phase.

get_ready_tasksA

Get all task nodes whose dependencies and phase gates are satisfied and are ready to be worked on.

Inputs: no named parameters.

init_project_graphA

Initialize a new project workflow graph with task nodes, phase milestones, dependencies, and validation commands.

Inputs: nodes (required), projectName (required), phase_order, projectRoot, +1 more.

load_graph_stateA

Load a workflow graph state from a JSON file on disk with full Zod schema validation.

Inputs: filePath (required).

reset_task_nodeA

Reset a task node status to PENDING and clear its error logs, allowing a fresh retry from the beginning.

Inputs: nodeId (required).

save_graph_stateA

Persist the current workflow state to disk using atomic write (write-to-temp then rename) to prevent corruption.

Inputs: filePath.

scaffold_project_docsA

Generate standard project documentation files (Architecture/ER Diagram, Phase-wise Tasks, and Test Cases) in the project workspace based on provided project requirements. Useful for initializing a project plan before creating the graph.

Inputs: phaseTasks, targetDirectory, testCasesContent, architectureContent, +1 more.

start_taskA

Mark a task node as IN_PROGRESS to start working on it. Enforces phase gates before allowing execution.

Inputs: nodeId (required).

switch_projectA

Switch the active project context to a different project that was previously initialized with init_project_graph. Lists available projects if the requested one is not found.

Inputs: projectName (required).

update_task_nodeA

Update an existing task node properties, phase, status, or validation command. Re-validates dependency references and cycle-checks after update.

Inputs: nodeId (required), tags, phase, title, +10 more.

validate_parallel_tasksA

Run validation commands for multiple READY/IN_PROGRESS tasks concurrently with atomic sequential state accumulation (race-condition free).

Inputs: nodeIds (required), cwd, timeoutMs.

validate_task_loopB

Execute the validation command for a task node with duration tracking and attempt error logging. Streams live output via progress notifications when supported.

Inputs: nodeId (required), cwd, timeoutMs, commandOverride.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 16 tools

    Disambiguation4/5

    Most tools have distinct purposes with clear descriptions. get_graph_state and get_phase_status both provide state information but differ in scope (overall graph vs phase-level). validate_task_loop and validate_parallel_tasks are similar but clearly distinguished by single vs parallel execution.

    Naming Consistency4/5

    Tool names consistently use snake_case with a verb_noun pattern (get_graph_state, start_task, add_task_node). Minor variation in verb choice (init vs initialize, scaffold, switch) is still predictable and does not undermine the overall pattern.

    Tool Count4/5

    At 16 tools, the set is slightly above the comfortable range but each tool serves a distinct function in the workflow graph lifecycle. The complexity of the domain justifies the count, and there is no redundancy.

    Completeness4/5

    The tool set covers graph initialization, task management (add/update/start/reset), validation (single/parallel), state inspection, persistence, and project switching. Missing an explicit delete_task_node or mark_completed is a minor gap, but the core workflow is covered and workarounds exist.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables LLMs to execute and validate autonomous multi-agent workflows with tools for workflow execution, output validation, and execution logging, plus resources and prompts for task decomposition and error recovery.
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables pipeline-driven task management for AI coding agents, with stage-gated workflows, dependency tracking, artifact versioning, and multi-agent collaboration.
      178 npm
      23
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables orchestrating external AI agents to execute development tasks with asynchronous management, automated acceptance verification, failure rework loops, and optional visual baseline validation.
      11
      16 npm
      Apache 2.0