Skip to main content
Glama
srieg

PAI Memory MCP Server

by srieg
README.md
# PAI Memory MCP Server

Semantic and keyword search across your AI work sessions, learnings, reflections, failures, research, and relationships. Built for [PAI](https://github.com/danielmiessler/PAI) (Personal AI Infrastructure).

## What It Does

Indexes your PAI `MEMORY/` directory into a searchable SQLite database with:

- **Keyword search** via FTS5 (full-text search) — works offline, no dependencies
- **Semantic search** via LM Studio embeddings — meaning-based retrieval using `nomic-embed-text-v1.5`
- **MCP server** exposing 7 tools for cross-tool access via Model Context Protocol

## Supported Memory Types

| Type | Source | Description |
|------|--------|-------------|
| `work` | `MEMORY/WORK/` | Work sessions with META.yaml, tasks, and markdown notes |
| `learning` | `MEMORY/LEARNING/ALGORITHM/`, `SYSTEM/` | Algorithm execution and system learnings |
| `reflection` | `MEMORY/LEARNING/REFLECTIONS/` | JSONL self-assessment after each task |
| `rating` | `MEMORY/LEARNING/SIGNALS/` | JSONL session ratings with sentiment |
| `failure` | `MEMORY/LEARNING/FAILURES/` | Context dumps from low-rated sessions |
| `research` | `MEMORY/RESEARCH/` | Research output files |
| `relationship` | `MEMORY/RELATIONSHIP/` | Relationship memory notes |

## Installation

```bash
cd ~/.claude/MCPs/pai-memory
bun install
```

## CLI Usage

```bash
# Index all MEMORY/ content into SQLite
bun cli.ts index

# Search (semantic if LM Studio running, keyword fallback)
bun cli.ts search "hook performance"

# Generate embeddings via LM Studio
bun cli.ts embed

# Show database statistics
bun cli.ts stats
```

## MCP Tools

When registered as an MCP server, exposes these tools:

| Tool | Description |
|------|-------------|
| `memory_search` | Semantic/keyword search across all memory types |
| `memory_recent_work` | List recent work sessions with status filter |
| `memory_recent_learnings` | List recent learnings with category filter |
| `memory_get_work` | Get full details of a specific work entry |
| `memory_stats` | Database statistics — entry counts, size, embedding coverage |
| `memory_failures` | List recent failure analyses |
| `memory_reflections` | List algorithm performance reflections |

### MCP Registration

Add to your `.mcp.json`:

```json
{
  "mcpServers": {
    "pai-memory": {
      "command": "bun",
      "args": ["run", "mcp-server.ts"],
      "cwd": "/path/to/pai-memory"
    }
  }
}
```

## Architecture

```
cli.ts              CLI entry point (index, search, embed, stats)
mcp-server.ts       MCP server (7 tools via StdioServerTransport)
src/
  types.ts          Shared types (MemoryEntry, SearchResult, MemoryStats)
  db.ts             SQLite layer (FTS5 + cosine similarity + embeddings)
  memory-reader.ts  Filesystem parser (YAML, JSON, JSONL, Markdown)
  search.ts         Unified search (semantic first, keyword fallback)
  embedder.ts       LM Studio embedding client (nomic-embed-text-v1.5)
data/
  pai-memory.db     SQLite database (generated, not committed)
```

## Requirements

- [Bun](https://bun.sh) runtime
- PAI with populated `MEMORY/` directory
- Optional: [LM Studio](https://lmstudio.ai) with `nomic-embed-text-v1.5` for semantic search

## License

MIT