Skip to main content
Glama
README.md
# GreeumMCP

GreeumMCP is a Model Context Protocol (MCP) server implementation for the Greeum Memory Engine. It enables seamless integration of Greeum's powerful memory capabilities with Large Language Models (LLMs) that support the MCP standard, such as Claude.

## Features

- **Memory Management**: Store, retrieve, and search through long-term and short-term memories
- **Time-based Recall**: Search memories based on temporal references like "yesterday" or "two weeks ago"
- **Semantic Search**: Find memories based on semantic similarity
- **Memory Enrichment**: Automatically extract keywords, tags, and compute importance scores
- **Multiple Transport Options**: Supports stdio, HTTP, and WebSocket transports
- **Claude Desktop Integration**: Ready to use with Claude Desktop

## Installation

### 🚀 빠른 설치 (UV 사용 - 권장)

<details open>
<summary>설치 없이 바로 실행 (uvx)</summary>

```bash
# UV 설치 (처음 한 번만)
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

# GreeumMCP 실행 (설치 없이)
uvx greeummcp
```

</details>

### 📦 일반 설치 (pip)

<details>
<summary>Linux / macOS (bash / zsh)</summary>

```bash
# 1) 가상 환경(권장)
python3 -m venv venv && source venv/bin/activate

# 2) 최신 안정판 설치
pip install greeummcp

# 3) 개발 도구까지 설치하려면
pip install "greeummcp[dev]"
```

</details>

<details>
<summary>Windows (PowerShell)</summary>

```powershell
# 1) 가상 환경(권장)
python -m venv venv
.\venv\Scripts\Activate.ps1

# 2) 패키지 설치
pip install greeummcp
```

</details>

### 📋 필수 조건
- Python 3.10 이상
- `greeum` v0.6.1 이상은 greeummcp가 자동으로 의존성으로 설치합니다.
- (선택) C/C++ Build Tools – 일부 확장 기능에서 필요할 수 있습니다.

### ✅ 설치 확인

```bash
# pip 설치 시
greeummcp version

# uvx 사용 시
uvx greeummcp version
```

위 명령이 버전 문자열(예: `0.2.4`)을 출력하면 설치가 완료된 것입니다.

---
### 빠른 시작

```bash
# 기본 실행 (data 디렉토리는 ./data 사용)
greeummcp

# 커스텀 데이터 디렉토리 지정
greeummcp /path/to/data

# HTTP transport 사용
greeummcp --transport http --port 8000
```

---
### Claude Desktop 연동

#### 🌟 방법 1: UV 사용 (가장 간단)

<details open>
<summary>모든 OS 공통</summary>

```json
{
  "mcpServers": {
    "greeum_mcp": {
      "command": "uvx",
      "args": ["greeummcp"]
    }
  }
}
```

커스텀 데이터 디렉토리 지정:
```json
{
  "mcpServers": {
    "greeum_mcp": {
      "command": "uvx",
      "args": ["greeummcp", "/path/to/data"]
    }
  }
}
```

</details>

#### 📦 방법 2: pip 설치 후 사용

<details>
<summary>Windows</summary>

```json
{
  "mcpServers": {
    "greeum_mcp": {
      "command": "greeummcp.exe",
      "args": ["C:\\Users\\USERNAME\\greeum-data"]
    }
  }
}
```

기본 설정 (./data 사용):
```json
{
  "mcpServers": {
    "greeum_mcp": {
      "command": "greeummcp.exe"
    }
  }
}
```
</details>

<details>
<summary>macOS / Linux</summary>

```json
{
  "mcpServers": {
    "greeum_mcp": {
      "command": "greeummcp",
      "args": ["/home/username/greeum-data"]
    }
  }
}
```

기본 설정 (./data 사용):
```json
{
  "mcpServers": {
    "greeum_mcp": {
      "command": "greeummcp"
    }
  }
}
```
</details>

1. 위 설정을 `claude_desktop_config.json`에 추가합니다.
2. Claude Desktop 재시작 → 🔨 아이콘 클릭해 Tool 목록에 **greeum_mcp** 가 나타나는지 확인.

---
### Cursor IDE 연동
프로젝트 루트에 `.cursor/mcp.json` 파일을 생성:

```json
{
  "greeum_mcp": {
    "command": "greeummcp",
    "args": ["${workspaceFolder}/data"]
  }
}
```

저장 후 Cursor를 재시작하면 MCP 툴이 자동으로 로드됩니다.

---

## Quick Start

### Running as a Command-Line Tool

GreeumMCP can be run directly from the command line:

```bash
# Run with default settings (stdio transport, ./data directory)
greeummcp

# Specify custom data directory
greeummcp /path/to/data

# Using HTTP transport
greeummcp --transport http --port 8000

# Legacy command (still supported)
greeum_mcp --data-dir ./data --transport stdio
```

### Using as a Python Library

```python
from greeummcp import run_server

# Run with default settings
run_server()

# Run with custom settings
run_server(
    data_dir="./data",
    server_name="greeum_mcp",
    port=8000,
    transport="http",
    greeum_config={
        "ttl_short": 3600,  # 1 hour
        "ttl_medium": 86400,  # 1 day
        "ttl_long": 604800,  # 1 week
        "default_language": "auto"
    }
)
```

## Claude Desktop Integration

GreeumMCP can be used with Claude Desktop to provide memory capabilities to Claude. The package includes a helper script to set up the integration:

```bash
# Run the Claude Desktop integration helper
python examples/claude_desktop.py

# Create the Claude Desktop configuration file
python examples/claude_desktop.py --create --data-dir ./data
```

After setting up, restart Claude Desktop, and you should see the GreeumMCP tools available in the tools panel (hammer icon).

### Manual Configuration for Claude Desktop

You can also manually configure Claude Desktop to use GreeumMCP by creating a JSON configuration file:

1. Locate or create the Claude Desktop configuration file:
   - Windows: `%APPDATA%\Claude\claude_desktop_config.json`
   - macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
   - Linux: `~/.config/Claude/claude_desktop_config.json`

2. Add the GreeumMCP server configuration to this file:

#### Windows Example:
```json
{
    "mcpServers": {
        "greeum_mcp": {
            "command": "python",
            "args": [
                "-m", "greeummcp.server",
                "--data-dir", "C:\\Users\\USERNAME\\Documents\\greeum-data",
                "--transport", "stdio"
            ]
        }
    }
}
```

#### macOS/Linux Example:
```json
{
    "mcpServers": {
        "greeum_mcp": {
            "command": "python3",
            "args": [
                "-m", "greeummcp.server",
                "--data-dir", "/Users/USERNAME/Documents/greeum-data",
                "--transport", "stdio"
            ]
        }
    }
}
```

3. Make sure to replace `USERNAME` and adjust paths according to your system.
4. Restart Claude Desktop to apply the changes.
5. Verify that the tools are available by looking for the hammer icon in the Claude Desktop interface.

### Cursor Integration

To use GreeumMCP with Cursor, create a `.cursor/mcp.json` file in your project root:

```json
{
  "greeum_mcp": {
    "command": "python",
    "args": ["-m", "greeummcp.server", "--data-dir", "YOUR_DATA_DIR", "--transport", "stdio", "--server-name", "greeum_mcp"]
  }
}
```

#### Important Notes

- **Server naming**: Always use underscores (`_`) instead of hyphens (`-`) in server names to avoid MCP compatibility issues.
- **Data directory**: Use an absolute path for the data directory to ensure reliability.

### Verifying the Integration

To verify that GreeumMCP is working properly with Claude Desktop:

1. Click the hammer icon in Claude Desktop.
2. You should see GreeumMCP tools listed (like add_memory, query_memory, etc.).
3. Try adding a memory with a query like "Save this information: Claude was developed by Anthropic."
4. Then try retrieving it with "What information do you have about Claude?"

If you encounter issues:
- Check Claude Desktop logs in `~/Library/Logs/Claude/` (macOS) or `%APPDATA%\Claude\Logs` (Windows)
- Ensure the GreeumMCP server is properly installed and paths are correct
- Verify your configuration file has the correct syntax

---

## 🚀 Claude Code (claude.ai/code) 연결 가이드

Claude Code는 웹 기반 통합 개발 환경으로, MCP 서버를 통해 GreeumMCP와 연결할 수 있습니다.

### 📋 전제 조건

- Python 3.10 이상
- GreeumMCP 패키지 설치 완료
- Greeum 패키지 v0.6.0 이상

### 🔧 설정 방법

#### 1단계: 개발 서버 선택

GreeumMCP는 두 가지 서버 구현을 제공합니다:

**A. `minimal_mcp_server.py` (테스트용)**
- 빠른 연결 테스트를 위한 최소 구현
- 실제 메모리 저장 없이 모의 응답만 제공
- MCP 프로토콜 호환성 확인 목적

**B. `working_mcp_server.py` (실제 사용)**  
- 실제 Greeum 메모리 엔진과 연동
- 진짜 메모리 저장, 검색, STM 관리 기능
- 프로덕션 환경에서 사용 권장

#### 2단계: 필수 환경변수 설정

```bash
# 메모리 데이터 저장 디렉토리 (필수)
export GREEUM_DATA_DIR="/Users/dryrain/greeum-global"

# 로그 레벨 설정 (선택)
export GREEUM_LOG_LEVEL="INFO"

# Python 경로 확인 (필수)
which python3
# 출력 예: /usr/bin/python3 또는 /opt/homebrew/bin/python3
```

#### 3단계: 의존성 설치

```bash
# 가상환경 생성 (권장)
python3 -m venv venv-greeummcp
source venv-greeummcp/bin/activate  # Windows: venv-greeummcp\Scripts\activate

# GreeumMCP 및 의존성 설치
pip install greeummcp

# 또는 개발 버전으로 설치
pip install -e .

# Greeum 코어 엔진 설치 확인
pip install greeum[all]
```

#### 4단계: 로컬 테스트

```bash
# 1. 최소 서버로 기본 연결 테스트
cd /Users/dryrain/DevRoom/GreeumMCP
python3 minimal_mcp_server.py

# 2. 실제 작동 서버로 기능 테스트  
python3 working_mcp_server.py

# 3. 설치된 패키지로 테스트
greeummcp --data-dir /Users/dryrain/greeum-global
```

#### 5단계: Claude Code에서 MCP 연결

Claude Code에서 MCP 서버에 연결하는 방법:

1. **프로젝트 디렉토리에서 작업**
   ```bash
   cd /Users/dryrain/DevRoom/GreeumMCP
   ```

2. **working_mcp_server.py 실행**
   ```bash
   # 터미널에서 백그라운드 실행
   GREEUM_DATA_DIR="/Users/dryrain/greeum-global" python3 working_mcp_server.py &
   ```

3. **Claude Code에서 연결**
   - Claude Code 인터페이스에서 MCP 서버 연결 시도
   - 로컬 stdio 프로토콜로 `python3 working_mcp_server.py` 명령 사용
   - 데이터 디렉토리: `/Users/dryrain/greeum-global`

### 🛠️ 트러블슈팅 가이드

#### 자주 발생하는 문제와 해결법

**1. "ModuleNotFoundError: No module named 'greeum'" 오류**
```bash
# 해결: Greeum 패키지 설치
pip install greeum[all]

# 가상환경이 활성화되어 있는지 확인
which python3
pip list | grep greeum
```

**2. "Permission denied" 오류**
```bash
# 해결: 데이터 디렉토리 권한 설정
mkdir -p /Users/dryrain/greeum-global
chmod 755 /Users/dryrain/greeum-global

# 또는 사용자 홈 디렉토리 사용
export GREEUM_DATA_DIR="$HOME/greeum-data"
```

**3. MCP 서버 연결 실패**
```bash
# 디버깅: 서버 로그 확인
python3 working_mcp_server.py 2>&1 | tee server.log

# JSON-RPC 메시지 테스트
echo '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {}}' | python3 working_mcp_server.py
```

**4. 메모리 저장/검색 실패**
```bash
# 해결: 데이터베이스 초기화
rm -f /Users/dryrain/greeum-global/memory.db
rm -f /Users/dryrain/greeum-global/context_cache.json

# 새로운 데이터베이스로 재시작
python3 working_mcp_server.py
```

### 🧪 연결 테스트 방법

#### A. 최소 기능 테스트 (minimal_mcp_server.py)

```bash
# 1. 서버 시작
python3 minimal_mcp_server.py

# 2. 다른 터미널에서 테스트
echo '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {}}' | python3 minimal_mcp_server.py

# 3. 예상 응답:
# {"jsonrpc": "2.0", "id": 1, "result": {"protocolVersion": "2024-11-05", ...}}
```

#### B. 실제 기능 테스트 (working_mcp_server.py)

```bash
# 1. 환경변수 설정 후 서버 시작
export GREEUM_DATA_DIR="/Users/dryrain/greeum-global"
mkdir -p "$GREEUM_DATA_DIR"
python3 working_mcp_server.py

# 2. 메모리 추가 테스트
echo '{"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "add_memory", "arguments": {"content": "테스트 메모리입니다"}}}' | python3 working_mcp_server.py

# 3. 메모리 검색 테스트  
echo '{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "search_memory", "arguments": {"query": "테스트"}}}' | python3 working_mcp_server.py
```

### 📊 성공 확인 체크리스트

- [ ] Python 3.10+ 설치 확인
- [ ] GreeumMCP 패키지 설치 완료
- [ ] Greeum 코어 엔진 설치 완료
- [ ] 환경변수 `GREEUM_DATA_DIR` 설정
- [ ] 데이터 디렉토리 생성 및 권한 설정
- [ ] `minimal_mcp_server.py` 연결 테스트 성공
- [ ] `working_mcp_server.py` 기능 테스트 성공
- [ ] Claude Code에서 MCP 서버 연결 성공
- [ ] `add_memory` 도구 작동 확인
- [ ] `search_memory` 도구 작동 확인

### 💡 성능 최적화 팁

1. **데이터 디렉토리 최적화**
   ```bash
   # SSD 디스크 사용 권장
   export GREEUM_DATA_DIR="/Users/dryrain/greeum-ssd"
   
   # 대용량 메모리 사용 시 전용 디렉토리
   export GREEUM_DATA_DIR="/Volumes/ExternalSSD/greeum-data"
   ```

2. **메모리 관리 설정**
   ```python
   # working_mcp_server.py 수정 예시
   self.stm_manager = STMManager(db_manager=db_manager, ttl=7200)  # 2시간
   self.block_manager = BlockManager(db_manager=db_manager, use_faiss=True)  # FAISS 사용
   ```

3. **로깅 최적화**
   ```bash
   # 운영 환경에서는 로그 레벨 조정
   export GREEUM_LOG_LEVEL="WARNING"
   
   # 로그 파일로 저장
   python3 working_mcp_server.py 2>&1 | tee -a greeum-mcp.log
   ```

### 🎯 고급 사용법

#### 커스텀 메모리 설정

```python
# custom_mcp_server.py 생성 예시
class CustomGreeumMCPServer(WorkingGreeumMCPServer):
    def __init__(self, data_dir: str = None):
        super().__init__(data_dir)
        
        # 커스텀 TTL 설정
        self.custom_ttl = {
            'short': 1800,   # 30분
            'medium': 7200,  # 2시간  
            'long': 86400    # 24시간
        }
    
    def init_greeum(self):
        """커스텀 Greeum 초기화"""
        # 기본 초기화 실행
        super().init_greeum()
        
        # 추가 설정 적용
        self.stm_manager.default_ttl = self.custom_ttl['short']
```

이 가이드를 따라하면 Claude Code에서 GreeumMCP를 성공적으로 연결하고 사용할 수 있습니다.

## Memory Tools

GreeumMCP provides the following memory-related tools:

- **add_memory**: Add a new memory to long-term storage
- **query_memory**: Search memories by query text
- **retrieve_memory**: Retrieve a specific memory by ID
- **update_memory**: Update an existing memory
- **delete_memory**: Delete a memory by ID
- **search_time**: Search memories based on time references
- **generate_prompt**: Generate a prompt that includes relevant memories
- **extract_keywords**: Extract keywords from text
- **verify_chain**: Verify the integrity of the memory blockchain
- **server_status**: Get server status information

## Example Usage

### Interactive CLI

GreeumMCP includes an interactive CLI example for trying out the memory capabilities:

```bash
python examples/cli_example.py --data-dir ./data
```

This opens an interactive shell where you can:

```
greeum> add This is my first memory
Memory added with ID: 1

greeum> add This is my second memory about Python
Memory added with ID: 2

greeum> search Python
Found 1 results:

--- Result 1 ---
ID: 2
Content: This is my second memory about Python
Timestamp: 2023-07-01T12:34:56
Keywords: memory, Python, second
Importance: 0.65
```

## Development

### Project Structure

```
GreeumMCP/
├── greeummcp/                   # Main package
│   ├── __init__.py              # Package initialization
│   ├── server.py                # MCP server implementation
│   ├── tools/                   # MCP tools implementation
│   ├── resources/               # MCP resources implementation
│   ├── prompts/                 # MCP prompts implementation
│   └── adapters/                # Greeum integration adapters
├── examples/                    # Usage examples
├── tests/                       # Tests
├── README.md                    # Project documentation
├── setup.py                     # Package setup
└── requirements.txt             # Dependencies
```

### Running Tests

```bash
pip install -e ".[dev]"
pytest
```

## License

GreeumMCP is licensed under the MIT License.

## Acknowledgments

- GreeumMCP is built on the [Model Context Protocol](https://modelcontextprotocol.io) standard
- GreeumMCP uses the [Greeum Memory Engine](https://github.com/GreeumAI/Greeum) as its core component