AI Agent Loop MCP Server

AI Agent Loop MCP Server

An AI debugging agent MCP server that enables autonomous plan-act-observe debugging workflows, allowing repository exploration, code inspection, human-approved edits, and test execution through structured MCP tools.

Category
Visit Server

README

๐Ÿค– Task 3 โ€” AI Agent Loop with MCP

A production-style AI Debugging Agent built using the Model Context Protocol (MCP), capable of planning, inspecting repositories, proposing code edits with human approval, executing tests, and evaluating performance across a benchmark suite.


<p align="center">

TypeScript

NodeJS

MCP

Groq

Status

</p>


๐Ÿ“Œ Overview

This project implements a complete autonomous debugging agent that follows the Plan โ†’ Act โ†’ Observe execution pattern.

Instead of directly editing repository files, the agent communicates through an MCP (Model Context Protocol) server, allowing every repository interaction to occur via structured tools.

The agent:

  • understands failing tests
  • creates a debugging plan
  • explores the repository
  • reads source files
  • proposes code edits
  • waits for user approval
  • executes tests
  • repeats until success or budget exhaustion

The implementation follows all major requirements from Task 3.


โœจ Features

Agent Loop

โœ” Planning

โœ” Tool selection

โœ” Repository exploration

โœ” Observation

โœ” Test execution

โœ” Halting conditions


MCP Server

Implemented tools:

  • read_file
  • list_dir
  • grep
  • propose_edit
  • run_test

All repository interaction occurs exclusively through MCP tools.


Human Approval

Before modifying any file the agent:

  • validates edit
  • shows diff
  • waits for user approval
  • updates repository only after confirmation

Unsafe edits are rejected automatically.


Safety

Implemented guardrails:

  • Step Budget
  • Wall Clock Budget
  • Stuck Loop Detection
  • Approval Validation
  • Repository Boundary Checks
  • Tool Error Handling

Evaluation

Includes:

  • Golden evaluation suite
  • Metrics
  • Trajectory logging
  • Result reporting

๐Ÿ— Architecture

                    +----------------------+
                    |      CLI / Index     |
                    +----------+-----------+
                               |
                               |
                     createInitialState()
                               |
                               |
                      +--------v--------+
                      |    Agent Loop   |
                      +--------+--------+
                               |
               +---------------+----------------+
               |                                |
               |                                |
        chooseTool()                     createPlan()
               |                                |
               |                                |
        +------v-------+                 +------v------+
        |    Groq LLM  |                 |   Planner   |
        +------+-------+                 +-------------+
               |
               |
        Tool Selection
               |
               |
      +--------v---------+
      |     MCP Client   |
      +--------+---------+
               |
               |
      +--------v---------+
      |    MCP Server    |
      +--------+---------+
               |
     +---------+----------+
     |         |          |
 read_file list_dir grep propose_edit run_test

๐Ÿ“‚ Project Structure

Task-3-Agent-Loop

โ”œโ”€โ”€ evals
โ”‚   โ””โ”€โ”€ golden-agent.jsonl
โ”‚
โ”œโ”€โ”€ packages
โ”‚   โ”œโ”€โ”€ agent
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ logs
โ”‚   โ”‚   โ”œโ”€โ”€ trajectory.jsonl
โ”‚   โ”‚   โ””โ”€โ”€ eval-results.json
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ src
โ”‚   โ”‚
โ”‚   โ”‚   โ”œโ”€โ”€ approval
โ”‚   โ”‚   โ”œโ”€โ”€ eval
โ”‚   โ”‚   โ”œโ”€โ”€ loop
โ”‚   โ”‚   โ”œโ”€โ”€ mcp
โ”‚   โ”‚   โ”œโ”€โ”€ metrics
โ”‚   โ”‚   โ”œโ”€โ”€ client.ts
โ”‚   โ”‚   โ”œโ”€โ”€ planner.ts
โ”‚   โ”‚   โ”œโ”€โ”€ model.ts
โ”‚   โ”‚   โ”œโ”€โ”€ logger.ts
โ”‚   โ”‚   โ”œโ”€โ”€ state.ts
โ”‚   โ”‚   โ””โ”€โ”€ cli.ts
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ tools
โ”‚   โ””โ”€โ”€ types
โ”‚
โ”œโ”€โ”€ broken-repo
โ”‚
โ”œโ”€โ”€ DESIGN.md
โ”œโ”€โ”€ NOTES.md
โ”œโ”€โ”€ RESULTS.md
โ””โ”€โ”€ README.md

๐Ÿง  Agent Workflow

Run Tests

โ†“

Tests Fail

โ†“

Create Debugging Plan

โ†“

Choose Tool

โ†“

Execute Tool

โ†“

Observe Result

โ†“

Update State

โ†“

Need Another Tool?

โ†“

Yes โ†’ Repeat

โ†“

No

โ†“

Run Tests

โ†“

Success

โ†“

Stop

โš™ Agent State

The agent maintains the following state:

Property Description
currentTest Active failing test
currentTestOutput Latest test output
currentStep Current iteration
maxSteps Maximum allowed iterations
seenFiles Already inspected files
seenDirectories Already listed directories
fileContents Cached repository files
history Tool execution history
completed Success flag

๐Ÿ”จ Available Tools

Tool Purpose
read_file Read source code
list_dir Explore repository
grep Search repository
propose_edit Request file modification
run_test Execute tests

๐Ÿ›ก Safety Mechanisms

Step Budget

Stops infinite reasoning after the configured limit.


Wall Clock Budget

Terminates execution after maximum runtime.


Stuck Loop Detection

Stops execution when the same tool with identical arguments is repeatedly selected.


Approval Gate

Every modification:

  • validated
  • previewed
  • confirmed

before writing to disk.


๐Ÿ“Š Metrics

The project reports:

  • Success Rate
  • Steps Used
  • Tool Errors
  • Guardrail Violations
  • Wasted Steps
  • Execution Time
  • Success within Budget

๐Ÿ“ˆ Evaluation

Golden evaluation contains:

Difficulty Cases
Easy 6
Medium 6
Hard 3
Total 15

Each evaluation records:

  • success
  • execution time
  • metrics
  • logs

๐Ÿ’ป CLI

Run the debugging agent

pnpm tsx src/cli.ts fix --test tests/math.test.ts

Run evaluation

pnpm tsx src/cli.ts eval

Run live evaluation

pnpm tsx src/cli.ts eval --live

Compare against baseline

pnpm tsx src/cli.ts eval --compare baseline.json

๐Ÿ“ Logs

Generated automatically:

logs/

trajectory.jsonl

eval-results.json

Trajectory contains:

  • tool
  • arguments
  • timestamp
  • result

๐Ÿงช Technologies

  • TypeScript
  • Node.js
  • Groq API
  • MCP SDK
  • Vitest
  • PNPM

๐ŸŽฏ Assignment Requirements

Requirement Status
Agent Loop โœ…
Planner โœ…
MCP Tools โœ…
Approval Workflow โœ…
Trajectory Logging โœ…
Metrics โœ…
Evaluation Harness โœ…
Golden Dataset โœ…
CLI โœ…
Documentation โœ…

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured