agent-guard-mcp
Detects and prevents infinite agent loops via circuit breakers, pattern detection, and recovery recommendations.
README
agent-guard-mcp
MCP server that detects and prevents infinite agent loops — the #1 reliability problem in agentic systems.
Provides circuit breakers, pattern detection, stuck-agent analysis, and recovery recommendations via the Model Context Protocol.
Install
npx agent-guard-mcp
Claude Desktop
Add to claude_desktop_config.json:
{
"mcpServers": {
"agent-guard": {
"command": "npx",
"args": ["agent-guard-mcp"]
}
}
}
From source
git clone https://github.com/mdfifty50-boop/agent-guard-mcp.git
cd agent-guard-mcp
npm install
node src/index.js
Tools
register_agent
Register an agent for monitoring.
| Param | Type | Default | Description |
|---|---|---|---|
agent_id |
string | required | Unique agent identifier |
max_iterations |
number | 100 | Max iterations before forced stop |
progress_threshold |
number | 0.3 | Min unique/total action ratio to be "making progress" |
log_action
Log an agent action for loop detection. Maintains a rolling window of the last 50 actions.
| Param | Type | Default | Description |
|---|---|---|---|
agent_id |
string | required | Agent identifier |
tool_name |
string | required | Tool being called |
args |
object | required | Arguments passed |
result_preview |
string | "" |
Brief result preview (max 200 chars) |
Returns early warnings when repeated patterns are detected.
detect_loop
Check if an agent is stuck in an infinite loop.
| Param | Type | Description |
|---|---|---|
agent_id |
string | Agent to check |
Returns:
is_stuck— booleanconfidence— 0.0 to 1.0pattern—healthy,exact_repeat,low_diversity, orexact_repeat_and_low_diversitysuggestion— human-readable recovery advicerepeated_actions— list of repeated signatures with counts
set_circuit_breaker
Configure automatic intervention when action patterns repeat.
| Param | Type | Default | Description |
|---|---|---|---|
agent_id |
string | required | Agent identifier |
max_repeats |
number | 3 | Trigger after N identical actions |
action |
string | "warn" |
"warn", "block", or "suggest_alternative" |
check_circuit_breaker
Pre-flight check before executing a tool. Call this BEFORE the actual tool call.
| Param | Type | Description |
|---|---|---|
agent_id |
string | Agent identifier |
proposed_tool |
string | Tool about to be called |
proposed_args |
object | Arguments about to be passed |
Returns proceed: false when the circuit breaker fires (block mode only).
get_stuck_report
Detailed analysis of why an agent is stuck.
| Param | Type | Description |
|---|---|---|
agent_id |
string | Agent to analyze |
Returns: action history, pattern analysis, token waste estimate, diversity ratio, top repeated patterns, and recovery recommendations.
get_health_dashboard
Overview of all monitored agents. No parameters.
Returns all agents sorted by risk score with their status (STUCK/HEALTHY), action counts, and circuit breaker config.
Resources
| URI | Description |
|---|---|
agent-guard://agents |
All monitored agents with current status |
Usage Pattern
1. register_agent — at agent startup
2. Before each tool call:
a. check_circuit_breaker — should this action proceed?
b. Execute the tool
c. log_action — record what happened
3. Periodically:
- detect_loop — am I stuck?
- get_health_dashboard — how are all agents doing?
4. On stuck detection:
- get_stuck_report — what went wrong and how to recover
Tests
npm test
License
MIT
Recommended Servers
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.
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.
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.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
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.
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.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
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.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.