Metadata-Version: 2.4
Name: enhanced-mcp-memory
Version: 2.5.2
Summary: Enterprise-grade MCP server with sequential thinking, project convention learning, and intelligent memory management
Home-page: https://github.com/cbunting99/enhanced-mcp-memory
Author: cbunting99
Author-email: cbunting99 <cbunting99@users.noreply.github.com>
Maintainer-email: cbunting99 <cbunting99@users.noreply.github.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/cbunting99/enhanced-mcp-memory
Project-URL: Repository, https://github.com/cbunting99/enhanced-mcp-memory
Project-URL: Issues, https://github.com/cbunting99/enhanced-mcp-memory/issues
Project-URL: Documentation, https://github.com/cbunting99/enhanced-mcp-memory#readme
Keywords: mcp,memory,ai,task-management,knowledge-graph,semantic-search,sequential-thinking,project-conventions,token-optimization
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Database
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fastmcp>=2.10.5
Requires-Dist: python-dotenv>=1.0.0
Requires-Dist: sentence-transformers>=2.2.0
Requires-Dist: numpy>=1.21.0
Requires-Dist: scipy>=1.7.0
Requires-Dist: filelock>=3.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
Requires-Dist: black>=22.0.0; extra == "dev"
Requires-Dist: isort>=5.0.0; extra == "dev"
Requires-Dist: flake8>=4.0.0; extra == "dev"
Dynamic: author
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

# Enhanced MCP Memory

> **⚡ Optimized for Claude Sonnet 4** - This MCP server works best with Claude Sonnet 4 for optimal performance and AI-powered features.

An enhanced MCP (Model Context Protocol) server for intelligent memory and task management, designed for AI assistants and development workflows. Features semantic search, automatic task extraction, knowledge graphs, and comprehensive project management.

## ✨ Key Features

### 🧠 Intelligent Memory Management
- **Semantic search** using sentence-transformers for natural language queries
- **Automatic memory classification** with importance scoring
- **Duplicate detection** and content deduplication
- **File path associations** for code-memory relationships
- **Knowledge graph relationships** with automatic similarity detection

### 🧬 Sequential Thinking Engine
- **Structured reasoning chains** with 5-stage process (analysis, planning, execution, validation, reflection)
- **Context management** with automatic token optimization
- **Conversation continuity** across sessions with intelligent summarization
- **Real-time token estimation** and compression (30-70% reduction)
- **Auto-extraction** of key points, decisions, and action items

### 📋 Advanced Task Management
- **Auto-task extraction** from conversations and code comments
- **Priority and category management** with validation
- **Status tracking** (pending, in_progress, completed, cancelled)
- **Task-memory relationships** in knowledge graph
- **Project-based organization**
- **Complex task decomposition** into manageable subtasks

### 🏗️ Project Convention Learning
- **Automatic environment detection** - OS, shell, tools, and runtime versions
- **Project type recognition** - Node.js, Python, Rust, Go, Java, MCP servers, etc.
- **Command pattern learning** - Extracts npm scripts, Makefile targets, and project commands
- **Tool configuration detection** - IDEs, linters, CI/CD, build tools, and testing frameworks
- **Dependency management** - Package managers, lock files, and installation commands
- **Smart command suggestions** - Corrects user commands based on project conventions
- **Windows-specific optimizations** - Proper path separators and command formats
- **Memory integration** - Stores learned conventions for AI context and future reference

### 📊 Performance Monitoring
- **Performance monitoring** with detailed metrics
- **Health checks** and system diagnostics
- **Automatic cleanup** of old data and duplicates
- **Database optimization** tools
- **Comprehensive logging** and error tracking
- **Token usage analytics** and optimization recommendations

### � Enterprise Features
- **Performance monitoring** with detailed metrics
- **Health checks** and system diagnostics
- **Automatic cleanup** of old data and duplicates
- **Database optimization** tools
- **Comprehensive logging** and error tracking
- **Token usage analytics** and optimization recommendations

### 🚀 Easy Deployment
- **Unified launcher** (`run_in_venv.py`) — wired into `[project.scripts]`, so `uvx enhanced-mcp-memory`, `uv tool install enhanced-mcp-memory`, and `pip install enhanced-mcp-memory` all flow through the launcher. From a checkout (`python run_in_venv.py`) it builds a private `~/enhanced-mcp-memory/.venv`; from an installed package it detects the outer venv and runs in place. No pollution of your system Python in either path.
- **Zero-configuration** startup with sensible defaults
- **Environment variable** configuration
- **Cross-platform** support (Windows, macOS, Linux)

## 🏗️ Project Structure

```
enhanced-mcp-memory/
├── mcp_server_enhanced.py    # Main MCP server with FastMCP integration
├── memory_manager.py         # Core memory/task logic and project detection
├── sequential_thinking.py    # Thinking chains and context optimization
├── database.py              # Database operations with retry mechanisms
├── run_in_venv.py           # Cross-platform venv launcher (run this)
├── requirements.txt         # Python dependencies
├── setup.py / pyproject.toml# Package configuration
├── data/                   # SQLite database storage
├── logs/                   # Application logs
```

## 🚀 Quick Start

The launcher (`run_in_venv.py`) is the single entry point — it's wired
into `[project.scripts]`, so every install path runs through it. The
launcher picks the right strategy for where it's invoked from:

| Invocation | What the launcher does |
|---|---|
| `uvx enhanced-mcp-memory` | Detects uvx's cache venv (`sys.prefix != base_prefix`), runs the server in place. No nested venv built on top of uvx's cache. |
| `uv tool install enhanced-mcp-memory` then `enhanced-mcp-memory` | Same as uvx: detects the tool venv, runs in place. |
| `pip install enhanced-mcp-memory` then `enhanced-mcp-memory` | Same: runs in the install's venv in place. |
| `python run_in_venv.py` (from a checkout) | Builds (or reuses) a private `~/enhanced-mcp-memory/.venv`, installs the package editable, re-execs the server inside. |

### Option 1: `uvx enhanced-mcp-memory` (Recommended)

```bash
uvx enhanced-mcp-memory
```

First launch is slow (it builds uvx's cache venv + downloads dependencies);
subsequent launches are a near-zero-overhead passthrough.

### Option 2: `python run_in_venv.py` (from a checkout)

```bash
git clone https://github.com/cbunting99/enhanced-mcp-memory.git
cd enhanced-mcp-memory
python run_in_venv.py
```

Use this when you want to hack on the server — the editable install
means source edits take effect after a re-launch.

### Useful launcher flags

```bash
python run_in_venv.py                # bootstrap (or reuse) + run
python run_in_venv.py --venv-path    # print the resolved venv path
python run_in_venv.py --data-dir     # print the resolved data dir path
python run_in_venv.py --upgrade      # force reinstall into the venv
python run_in_venv.py --uninstall    # remove venv + database + logs
python run_in_venv.py --uninstall --yes   # same, skip the confirmation
```

Override locations with environment variables if needed:

```bash
ENHANCED_MCP_MEMORY_VENV=/some/other/path/.venv
ENHANCED_MCP_MEMORY_DATA=/some/other/data/dir
```

### Option 3: Development setup (system Python, no venv)

```bash
git clone https://github.com/cbunting99/enhanced-mcp-memory.git
cd enhanced-mcp-memory
pip install -r requirements.txt
python mcp_server_enhanced.py
```

## ⚙️ MCP Configuration

The MCP server is launched via the same `enhanced-mcp-memory` entry point
regardless of install method — point your client at whichever form fits:

### `uvx` (recommended for end users):

```json
{
  "mcpServers": {
    "memory-manager": {
      "command": "uvx",
      "args": ["enhanced-mcp-memory"],
      "env": {
        "LOG_LEVEL": "INFO",
        "MAX_MEMORY_ITEMS": "1000",
        "ENABLE_AUTO_CLEANUP": "true"
      }
    }
  }
}
```

### Local checkout (developer / hacking):

```json
{
  "mcpServers": {
    "memory-manager": {
      "command": "python",
      "args": ["run_in_venv.py"],
      "cwd": "/path/to/enhanced-mcp-memory",
      "env": {
        "LOG_LEVEL": "INFO",
        "MAX_MEMORY_ITEMS": "1000",
        "ENABLE_AUTO_CLEANUP": "true"
      }
    }
  }
}
```

## 🛠️ Available Tools

### Core Memory Tools
- `get_memory_context(query)` - Get relevant memories and context
- `list_memories(memory_type, project_id, limit)` - List stored memories with optional filters
- `create_task(title, description, priority, category)` - Create new tasks
- `get_tasks(status, limit)` - Retrieve tasks with filtering
- `get_project_summary()` - Get comprehensive project overview

### Sequential Thinking Tools
- `start_thinking_chain(objective)` - Begin structured reasoning process
- `add_thinking_step(chain_id, stage, title, content, reasoning)` - Add reasoning steps
- `get_thinking_chain(chain_id)` - Retrieve complete thinking chain
- `list_thinking_chains(limit)` - List recent thinking chains

### Context Management Tools  
- `create_context_summary(content, key_points, decisions, actions)` - Compress context for token optimization
- `start_new_chat_session(title, objective, continue_from)` - Begin new conversation with optional continuation
- `consolidate_current_session()` - Compress current session for handoff
- `get_optimized_context(max_tokens)` - Get token-optimized context
- `estimate_token_usage(text)` - Estimate token count for planning

### Enterprise Auto-Processing
- `auto_process_conversation(content, interaction_type)` - Extract memories and tasks automatically
- `decompose_task(prompt)` - Break complex tasks into subtasks

### Project Convention Tools
- `auto_learn_project_conventions(project_path)` - Automatically detect and learn project patterns
- `get_project_conventions_summary()` - Get formatted summary of learned conventions
- `suggest_correct_command(user_command)` - Suggest project-appropriate command corrections
- `remember_project_pattern(pattern_type, pattern, description)` - Manually store project patterns
- `update_memory_context()` - Refresh memory context with latest project conventions

### System Management Tools
- `health_check()` - Check server health and connectivity
- `get_performance_stats()` - Get detailed performance metrics
- `cleanup_old_data(days_old)` - Clean up old memories and tasks
- `optimize_memories()` - Remove duplicates and optimize storage
- `get_database_stats()` - Get comprehensive database statistics

## 🏗️ Project Convention Learning

The Enhanced MCP Memory Server automatically learns and remembers project-specific conventions to prevent AI assistants from suggesting incorrect commands or approaches:

### Automatic Detection
- **Operating System**: Windows vs Unix, preferred shell and commands
- **Project Type**: Node.js, Python, Rust, Go, Java, MCP servers, FastAPI, Django
- **Development Tools**: IDEs, linters, formatters, CI/CD configurations
- **Package Management**: npm, yarn, pip, poetry, cargo, go modules
- **Build Systems**: Vite, Webpack, Make, batch scripts, shell scripts

### Smart Command Suggestions
```bash
# Instead of generic commands, suggests project-specific ones:
User types: "node server.js"
AI suggests: "Use 'npm run dev' instead for this project"

User types: "python main.py" 
AI suggests: "Use 'uvicorn main:app --reload' for this FastAPI project"
```

### Windows Optimization
- Automatically detects Windows environment
- Uses `cmd.exe` and Windows-appropriate path separators
- Suggests Windows-compatible commands (e.g., `dir` instead of `ls`)
- Handles Windows-specific Python and Node.js patterns

### Memory Integration
All learned conventions are stored as high-importance memories that:
- Appear in AI context for every interaction
- Persist across sessions and project switches
- Include environment warnings and project-specific guidance
- Prevent repeated incorrect command suggestions

## 🔧 Configuration Options

Configure via environment variables:

| Variable | Default | Description |
|----------|---------|-------------|
| `LOG_LEVEL` | `INFO` | Logging level (DEBUG, INFO, WARNING, ERROR) |
| `MAX_MEMORY_ITEMS` | `1000` | Maximum memories per project |
| `MAX_CONTEXT_TOKENS` | `8000` | Token threshold for auto-compression |
| `CLEANUP_INTERVAL_HOURS` | `24` | Auto-cleanup interval |
| `ENABLE_AUTO_CLEANUP` | `true` | Enable automatic cleanup |
| `MAX_CONCURRENT_REQUESTS` | `5` | Max concurrent requests |
| `REQUEST_TIMEOUT` | `30` | Request timeout in seconds |
| `DATA_DIR` | ~/enhanced-mcp-memory | Where to store data and logs |

## 🧪 Testing

This package is production-ready and does not include a test suite in the distributed version. For development or CI, refer to the repository for test scripts and additional resources.

## 📊 Performance & Monitoring

The server includes built-in performance tracking:

- **Response time monitoring** for all tools
- **Success rate tracking** with error counts
- **Memory usage statistics**
- **Database performance metrics**
- **Automatic health checks**

Access via the `get_performance_stats()` and `health_check()` tools.

## 🗄️ Database

- **SQLite** for reliable, file-based storage
- **Automatic schema migrations** for updates
- **Comprehensive indexing** for fast queries
- **Built-in backup and optimization** tools
- **Cross-platform compatibility**

Default location: `./data/mcp_memory.db`

## 🔍 Semantic Search

Powered by sentence-transformers for intelligent memory retrieval:

- **Natural language queries** - "Find memories about database optimization"
- **Similarity-based matching** using embeddings
- **Configurable similarity thresholds**
- **Automatic model downloading** (~90MB on first run)

## 🧠 Sequential Thinking

Structured reasoning system:

- **5-stage thinking process**: Analysis → Planning → Execution → Validation → Reflection
- **Token optimization**: Real-time estimation and compression (30-70% reduction)
- **Context continuity**: Intelligent session handoffs with preserved context
- **Auto-extraction**: Automatically identifies key points, decisions, and action items
- **Performance tracking**: Monitor reasoning chains and optimization metrics

## 💼 Token Management

Advanced context optimization for high-scale deployments:

- **Smart compression**: Pattern-based extraction preserves essential information
- **Token estimation**: Real-time calculation for planning and budgeting
- **Context summarization**: Automatic conversion of conversations to actionable summaries
- **Session consolidation**: Seamless handoffs between conversation sessions
- **Performance analytics**: Detailed metrics on compression ratios and response times

## 📝 Logging

Comprehensive logging system:

- **Daily log rotation** in `./logs/` directory
- **Structured logging** with timestamps and levels
- **Performance tracking** integrated
- **Error tracking** with stack traces

## 🤝 Contributing

1. Fork the repository
2. Create a feature branch
3. Add tests for new functionality
4. Ensure all tests pass
5. Submit a pull request

## 📄 License

MIT License - see LICENSE file for details.

## 🆘 Support

- **Issues**: [GitHub Issues](https://github.com/cbunting99/enhanced-mcp-memory/issues)
- **Documentation**: [README](https://github.com/cbunting99/enhanced-mcp-memory#readme)
- **Discussions**: [GitHub Discussions](https://github.com/cbunting99/enhanced-mcp-memory/discussions)

## 🏷️ Version History

- **v2.0.2** - Updated package build configuration and license compatibility fixes
- **v2.0.1** - Enhanced features with sequential thinking and project conventions
- **v1.2.0** - Enhanced MCP server with performance monitoring and health checks
- **v1.1.0** - Added semantic search and knowledge graph features
- **v1.0.0** - Initial release with basic memory and task management
