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.
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">
</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 | ✅ |
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。