Katamari MCP Server
by ciphernaut
README.md
# Katamari MCP Server
An adaptive MCP (Model Context Protocol) server with ACP (Agent Control Protocol) that grows and evolves based on user needs through adaptive learning.
## Features
### Core Architecture
- **Intelligent Routing**: Tiny LLM model for efficient call routing
- **Modular Capabilities**: Plugin-based architecture with environment isolation
- **Hot Reload**: Development-friendly reload after test completion
- **Security**: Sandboxed execution and package validation
- **Asset Tracking**: Complete provenance tracking for all components
### ACP Self-Modification (Phase 1)
- **Self-Inspection**: Analyze current capabilities and system state
- **Capability Generation**: Create new capabilities based on needs
- **Workflow Composition**: Combine capabilities into workflows
- **Self-Healing**: Detect and fix system issues
- **Heuristic Governance**: 7-tag safety system for all operations
### Adaptive Learning (Phase 2) โจ NEW
- **Dynamic Heuristics**: Self-adjusting decision making based on performance
- **Multi-Channel Feedback**: User satisfaction, automatic monitoring, test results
- **Performance Analytics**: Real-time capability health scoring and trends
- **Learning Engine**: Pattern recognition and confidence-weighted adaptations
- **Feedback Loops**: Continuous improvement from every execution
### Advanced Agency (Phase 3) ๐ NEW
- **Workflow Optimizer**: Parallel execution, pattern recognition, auto-optimization
- **Predictive Analytics**: Performance prediction, proactive alerts, resource forecasting
- **Knowledge Transfer**: Cross-component learning, artifact sharing, similarity analysis
- **Self-Healing System**: Enhanced error recovery, pattern recognition, resilience policies
## Quick Start
### ๐ Option 1: Automated Setup (Recommended)
```bash
# Clone and run the auto-setup script
git clone <repository-url>
cd katamari-mcp
./start_server.sh
```
The `start_server.sh` script automatically:
- โ
Checks Python 3.9+ compatibility
- โ
Creates and activates virtual environment
- โ
Installs all dependencies (PyTorch CPU-only for faster setup)
- โ
Verifies server functionality
- โ
Creates necessary data directories
- โ
Starts the MCP server
### ๐ง Option 2: Manual Setup
```bash
# 1. Clone and setup environment
git clone <repository-url>
cd katamari-mcp
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# 2. Install dependencies
pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install transformers pydantic aiohttp mcp pytest-asyncio beautifulsoup4 psutil
# 3. Verify installation
python -c "from katamari_mcp.server import KatamariServer; print('โ
Ready')"
# 4. Start server
python -m katamari_mcp.server
```
### ๐งช Testing
```bash
# Run all tests
pytest
# Run Phase 2 adaptive learning tests
pytest tests/test_adaptive_learning.py
# Run Phase 3 advanced agency tests
pytest tests/test_phase3_simple.py tests/test_phase3_integration.py
# Test specific functionality
pytest tests/test_adaptive_learning.py::test_feedback_submission
```
## Project Structure
```
katamari-mcp/
โโโ katamari_mcp/ # Core server code
โ โโโ router/ # LLM routing system with Phase 2 endpoints
โ โโโ acp/ # ACP self-modification system
โ โ โโโ adaptive_learning.py # Dynamic heuristic adjustment
โ โ โโโ feedback.py # Feedback collection system
โ โ โโโ performance_tracker.py # Performance analytics
โ โ โโโ data_models.py # Centralized data structures
โ โ โโโ controller.py # ACP main orchestrator
โ โ โโโ heuristics.py # 7-tag safety system
โ โ โโโ testing.py # Parallel testing
โ โ โโโ git_tracker.py # Version control integration
โ โ โโโ workflow_optimizer.py # Phase 3: Workflow optimization
โ โ โโโ predictive_engine.py # Phase 3: Predictive analytics
โ โ โโโ knowledge_transfer.py # Phase 3: Cross-component learning
โ โ โโโ self_healing.py # Phase 3: Enhanced error recovery
โ โโโ security/ # Security and validation
โ โโโ utils/ # Utilities and helpers
โโโ tests/ # Test suite
โ โโโ test_adaptive_learning.py # Phase 2 comprehensive tests
โ โโโ test_phase3_simple.py # Phase 3 basic functionality tests
โ โโโ test_phase3_integration.py # Phase 3 integration tests
โโโ capabilities/ # Individual capability implementations
โโโ PLAN.md # Detailed project plan with Phase 2 details
โโโ README.md # This file
```
## Usage Examples
### MCP Client Integration
**Claude Desktop:**
Add to `claude_desktop_config.json`:
```json
{
"mcpServers": {
"katamari": {
"command": "bash",
"args": ["/path/to/katamari-mcp/start_server.sh"],
"cwd": "/path/to/katamari-mcp"
}
}
}
```
**Direct MCP Usage:**
```python
# List available capabilities
capabilities = await router.list_capabilities()
# Use web search
results = await router.call("web_search", {
"query": "adaptive learning systems",
"max_results": 5
})
# Use web scraping
content = await router.call("web_scrape", {
"url": "https://example.com",
"format": "markdown"
})
# Submit feedback for learning
await router.call("acp_feedback_submit", {
"capability_id": "web_search",
"rating": 5,
"comment": "Great results!"
})
```
### Available Capabilities
| Capability | Description | Parameters |
|------------|-------------|-------------|
| `web_search` | Search web without API tokens | `query` (string), `max_results` (int) |
| `web_scrape` | Extract web page content | `url` (string), `format` (string) |
| `acp_feedback_submit` | Submit execution feedback | `capability_id`, `rating`, `comment` |
| `acp_performance_metrics` | View capability analytics | `capability_id` (optional) |
| `acp_learning_summary` | Learning progress overview | None |
| `acp_inspect` | System inspection | None |
| `phase3_workflow_status` | Workflow optimization status | `workflow_id` (optional) |
| `phase3_predictions` | Predictive analytics | `capability_id` (optional) |
| `phase3_knowledge_artifacts` | Knowledge transfer artifacts | `capability_id` (optional) |
| `phase3_healing_status` | Self-healing system status | `capability_id` (optional) |
### ACP Self-Modification
```python
# Inspect system capabilities
inspection = await router.call("acp_inspect", {})
# Propose new capability
proposal = await router.call("acp_propose", {
"need": "data visualization capability",
"context": {"user_preference": "chart generation"}
})
# Compose workflow
workflow = await router.call("acp_compose", {
"capabilities": ["web_search", "data_analysis"],
"workflow_name": "research_pipeline"
})
```
### Phase 2 Adaptive Learning
```python
# Submit feedback for capability
await router.call("acp_feedback_submit", {
"capability_id": "web_search",
"rating": 5,
"comment": "Excellent results!"
})
# Get performance analytics
metrics = await router.call("acp_performance_metrics", {
"capability_id": "web_search",
"days_back": 7
})
# Get learning summary
learning = await router.call("acp_learning_summary", {})
```
## Build/Test Commands
### Setup & Running
- `./start_server.sh` - **Recommended**: Auto-setup and start server
- `python -m katamari_mcp.server` - Start server (manual setup required)
### Testing
- `pytest` - Run all tests
- `pytest tests/test_adaptive_learning.py` - Run Phase 2 adaptive learning tests
- `pytest -k "test_name"` - Run specific test
### Development (Manual Setup)
- `source .venv/bin/activate` - Activate virtual environment
- `pip install torch --index-url https://download.pytorch.org/whl/cpu` - Install PyTorch
- `pip install transformers pydantic aiohttp mcp pytest-asyncio beautifulsoup4 psutil` - Install deps
- `ruff check .` - Lint code
- `black .` - Format code
- `mypy .` - Type checking
## Development
See [PLAN.md](PLAN.md) for detailed architecture and implementation roadmap.
### Phase 2 Features
- โ
**Adaptive Learning Engine** - Dynamic heuristic adjustment
- โ
**Feedback Collection** - Multi-channel feedback system
- โ
**Performance Tracking** - Real-time analytics and health scoring
- โ
**Data Models** - Centralized validation and serialization
- โ
**Router Integration** - New MCP endpoints for learning features
- โ
**Comprehensive Testing** - Full test coverage for adaptive components
### Phase 3 Features
- โ
**Workflow Optimizer** - Parallel execution, pattern recognition, auto-optimization
- โ
**Predictive Analytics Engine** - Performance prediction, proactive alerts, resource forecasting
- โ
**Knowledge Transfer System** - Cross-component learning, artifact sharing, similarity analysis
- โ
**Self-Healing System** - Enhanced error recovery, pattern recognition, resilience policies
- โ
**System Integration** - All Phase 3 components integrated with main server
- โ
**Comprehensive Testing** - Full test coverage for Phase 3 components
### Architecture Evolution
- **Phase 1**: Foundation - ACP self-modification and basic capabilities
- **Phase 2**: Intelligence - Adaptive learning and feedback systems
- **Phase 3**: Agency - Advanced workflow optimization, predictive capabilities, and self-healing
### Future Stretch Goals ๐
See [TODO.md](TODO.md) for planned enhancements:
- **Named Pipe Communication** - Faster startup and persistent context
- **MCP TaskMaster** - Stateful background task management
- **Enhanced Context Management** - Cross-call conversation context
- **Performance Optimization Suite** - Advanced monitoring and tuning