The MCP Dual-Cycle Reasoner server enhances AI agent autonomy and self-awareness through metacognitive monitoring and case-based reasoning.
• Metacognitive Monitoring: Initialize, update, and stop monitoring of agent cognitive processes, tracking actions, context, and goals with real-time insights and session summaries • Intelligent Loop Detection: Identify repetitive patterns or stagnation using statistical, pattern-based, or hybrid methods with configurable thresholds and progress indicators • Experience Management: Store and retrieve problem-solution cases with detailed metadata, utilizing semantic matching for efficient case-based reasoning • System Management: Access current monitoring status and statistics, configure detection parameters, and reset the engine state for fresh sessions
Integrated with GitHub Actions for CI/CD pipeline automation, as shown by the workflow badge in the README.
A Model Context Protocol (MCP) server implementing the Dual-Cycle Metacognitive Reasoning Framework for autonomous agents. This tool empowers agents with greater self-awareness and reliability through intelligent loop detection and experience acquisition.
Description
The MCP Dual-Cycle Reasoner is a sophisticated tool designed to enhance the autonomy and reliability of AI agents. By implementing a dual-cycle metacognitive framework, it provides agents with the ability to monitor their own cognitive processes, detect when they are stuck in repetitive loops, and learn from past experiences to make better decisions.
The framework consists of two main components:
- Sentinel: Monitors the agent's actions and detects anomalies, such as action repetition, state invariance, and progress stagnation.
- Adjudicator: Manages a case base of past experiences, allowing the agent to store and retrieve solutions to previously encountered problems.
This server is built with TypeScript and leverages high-performance libraries for statistical analysis, natural language processing, and semantic similarity, enabling advanced features like entropy-based anomaly detection, NLI-based text analysis, and intelligent case management.
Key Features
- 📊 Advanced Statistical Analysis: Entropy-based anomaly detection and time series analysis.
- 🧠 Enhanced Case-Based Reasoning: Semantic similarity matching with NLI-based text analysis.
- 🎯 Multi-Strategy Detection: Statistical, pattern-based, and hybrid loop detection.
- 📈 Time Series Analysis: Trend detection and cyclical pattern recognition.
- 🔧 Configurable Detection: Domain-specific thresholds and progress indicators.
- 🎨 Intelligent Case Management: Quality scoring, deduplication, and usage-based optimization.
- 🚀 High-Performance Libraries: Built with
simple-statistics
,natural
,compromise
, and HuggingFace Transformers.
Tech Stack
- Language: TypeScript
- Framework: Node.js
- Server: FastMCP for SSE transport
- NLP and Machine Learning:
@huggingface/transformers
: For NLI-based semantic analysisnatural
: For sentiment analysis and tokenizationcompromise
: For natural language processing
- Statistics:
simple-statistics
: For statistical calculationsml-matrix
: For matrix operations
- Development Tools:
jest
: For testingeslint
: For lintingprettier
: For code formattingzod
: For schema validation
Installation
To get the project running locally, follow these steps:
- Clone the repository:
- Install dependencies:
- Build the project:
Usage
Running the Server
You can run the server in two modes:
- HTTP Stream (Default):The server will start on port 8080.
- Stdio:
Using with Claude Desktop
Add the following to your Claude Desktop MCP configuration:
For stdio transport, add the --stdio
flag to the args
array.
Available Tools
Core Monitoring Tools
start_monitoring
Initialize metacognitive monitoring of an agent's cognitive process.
Input Schema:
process_trace_update
Main monitoring function—processes cognitive trace updates from the agent.
Input Schema:
Return Payload:
Returns a JSON object indicating if intervention is required and details about any detected loop.
stop_monitoring
Stop metacognitive monitoring and get a session summary.
Input Schema: {}
Loop Detection Tools
detect_loop
Detect if the agent is stuck in a loop using various strategies.
Input Schema:
Return Payload:
Returns a LoopDetectionResult
object as a JSON string.
configure_detection
Configure loop detection parameters and domain-specific progress indicators.
Input Schema:
Enhanced Experience Management
store_experience
Store a case for future case-based reasoning with enhanced metadata and quality scoring.
Input Schema:
retrieve_similar_cases
Retrieve similar cases using advanced semantic matching and filtering.
Input Schema:
Return Payload:
Returns an array of Case
objects as a JSON string.
System Tools
get_monitoring_status
Get the current monitoring status and statistics.
Input Schema: {}
Return Payload:
Returns a JSON string with the current monitoring status, including is_monitoring
, current_goal
, trace_length
, and intervention_count
.
reset_engine
Reset the dual-cycle engine state.
Input Schema: {}
Example Usage Scenario
Example Usage Scenario
Here's a complete example showing how to use the dual-cycle reasoner to monitor an autonomous agent and build up experience over time:
1. Initial Setup and Configuration
2. Monitoring Agent Actions
3. Storing and Retrieving Experiences
Understanding Loop Detection
When the process_trace_update
tool detects a potential loop, it returns a detailed loop_detected
object. Understanding the components of this object can help you diagnose and debug agent behavior.
Here's a quick guide to the key metrics in the details
object:
dominant_method
: The primary method that triggered the loop detection (e.g.,semantic_repetition
,state_invariance
).anomaly_score
: An overall score (0-1) representing the confidence that the agent's recent actions are part of a loop. It's a weighted average of multiple detection methods.actions_involved_count
: The number of recent actions identified as being part of the detected loop.recent_actions_count
: The total number of recent actions analyzed.metrics
: An object containing the raw scores from the different detection methods, such as:semantic_repetition
: The percentage of recent actions that are semantically similar to each other.parameter_repetition
: The percentage of similarity between the parameters of semantically similar actions.exact_repetition
: The percentage of recent actions that are exact, character-for-character duplicates.cyclical_pattern
: The score (0-1) indicating the presence of repeating sequences of actions.oscillation_pattern
: The score (0-1) indicating the presence of oscillating (back-and-forth) actions.alternating_pattern
: The score (0-1) indicating the presence of alternating action patterns.
Contributing
Contributions are welcome! Please read the contributing guidelines and ensure all tests pass before submitting a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
Tools
A Model Context Protocol server that empowers AI agents with metacognitive monitoring to detect reasoning loops and provide intelligent recovery using case-based reasoning and statistical analysis.
Related MCP Servers
- AsecurityAlicenseAqualityA Model Context Protocol server that enhances AI-generated code quality through comprehensive analysis across 10 critical dimensions, helping identify issues before they become problems.Last updated -158PythonApache 2.0
- -securityFlicense-qualityA comprehensive Model Context Protocol server implementation that enables AI assistants to interact with file systems, databases, GitHub repositories, web resources, and system tools while maintaining security and control.Last updated -31TypeScript
CodeAlive MCPofficial
-securityAlicense-qualityA Model Context Protocol server that enhances AI agents by providing deep semantic understanding of codebases, enabling more intelligent interactions through advanced code search and contextual awareness.Last updated -47PythonMIT License- -securityFlicense-qualityA Model Context Protocol server that allows AI assistants to fetch and analyze incident data from Appsignal, including retrieving incident details, samples, listing recent incidents, and analyzing incidents to suggest fixes.Last updated -JavaScript