ARCHITECTURE.mdā¢6.66 kB
# MCP Self-Learning Server Architecture
## šļø System Overview
The MCP Self-Learning Server is an autonomous learning system that integrates with multiple AI agents and services to continuously improve performance through pattern recognition and knowledge accumulation.
## š§ Core Components
### 1. Learning Engine
**Location**: `mcp-self-learning-server.js` (LearningEngine class)
- **Pattern Recognition**: Analyzes interaction patterns using semantic embeddings
- **Feature Extraction**: Extracts contextual cues, performance metrics, and temporal patterns
- **Memory Management**: Manages up to 1000 patterns in memory with LRU eviction
- **Learning Cycles**: Periodic optimization and knowledge consolidation
### 2. Knowledge Synchronizer
**Location**: `mcp-self-learning-server.js` (KnowledgeSynchronizer class)
- **Cross-Service Learning**: Shares knowledge between different AI services
- **Data Persistence**: Auto-saves learning data every 5 minutes
- **Export/Import**: Supports knowledge transfer between instances
- **Backup Management**: Maintains rotating backups of learning data
### 3. MCP Server Interface
**Location**: `mcp-self-learning-server.js` (SelfLearningMCPServer class)
- **MCP Protocol**: Implements Model Context Protocol for tool registration
- **Tool Definitions**: Provides learning tools for external agents
- **Request Handling**: Processes learning requests from connected agents
- **Resource Management**: Manages server resources and connections
## š Integration Architecture
### Client Libraries
#### Node.js Client (`lib/self-learning-client.js`)
```javascript
import SelfLearningClient from './lib/self-learning-client.js';
const client = new SelfLearningClient({ port: 8765 });
await client.connect();
```
#### Python Client (`lib/self_learning_client.py`)
```python
from lib.self_learning_client import SelfLearningClient
client = SelfLearningClient(base_url="http://localhost:8765")
await client.connect()
```
### REST API (`api/rest-server.js`)
- **Endpoints**: `/analyze`, `/insights`, `/optimize`, `/predict`, `/metrics`
- **WebSocket**: Real-time updates on `ws://localhost:8765/ws`
- **CORS Support**: Cross-origin requests enabled
- **Authentication**: Token-based auth (configurable)
### CLI Tool (`bin/mcp-learn.js`)
```bash
mcp-learn start # Start MCP server
mcp-learn api # Start REST API
mcp-learn analyze # Analyze patterns
mcp-learn insights # Get learning insights
```
## š Data Flow
### 1. Pattern Analysis Flow
```
Agent Interaction ā Feature Extraction ā Pattern Matching ā Learning Update ā Knowledge Storage
```
### 2. Learning Cycle Flow
```
Accumulated Patterns ā Analysis ā Optimization ā Knowledge Consolidation ā Performance Improvement
```
### 3. Integration Flow
```
External Agent ā MCP Tool Call ā Learning Engine ā Pattern Analysis ā Recommendations ā Agent
```
## šļø Integration Patterns
### Claudio (AIMCP Orchestrator)
**Integration**: `integrations/claudio-mcp-tools.js`
- **6 MCP Tools**: learn_from_interaction, get_learning_insights, optimize_workflow, etc.
- **Workflow Learning**: Learns from multi-agent workflow outcomes
- **Predictive Suggestions**: Predicts next best actions in workflows
### Claudia (Voice Assistant)
**Integration**: `integrations/claudia_learning_plugin.py`
- **Voice Interaction Learning**: Analyzes voice commands and responses
- **Intent Recognition**: Improves intent detection accuracy over time
- **Conversation Optimization**: Suggests better response patterns
## š Performance Characteristics
### Learning Engine Performance
- **Startup Time**: ~50ms
- **Pattern Analysis**: <100ms per interaction
- **Memory Efficiency**: ~85MB RSS for 1000+ patterns
- **Persistence**: Auto-save every 5 minutes
### API Performance
- **Response Time**: <100ms average
- **WebSocket Latency**: <10ms
- **Concurrent Connections**: Supports 100+ simultaneous
- **Throughput**: 1000+ requests/minute
## š§ Configuration Architecture
### Server Configuration
```json
{
"maxMemorySize": 1000,
"persistenceEnabled": true,
"autoSaveInterval": 300000,
"logLevel": "info"
}
```
### Integration Configuration
- **Claudio**: Defined in `/home/ben/saralegui-solutions-llc/claude-assistant/config/claudio.config.json`
- **Claudia**: Plugin-based configuration
- **Systemd**: Service configuration in `~/.config/systemd/user/`
## š Security Architecture
### Data Security
- **Local Storage**: All data stored locally in `data/` directory
- **No External Dependencies**: No external API calls for core functionality
- **Configurable Auth**: Optional API authentication
- **Process Isolation**: Runs as user service
### Network Security
- **Local Binding**: Default binding to localhost only
- **Optional CORS**: Configurable cross-origin policies
- **WebSocket Security**: Optional authentication for WebSocket connections
- **Rate Limiting**: Configurable request rate limits
## š Scalability Architecture
### Horizontal Scaling
- **Multiple Instances**: Can run multiple learning servers
- **Knowledge Sharing**: Cross-instance knowledge synchronization
- **Load Distribution**: REST API can be load balanced
### Vertical Scaling
- **Memory Management**: Configurable memory limits
- **Background Processing**: Non-blocking learning cycles
- **Resource Monitoring**: Built-in performance metrics
## š Extension Points
### Custom Learning Algorithms
- **Pattern Extractors**: Custom feature extraction algorithms
- **Learning Strategies**: Pluggable learning strategies
- **Optimization Functions**: Custom optimization algorithms
### Integration Extensions
- **New Agent Types**: Easy integration with new AI agents
- **Custom Tools**: Extensible MCP tool definitions
- **Protocol Extensions**: Support for new communication protocols
## š Dependencies
### Core Dependencies
- `@modelcontextprotocol/sdk`: MCP protocol implementation
- `express`: REST API server
- `ws`: WebSocket support
- `commander`: CLI interface
### Development Dependencies
- `axios`: HTTP client for testing
- Testing framework: Custom test implementations
## š Deployment Architecture
### Local Development
- **Direct Execution**: `node mcp-self-learning-server.js`
- **CLI Development**: `mcp-learn start`
### Production Deployment
- **Systemd Service**: Auto-start with system boot
- **Global CLI**: NPM global package installation
- **Docker**: Containerized deployment option
- **Kubernetes**: Pod deployment with persistent volumes
This architecture provides a scalable, secure, and extensible foundation for autonomous learning across multiple AI agent systems.