prism-mcp-server 1.5.1 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +316 -849
  2. package/{src/config.ts → dist/config.js} +32 -23
  3. package/dist/dashboard/server.js +94 -0
  4. package/dist/dashboard/ui.js +444 -0
  5. package/dist/server.js +591 -0
  6. package/dist/storage/index.js +51 -0
  7. package/dist/storage/interface.js +21 -0
  8. package/dist/storage/sqlite.js +729 -0
  9. package/dist/storage/supabase.js +180 -0
  10. package/dist/sync/factory.js +33 -0
  11. package/dist/sync/index.js +31 -0
  12. package/dist/sync/sqliteSync.js +92 -0
  13. package/dist/sync/supabaseSync.js +83 -0
  14. package/dist/templates/codeMode.js +168 -0
  15. package/dist/tools/compactionHandler.js +172 -0
  16. package/dist/tools/definitions.js +314 -0
  17. package/dist/tools/handlers.js +235 -0
  18. package/{src/tools/index.ts → dist/tools/index.js} +2 -5
  19. package/dist/tools/sessionMemoryDefinitions.js +469 -0
  20. package/dist/tools/sessionMemoryHandlers.js +981 -0
  21. package/dist/utils/autoCapture.js +71 -0
  22. package/dist/utils/braveApi.js +217 -0
  23. package/dist/utils/briefing.js +68 -0
  24. package/dist/utils/embeddingApi.js +89 -0
  25. package/{src/utils/executor.ts → dist/utils/executor.js} +7 -21
  26. package/dist/utils/git.js +72 -0
  27. package/dist/utils/googleAi.js +88 -0
  28. package/dist/utils/keywordExtractor.js +182 -0
  29. package/dist/utils/supabaseApi.js +137 -0
  30. package/package.json +25 -9
  31. package/.gitmodules +0 -3
  32. package/Dockerfile +0 -30
  33. package/benchmark.ts +0 -172
  34. package/call_chrome_mcp.py +0 -96
  35. package/docker-compose.yml +0 -67
  36. package/execute_via_chrome_mcp.py +0 -133
  37. package/gmail_auth_test.py +0 -29
  38. package/gmail_list_latest_5.py +0 -27
  39. package/index.ts +0 -37
  40. package/list_chrome_tools.py +0 -70
  41. package/patch_cgc_mcp.py +0 -90
  42. package/repomix-output.xml +0 -9
  43. package/run_server.sh +0 -9
  44. package/server.json +0 -78
  45. package/src/server.ts +0 -638
  46. package/src/tools/compactionHandler.ts +0 -313
  47. package/src/tools/definitions.ts +0 -367
  48. package/src/tools/handlers.ts +0 -261
  49. package/src/tools/sessionMemoryDefinitions.ts +0 -437
  50. package/src/tools/sessionMemoryHandlers.ts +0 -774
  51. package/src/utils/braveApi.ts +0 -375
  52. package/src/utils/embeddingApi.ts +0 -97
  53. package/src/utils/googleAi.ts +0 -107
  54. package/src/utils/keywordExtractor.ts +0 -207
  55. package/src/utils/supabaseApi.ts +0 -194
  56. package/supabase/migrations/015_session_memory.sql +0 -145
  57. package/supabase/migrations/016_knowledge_accumulation.sql +0 -315
  58. package/supabase/migrations/017_ledger_compaction.sql +0 -74
  59. package/supabase/migrations/018_semantic_search.sql +0 -110
  60. package/supabase/migrations/019_concurrency_control.sql +0 -320
  61. package/supabase/migrations/020_multi_tenant_rls.sql +0 -459
  62. package/test_cross_mcp.js +0 -393
  63. package/test_mcp_schema.js +0 -83
  64. package/tests/test_knowledge_system.js +0 -319
  65. package/tsconfig.json +0 -16
  66. package/vertex-ai/test_claude_vertex.py +0 -78
  67. package/vertex-ai/test_gemini_vertex.py +0 -39
  68. package/vertex-ai/test_hybrid_search_pipeline.ts +0 -296
  69. package/vertex-ai/test_pipeline_benchmark.ts +0 -251
  70. package/vertex-ai/test_realworld_comparison.ts +0 -290
  71. package/vertex-ai/verify_discovery_engine.ts +0 -72
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Prism MCP — Persistent Memory for Claude Desktop, Cursor & AI Agents
1
+ # Prism MCP — The Mind Palace for AI Agents 🧠
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/prism-mcp-server?color=cb0000&label=npm)](https://www.npmjs.com/package/prism-mcp-server)
4
4
  [![MCP Registry](https://img.shields.io/badge/MCP_Registry-listed-00ADD8?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZmlsbD0id2hpdGUiIGQ9Ik0xMiAyTDIgN2wxMCA1IDEwLTUtMTAtNXpNMiAxN2wxMCA1IDEwLTV2LTJMMTI0djJMMiA5djh6Ii8+PC9zdmc+)](https://registry.modelcontextprotocol.io)
@@ -8,71 +8,55 @@
8
8
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-3178C6?logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
9
9
  [![Node.js](https://img.shields.io/badge/Node.js-18+-339933?logo=node.js&logoColor=white)](https://nodejs.org/)
10
10
 
11
- > **Give your AI agent memory that survives between sessions.** Prism MCP is a Model Context Protocol server that adds **persistent session memory**, **progressive context loading**, and **multi-engine search** to Claude Desktop, Cursor, Windsurf, and any MCP-compatible client. No more re-explaining your project every time you start a new chat.
11
+ > **Your AI agent's memory that survives between sessions.** Prism MCP is a Model Context Protocol server that gives Claude Desktop, Cursor, Windsurf, and any MCP client **persistent memory**, **time travel**, **visual context**, **multi-agent sync**, and **multi-engine search** all running locally with zero cloud dependencies.
12
12
  >
13
- > Built with **semantic search (pgvector)**, **optimistic concurrency control**, **MCP Prompts & Resources**, **auto-compaction**, and **multi-tenant RLS** on Supabase free tier.
13
+ > Built with **SQLite + F32_BLOB vector search**, **optimistic concurrency control**, **MCP Prompts & Resources**, **auto-compaction**, **Gemini-powered Morning Briefings**, and optional **Supabase cloud sync**.
14
14
 
15
15
  ---
16
16
 
17
- ## What's New in v1.5.0
17
+ ## What's New in v2.0 "Mind Palace" 🧠
18
+
19
+ Prism MCP has been completely rebuilt from the ground up to support **local-first workflows**, **visual agent memory**, and **multi-client synchronization**.
18
20
 
19
21
  | Feature | Description |
20
22
  |---|---|
21
- | 🧠 **MCP Prompts** | `/resume_session` slash command inject context before the LLM thinks. Zero tool calls. |
22
- | 📎 **MCP Resources** | Attach `memory://project/handoff` via paperclip auto-refresh on state changes. |
23
- | 🔒 **Optimistic Concurrency** | Version-tracked handoffs prevent multi-client data loss. |
24
- | 🧹 **Ledger Compaction** | Gemini-powered rollup of old entries keeps ledger lean with soft-delete archiving. |
25
- | 🔍 **Semantic Search** | pgvector embeddings find sessions by meaning, not just keywords. |
26
- | ♻️ **Resource Subscriptions** | Attached memory auto-refreshes when handoff state changes mid-conversation. |
27
- | 🛡️ **Multi-Tenant RLS** | `PRISM_USER_ID` env var Row Level Security isolates data per user on shared Supabase. |
23
+ | 🏠 **Local-First SQLite** | Run Prism entirely locally with zero cloud dependencies. Full vector search (libSQL F32_BLOB) and FTS5 included. |
24
+ | 🔮 **Mind Palace UI** | A beautiful glassmorphism dashboard at `localhost:3000` to inspect your agent's memory, visual vault, and Git drift. |
25
+ | 🕰️ **Time Travel** | `memory_history` and `memory_checkout` act like `git revert` for your agent's brain — full version history with OCC. |
26
+ | 🖼️ **Visual Memory** | Agents can save screenshots to a local media vault. Auto-capture mode snapshots your local dev server on every handoff save. |
27
+ | 📡 **Agent Telepathy** | Multi-client sync: if your agent in Cursor saves state, Claude Desktop gets a live notification instantly. |
28
+ | 🌅 **Morning Briefing** | Gemini auto-synthesizes a 3-bullet action plan if it's been >4 hours since your last session. |
29
+ | 📝 **Code Mode Templates** | 8 pre-built QuickJS extraction templates for GitHub, Jira, OpenAPI, Slack, CSV, and DOM parsing — zero reasoning tokens. |
30
+ | 🔍 **Reality Drift Detection** | Prism captures Git state on save and warns if files changed outside the agent's view. |
28
31
 
29
32
  ---
30
33
 
31
- ## How Prism MCP Compares
34
+ ## Quick Start (Zero Config — Local Mode)
32
35
 
33
- | Capability | **Prism MCP** | **Mem0** | **Zep** | **Basic Memory** |
34
- |---|---|---|---|---|
35
- | **Architecture** | MCP-native (single npm package) | Standalone service + MCP adapter | Standalone service + API | MCP-native (local files) |
36
- | **Storage** | Supabase (PostgreSQL) | Hybrid (vector + graph DBs) | PostgreSQL + Neo4j | Local markdown files |
37
- | **Cold Start Fix** | ✅ MCP Prompts + Resources inject context before LLM thinks | ❌ Requires tool call | ❌ Requires tool call | ❌ Requires tool call |
38
- | **Progressive Loading** | ✅ quick / standard / deep levels | ❌ All-or-nothing | ❌ Fixed context window | ❌ All-or-nothing |
39
- | **Semantic Search** | ✅ pgvector + HNSW | ✅ Qdrant/Chroma | ✅ Built-in embeddings | ❌ No embeddings |
40
- | **Concurrency Control** | ✅ OCC with version tracking | ❌ Last write wins | ❌ Last write wins | ❌ Single user only |
41
- | **Auto-Compaction** | ✅ Gemini-powered rollup | ❌ Manual management | ✅ Auto-summarization | ❌ No compaction |
42
- | **Resource Subscriptions** | ✅ Live refresh on state change | ❌ Not MCP-native | ❌ Not MCP-native | ❌ Not supported |
43
- | **Knowledge Accumulation** | ✅ Auto-extracted keywords + categories | ✅ User/agent memories | ✅ Fact extraction | ❌ Manual tagging |
44
- | **Infrastructure Cost** | Free tier (Supabase + Gemini) | Free tier available, paid for scale | Self-hosted or cloud ($$$) | Free (local only) |
45
- | **Setup Complexity** | 2 env vars (Supabase URL + Key) | Docker + API keys + vector DB | Docker + PostgreSQL + Neo4j | No setup needed |
46
- | **Multi-Project** | ✅ Built-in project isolation | ✅ User-scoped memories | ✅ Session-scoped | ❌ Single knowledge base |
47
- | **Multi-Tenant RLS** | ✅ user_id + RLS policies | ❌ Not built-in | ❌ Not built-in | ❌ Single user only |
48
-
49
- > **When to choose Prism MCP**: You want MCP-native memory with zero infrastructure overhead, progressive context loading, and enterprise features (OCC, compaction, semantic search) that work directly in Claude Desktop — without running separate services.
36
+ Get the MCP server running with Claude Desktop or Cursor in **under 60 seconds**. No API keys required for basic local memory!
50
37
 
51
- ---
52
-
53
- ## Overview
38
+ ### Option A: npx (Fastest)
54
39
 
55
- Prism MCP is a unified AI agent platform with two core pillars:
40
+ Add this to your `claude_desktop_config.json` or `.cursor/mcp.json`:
56
41
 
57
- 1. **Session Memory & Knowledge System** — Persistent session memory with progressive context loading, MCP Prompts for cold-start fix, MCP Resources for zero-tool-call context, semantic search via pgvector embeddings, optimistic concurrency control, auto-compaction, cross-project knowledge transfer, and selective memory pruning
58
- 2. **Multi-Engine Search & Analysis** — Brave Search + Vertex AI Discovery Engine hybrid pipeline with 94% context reduction, Gemini research analysis, and sandboxed code transforms
42
+ ```json
43
+ {
44
+ "mcpServers": {
45
+ "prism-mcp": {
46
+ "command": "npx",
47
+ "args": ["-y", "prism-mcp-server"]
48
+ }
49
+ }
50
+ }
51
+ ```
59
52
 
60
- | Capability | Implementation |
61
- |---|---|
62
- | **Session Memory & Knowledge** | Progressive context loading (quick / standard / deep), MCP Prompts (/resume_session), MCP Resources (memory://), OCC (version tracking), ledger compaction, semantic search (pgvector), knowledge accumulation, and memory pruning via Supabase |
63
- | **Multi-Engine Search** | Brave Search (real-time web) + Vertex AI Discovery Engine (curated enterprise index) with hybrid merge/dedup pipeline |
64
- | **MCP Server Architecture** | Multi-tool server with `@modelcontextprotocol/sdk`, structured request handling, MCP Prompts, Resources with subscriptions, and extensible tool registration |
65
- | **LLM Integration** | Claude Desktop, Google Gemini, and Claude-on-Vertex AI with secure prompt patterns |
66
- | **API Orchestration** | Brave Search, Gemini, Gmail, Chrome DevTools Protocol, GCP Discovery Engine, and Supabase REST APIs |
67
- | **Code-Mode Transforms** | Sandboxed JavaScript extraction over raw JSON/CSV payloads — 85-95% token reduction |
68
- | **Security & IP Protection** | GCP Application Default Credentials, OAuth 2.0, encrypted credential management, env-based secrets |
69
- | **Testing & Validation** | Cross-MCP integration tests, Vertex AI verification scripts, schema validation, and benchmarks |
53
+ That's it **zero env vars needed** for local memory, Mind Palace dashboard, Time Travel, and Telepathy.
70
54
 
71
- ## Quick Start
55
+ > **Optional API keys:** Add `BRAVE_API_KEY` for web search, `GOOGLE_API_KEY` for semantic search + Morning Briefings + paper analysis. See [Environment Variables](#environment-variables) for the full list.
72
56
 
73
- Get the MCP server running with Claude Desktop in under 2 minutes:
57
+ ### Option B: Cloud Sync Mode (Supabase)
74
58
 
75
- ### Option A: npx (Fastest No Clone Needed)
59
+ To share memory across multiple machines or teams, switch to Supabase:
76
60
 
77
61
  ```json
78
62
  {
@@ -81,16 +65,16 @@ Get the MCP server running with Claude Desktop in under 2 minutes:
81
65
  "command": "npx",
82
66
  "args": ["-y", "prism-mcp-server"],
83
67
  "env": {
84
- "BRAVE_API_KEY": "your-brave-api-key"
68
+ "PRISM_STORAGE": "supabase",
69
+ "SUPABASE_URL": "https://your-project.supabase.co",
70
+ "SUPABASE_KEY": "your-supabase-anon-key"
85
71
  }
86
72
  }
87
73
  }
88
74
  }
89
75
  ```
90
76
 
91
- Paste into your Claude Desktop config and restart. That's it.
92
-
93
- ### Option B: Clone & Build (Full Control)
77
+ ### Option C: Clone & Build (Full Control)
94
78
 
95
79
  ```bash
96
80
  git clone https://github.com/dcostenco/prism-mcp.git
@@ -99,54 +83,71 @@ npm install
99
83
  npm run build
100
84
  ```
101
85
 
102
- Then add to your `claude_desktop_config.json`:
86
+ Then add to your MCP config:
103
87
 
104
88
  ```json
105
89
  {
106
90
  "mcpServers": {
107
91
  "prism-mcp": {
108
92
  "command": "node",
109
- "args": ["/absolute/path/to/prism-mcp/build/server.js"],
93
+ "args": ["/absolute/path/to/prism-mcp/dist/server.js"],
110
94
  "env": {
111
95
  "BRAVE_API_KEY": "your-brave-api-key",
112
- "GOOGLE_API_KEY": "your-google-gemini-key",
113
- "SUPABASE_URL": "https://your-project.supabase.co",
114
- "SUPABASE_KEY": "your-supabase-anon-key",
115
- "PRISM_USER_ID": "your-unique-user-id"
96
+ "GOOGLE_API_KEY": "your-google-gemini-key"
116
97
  }
117
98
  }
118
99
  }
119
100
  }
120
101
  ```
121
102
 
122
- > **Note:** Only `BRAVE_API_KEY` is required. All other keys are optional and enable additional tools (Gemini analysis, session memory, etc.)
103
+ ### Restart your MCP client. That's it all tools are now available.
123
104
 
124
- ### 3. Restart Claude Desktop
105
+ ---
125
106
 
126
- That's it all tools are now available in Claude.
107
+ ## 🔮 The Mind Palace Dashboard
127
108
 
128
- ### Alternative: Local PostgreSQL (Docker)
109
+ Prism MCP spins up a lightweight, zero-dependency HTTP server alongside the MCP stdio process. No frameworks, no build step — just pure glassmorphism CSS served as a template literal.
129
110
 
130
- If you prefer local PostgreSQL instead of Cloud Supabase:
111
+ Open **`http://localhost:3000`** in your browser to see exactly what your AI agent is thinking:
131
112
 
132
- ```bash
133
- docker compose up -d # Start PostgreSQL + PostgREST
134
- # Run all migrations:
135
- cat supabase/migrations/*.sql | docker compose exec -T db psql -U prism -d prism_mcp
136
- ```
113
+ - **Current State & TODOs** — See the exact context injected into the LLM's prompt
114
+ - **Git Drift Detection** Alerts you if you've modified code outside the agent's view
115
+ - **Morning Briefing** — AI-synthesized action plan from your last sessions
116
+ - **Time Travel Timeline** Browse historical handoff states and revert any version
117
+ - **Visual Memory Vault** — Browse UI screenshots and auto-captured HTML states
118
+ - **Session Ledger** — Full audit trail of every decision your agent has made
137
119
 
138
- Then set `SUPABASE_URL=http://localhost:3000` in your MCP config.
120
+ The dashboard auto-discovers all your projects and updates in real time.
121
+
122
+ ---
123
+
124
+ ## How Prism MCP Compares
125
+
126
+ | Capability | **Prism MCP** | **Mem0** | **Zep** | **Basic Memory** |
127
+ |---|---|---|---|---|
128
+ | **Architecture** | MCP-native (single npm package) | Standalone service + MCP adapter | Standalone service + API | MCP-native (local files) |
129
+ | **Storage** | SQLite (local) or Supabase (cloud) | Hybrid (vector + graph DBs) | PostgreSQL + Neo4j | Local markdown files |
130
+ | **Local-First** | ✅ Full SQLite mode, zero cloud | ❌ Requires cloud/Docker | ❌ Requires PostgreSQL | ✅ Local files |
131
+ | **Visual Dashboard** | ✅ Mind Palace UI at localhost:3000 | ❌ No UI | ❌ No UI | ❌ No UI |
132
+ | **Time Travel** | ✅ Version history + checkout | ❌ No versioning | ❌ No versioning | ❌ No versioning |
133
+ | **Multi-Agent Sync** | ✅ Telepathy (realtime IPC/CDC) | ❌ Siloed | ❌ Siloed | ❌ Single user |
134
+ | **Auto-Capture** | ✅ HTML snapshots of dev server | ❌ Text only | ❌ Text only | ❌ Text only |
135
+ | **Cold Start Fix** | ✅ MCP Prompts + Resources | ❌ Requires tool call | ❌ Requires tool call | ❌ Requires tool call |
136
+ | **Progressive Loading** | ✅ quick / standard / deep | ❌ All-or-nothing | ❌ Fixed window | ❌ All-or-nothing |
137
+ | **Semantic Search** | ✅ F32_BLOB vectors (local) or pgvector (cloud) | ✅ Qdrant/Chroma | ✅ Built-in | ❌ None |
138
+ | **Concurrency Control** | ✅ OCC with version tracking | ❌ Last write wins | ❌ Last write wins | ❌ Single user |
139
+ | **Setup Complexity** | Zero config (local mode) | Docker + API keys + vector DB | Docker + PostgreSQL + Neo4j | No setup needed |
139
140
 
140
141
  ---
141
142
 
142
143
  ## Integration Examples
143
144
 
144
- Copy-paste configs for popular MCP clients. All configs use the `npx` method — replace with the `node` path if you cloned the repo.
145
+ Copy-paste configs for popular MCP clients. All configs use the `npx` method.
145
146
 
146
147
  <details>
147
- <summary><strong>Cursor</strong></summary>
148
+ <summary><strong>Claude Desktop</strong></summary>
148
149
 
149
- Add to `.cursor/mcp.json` in your project root (or `~/.cursor/mcp.json` for global):
150
+ Add to your `claude_desktop_config.json`:
150
151
 
151
152
  ```json
152
153
  {
@@ -154,11 +155,7 @@ Add to `.cursor/mcp.json` in your project root (or `~/.cursor/mcp.json` for glob
154
155
  "prism-mcp": {
155
156
  "command": "npx",
156
157
  "args": ["-y", "prism-mcp-server"],
157
- "env": {
158
- "BRAVE_API_KEY": "your-brave-api-key",
159
- "SUPABASE_URL": "https://your-project.supabase.co",
160
- "SUPABASE_KEY": "your-supabase-anon-key"
161
- }
158
+ "env": {}
162
159
  }
163
160
  }
164
161
  }
@@ -167,9 +164,9 @@ Add to `.cursor/mcp.json` in your project root (or `~/.cursor/mcp.json` for glob
167
164
  </details>
168
165
 
169
166
  <details>
170
- <summary><strong>Windsurf</strong></summary>
167
+ <summary><strong>Cursor</strong></summary>
171
168
 
172
- Add to `~/.codeium/windsurf/mcp_config.json`:
169
+ Add to `.cursor/mcp.json` in your project root (or `~/.cursor/mcp.json` for global):
173
170
 
174
171
  ```json
175
172
  {
@@ -177,11 +174,7 @@ Add to `~/.codeium/windsurf/mcp_config.json`:
177
174
  "prism-mcp": {
178
175
  "command": "npx",
179
176
  "args": ["-y", "prism-mcp-server"],
180
- "env": {
181
- "BRAVE_API_KEY": "your-brave-api-key",
182
- "SUPABASE_URL": "https://your-project.supabase.co",
183
- "SUPABASE_KEY": "your-supabase-anon-key"
184
- }
177
+ "env": {}
185
178
  }
186
179
  }
187
180
  }
@@ -190,33 +183,28 @@ Add to `~/.codeium/windsurf/mcp_config.json`:
190
183
  </details>
191
184
 
192
185
  <details>
193
- <summary><strong>VS Code + Continue</strong></summary>
186
+ <summary><strong>Windsurf</strong></summary>
194
187
 
195
- Add to your Continue `config.json` (usually `~/.continue/config.json`):
188
+ Add to `~/.codeium/windsurf/mcp_config.json`:
196
189
 
197
190
  ```json
198
191
  {
199
- "mcpServers": [
200
- {
201
- "name": "prism-mcp",
192
+ "mcpServers": {
193
+ "prism-mcp": {
202
194
  "command": "npx",
203
195
  "args": ["-y", "prism-mcp-server"],
204
- "env": {
205
- "BRAVE_API_KEY": "your-brave-api-key",
206
- "SUPABASE_URL": "https://your-project.supabase.co",
207
- "SUPABASE_KEY": "your-supabase-anon-key"
208
- }
196
+ "env": {}
209
197
  }
210
- ]
198
+ }
211
199
  }
212
200
  ```
213
201
 
214
202
  </details>
215
203
 
216
204
  <details>
217
- <summary><strong>Cline (VS Code)</strong></summary>
205
+ <summary><strong>VS Code + Continue / Cline</strong></summary>
218
206
 
219
- In VS Code, open Cline settings MCP Servers → Add Server:
207
+ Add to your Continue `config.json` or Cline MCP settings:
220
208
 
221
209
  ```json
222
210
  {
@@ -225,9 +213,8 @@ In VS Code, open Cline settings → MCP Servers → Add Server:
225
213
  "command": "npx",
226
214
  "args": ["-y", "prism-mcp-server"],
227
215
  "env": {
228
- "BRAVE_API_KEY": "your-brave-api-key",
229
- "SUPABASE_URL": "https://your-project.supabase.co",
230
- "SUPABASE_KEY": "your-supabase-anon-key"
216
+ "PRISM_STORAGE": "local",
217
+ "BRAVE_API_KEY": "your-brave-api-key"
231
218
  }
232
219
  }
233
220
  }
@@ -242,13 +229,13 @@ In VS Code, open Cline settings → MCP Servers → Add Server:
242
229
 
243
230
  | Scenario | How Prism MCP Helps |
244
231
  |----------|-------------------|
245
- | **Long-running feature development** | Save session state at end of day, restore full context the next morning — no re-explaining |
246
- | **Multi-agent workflows** | Shared Supabase backend with RLS lets multiple agents collaborate on the same project |
247
- | **Consulting / multi-project work** | Switch between client projects with progressive context loading (quick / standard / deep) |
248
- | **Research & analysis** | Multi-engine search (Brave + Vertex AI) with 94% context reduction via sandboxed code transforms |
232
+ | **Long-running feature work** | Save session state at end of day, restore full context the next morning — no re-explaining |
233
+ | **Multi-agent collaboration** | Telepathy sync lets multiple agents share context in real time |
234
+ | **Consulting / multi-project** | Switch between client projects with progressive context loading |
235
+ | **Research & analysis** | Multi-engine search with 94% context reduction via sandboxed code transforms |
249
236
  | **Team onboarding** | New team member's agent loads full project history via `session_load_context("deep")` |
250
- | **Claude Desktop memory** | The `/resume_session` MCP Prompt injects context *before* Claude starts thinking zero tool calls |
251
- | **Knowledge management** | Auto-extracted keywords + categories turn session logs into a searchable knowledge base |
237
+ | **Visual debugging** | Save screenshots of broken UI to visual memory the agent remembers what it looked like |
238
+ | **Offline / air-gapped** | Full SQLite local mode with no internet dependency for memory features |
252
239
 
253
240
  ---
254
241
 
@@ -261,847 +248,327 @@ graph TB
261
248
 
262
249
  Client -- "MCP Protocol (stdio)" --> MCP
263
250
 
251
+ MCP --> Dashboard["Mind Palace Dashboard<br/>localhost:3000"]
264
252
  MCP --> Brave["Brave Search API<br/>Web + Local + AI Answers"]
265
- MCP --> Gemini["Google Gemini API<br/>Research Paper Analysis"]
266
- MCP --> Vertex["Vertex AI Discovery Engine<br/>Enterprise Search"]
267
- MCP --> Sandbox["QuickJS Sandbox<br/>Code-Mode Transforms"]
268
- MCP --> Supabase["Supabase<br/>Session Memory (Optional)"]
253
+ MCP --> Gemini["Google Gemini API<br/>Analysis + Briefings"]
254
+ MCP --> Sandbox["QuickJS Sandbox<br/>Code-Mode Templates"]
255
+ MCP --> SyncBus["SyncBus<br/>Agent Telepathy"]
269
256
 
270
- Supabase --> Ledger["session_ledger<br/>(append-only log)"]
271
- Supabase --> Handoffs["session_handoffs<br/>(project state)"]
272
- Supabase --> Context["get_session_context<br/>(progressive loading<br/>+ knowledge cache)"]
273
- Supabase --> Knowledge["Knowledge System<br/>(search / forget / cache)"]
257
+ MCP --> Storage{"Storage Backend"}
258
+ Storage --> SQLite["SQLite (Local)<br/>libSQL + F32_BLOB vectors"]
259
+ Storage --> Supabase["Supabase (Cloud)<br/>PostgreSQL + pgvector"]
260
+
261
+ SQLite --> Ledger["session_ledger"]
262
+ SQLite --> Handoffs["session_handoffs"]
263
+ SQLite --> History["history_snapshots<br/>(Time Travel)"]
264
+ SQLite --> Media["media vault<br/>(Visual Memory)"]
274
265
 
275
266
  style Client fill:#4A90D9,color:#fff
276
267
  style MCP fill:#2D3748,color:#fff
268
+ style Dashboard fill:#9F7AEA,color:#fff
277
269
  style Brave fill:#FB542B,color:#fff
278
270
  style Gemini fill:#4285F4,color:#fff
279
- style Vertex fill:#34A853,color:#fff
280
271
  style Sandbox fill:#805AD5,color:#fff
272
+ style SyncBus fill:#ED64A6,color:#fff
273
+ style Storage fill:#2D3748,color:#fff
274
+ style SQLite fill:#38B2AC,color:#fff
281
275
  style Supabase fill:#3ECF8E,color:#fff
282
- style Knowledge fill:#F6AD55,color:#fff
283
276
  ```
284
277
 
285
- ### ASCII Architecture (for terminals)
286
-
287
- ```
288
- ┌────────────────────┐ MCP Protocol (stdio) ┌──────────────────────────┐
289
- │ AI Client │ ◄───────────────────────────────── │ MCP Server │
290
- │ (Claude Desktop) │ │ (TypeScript + Python) │
291
- └────────────────────┘ └────────────┬─────────────┘
292
-
293
- ┌──────────────────┬──────────────────┼──────────────────┬────────────────────┐
294
- │ │ │ │ │
295
- ┌───────▼────────┐ ┌───────▼───────┐ ┌───────▼────────┐ ┌──────▼──────────┐ ┌───────▼──────────────┐
296
- │ Brave Search │ │ Gemini API │ │ Gmail OAuth │ │ Chrome DevTools │ │ Vertex AI Search │
297
- │ (Web + Local) │ │ (Analysis) │ │ (Data Pipe) │ │ (MCP Introspect)│ │ (Discovery Engine) │
298
- └────────────────┘ └───────────────┘ └────────────────┘ └─────────────────┘ └──────────────────────┘
299
-
300
- ┌──────────────────────────────────────────────────────┐
301
- │ Google Cloud (Vertex AI) │
302
- │ │
303
- │ ┌──────────────┐ ┌─────────────┐ ┌────────────┐ │
304
- │ │ Discovery │ │ Gemini SDK │ │ Claude on │ │
305
- │ │ Engine / │ │ (Vertex AI) │ │ Vertex AI │ │
306
- │ │ AI Search │ │ │ │ (Anthropic)│ │
307
- │ └──────────────┘ └─────────────┘ └────────────┘ │
308
- └──────────────────────────────────────────────────────┘
309
-
310
- ┌──────────────────────────────────────────────────────┐
311
- │ Supabase (Optional) │
312
- │ │
313
- │ ┌──────────────┐ ┌─────────────┐ ┌────────────┐ │
314
- │ │ session_ │ │ session_ │ │ get_session│ │
315
- │ │ ledger │ │ handoffs │ │ _context() │ │
316
- │ │ (append-only)│ │ (upsert) │ │ (RPC) │ │
317
- │ └──────────────┘ └─────────────┘ └────────────┘ │
318
- └──────────────────────────────────────────────────────┘
319
- ```
320
-
321
- ## Core Components
322
-
323
- ### 1. MCP Server (`src/`, `index.ts`)
324
-
325
- The backbone of the platform — a TypeScript MCP server that registers and exposes multiple tools via the Model Context Protocol standard.
326
-
327
- - **Server entry point** with stdio transport binding
328
- - **Modular tool definitions** with JSON Schema parameter validation
329
- - **Request handlers** with structured error handling and response formatting
330
- - **Config management** with environment-variable-driven API key injection
331
-
332
- ### 2. Vertex AI Applications (`vertex-ai/`)
333
-
334
- Integration layer connecting Google Cloud's Vertex AI services with the MCP search pipeline, enabling hybrid retrieval and multi-model analysis:
335
-
336
- | Component | Description | GCP Service |
337
- |-----------|-------------|-------------|
338
- | `verify_discovery_engine.ts` | Queries and validates a Discovery Engine search index with structured result parsing | Vertex AI Search / Discovery Engine |
339
- | `test_gemini_vertex.py` | Gemini model invocation via the Vertex AI Python SDK with ADC authentication | Vertex AI Generative Models |
340
- | `test_claude_vertex.py` | Claude model deployment via Anthropic's Vertex AI integration with multi-region failover | Claude on Vertex AI (Model Garden) |
341
-
342
- **Key capabilities:**
343
- - **Discovery Engine Search** — Document ingestion, index building, and structured query execution via `@google-cloud/discoveryengine` SDK
344
- - **Multi-model orchestration** — Seamless switching between Gemini and Claude models through the same GCP project
345
- - **Application Default Credentials (ADC)** — Secure, keyless authentication using `gcloud auth application-default login`
346
- - **Multi-region failover** — Automatic region rotation for Claude on Vertex AI (`us-east5`, `us-central1`, `europe-west1`)
347
-
348
- ### Hybrid Search Pipeline: MCP + Vertex AI Discovery Engine
349
-
350
- The platform's core architectural advantage is combining **real-time web search** (via MCP/Brave) with **enterprise-curated search** (via Vertex AI Discovery Engine) in a unified pipeline:
351
-
352
- ```
353
- Query ──► MCP Server
354
- ├── brave_web_search ──────────► Real-time web results
355
- ├── Discovery Engine ──────────► Curated enterprise index
356
- └── code_mode_transform ───────► Merged, deduplicated, normalized output
357
-
358
- gemini_research_paper_analysis
359
-
360
- Structured analysis (LLM)
361
- ```
362
-
363
- **Why a hybrid pipeline?** Each source has distinct strengths — the enhancement comes from combining them, not replacing one with the other:
364
-
365
- | Dimension | 🌐 Brave Search (MCP) | 🔍 Discovery Engine (Vertex AI) | 🔀 Hybrid (Combined) |
366
- |-----------|----------------------|----------------------------------|----------------------|
367
- | **Coverage** | Public web — broad, real-time | Curated document index — deep, domain-specific | **Both:** breadth + depth |
368
- | **Result quality** | Keyword-ranked web pages | ML-ranked with semantic understanding | **Deduplicated, best-of-both** |
369
- | **Speed** | **~200ms** (live search) | ~900ms (pre-indexed retrieval) | ~2.4s sequential (both stages) |
370
- | **Context efficiency** | 93% reduction via `code_mode_transform` | 95% reduction (pre-structured data) | 94% overall (71 KB → 4.1 KB) |
371
- | **Token savings** | **~10,074 / query** | **~7,087 / query** | Combined: **~17K tokens saved** |
372
- | **Freshness** | Real-time (seconds old) | Managed re-crawl schedules | Real-time + deep archive |
373
- | **Model routing** | Single Gemini API key | Multi-model (Gemini + Claude) via GCP | Full model flexibility |
278
+ ---
374
279
 
375
- The `code_mode_transform` tool is the key performance enabler — it runs sandboxed JavaScript over raw API payloads to extract only the relevant fields before passing data to the LLM, reducing context window usage by **85-95%** (measured via the built-in `benchmark.ts` suite). When combined with Discovery Engine's pre-structured results, the total pipeline achieves significantly lower token consumption compared to raw web scraping approaches.
280
+ ## Tool Reference
281
+
282
+ ### Search & Analysis Tools
283
+
284
+ | Tool | Purpose |
285
+ |------|---------|
286
+ | `brave_web_search` | Real-time internet search |
287
+ | `brave_local_search` | Location-based POI discovery |
288
+ | `brave_web_search_code_mode` | JS extraction over web search results |
289
+ | `brave_local_search_code_mode` | JS extraction over local search results |
290
+ | `code_mode_transform` | Universal post-processing with **8 built-in templates** |
291
+ | `gemini_research_paper_analysis` | Academic paper analysis via Gemini |
292
+ | `brave_answers` | AI-grounded answers from Brave |
293
+
294
+ ### Session Memory & Knowledge Tools
295
+
296
+ | Tool | Purpose |
297
+ |------|---------|
298
+ | `session_save_ledger` | Append immutable session log (summary, TODOs, decisions) |
299
+ | `session_save_handoff` | Upsert latest project state with OCC version tracking |
300
+ | `session_load_context` | Progressive context loading (quick / standard / deep) |
301
+ | `knowledge_search` | Semantic search across accumulated knowledge |
302
+ | `knowledge_forget` | Prune outdated or incorrect memories (4 modes + dry_run) |
303
+ | `session_search_memory` | Vector similarity search across all sessions |
304
+ | `backfill_embeddings` | Retroactively generate embeddings for existing entries |
305
+
306
+ ### v2.0 Advanced Memory Tools
307
+
308
+ | Tool | Purpose |
309
+ |------|---------|
310
+ | `memory_history` | Browse all historical versions of a project's handoff state |
311
+ | `memory_checkout` | Revert to any previous version (non-destructive, like `git revert`) |
312
+ | `session_save_image` | Save a screenshot/image to the visual memory vault |
313
+ | `session_view_image` | Retrieve and display a saved image from the vault |
314
+
315
+ ### Code Mode Templates (v2.1)
316
+
317
+ Instead of writing custom JavaScript, pass a `template` name for instant extraction:
318
+
319
+ | Template | Source Data | What It Extracts |
320
+ |----------|-----------|-----------------|
321
+ | `github_issues` | GitHub REST API | `#number [state] title (@author) {labels}` |
322
+ | `github_prs` | GitHub REST API | `#number [state] title (base ← head)` |
323
+ | `jira_tickets` | Jira REST API | `[KEY] summary - Status - Priority - Assignee` |
324
+ | `dom_links` | Raw HTML | All `<a>` links as markdown |
325
+ | `dom_headings` | Raw HTML | H1-H6 hierarchy with indentation |
326
+ | `api_endpoints` | OpenAPI/Swagger JSON | `[METHOD] /path - summary` |
327
+ | `slack_messages` | Slack Web API | `[timestamp] @user: message` |
328
+ | `csv_summary` | CSV text | Column names, row count, sample rows |
329
+
330
+ **Usage:** `{ "data": "<raw JSON>", "template": "github_issues" }` — no custom code needed.
376
331
 
377
- ### Verified Test Results
332
+ ---
378
333
 
379
- Benchmark data from [`test_pipeline_benchmark.ts`](vertex-ai/test_pipeline_benchmark.ts) (5 queries × 3 iterations each):
334
+ ## Environment Variables
380
335
 
381
- | Metric | 🌐 Brave (MCP) | 🔍 Discovery Engine | Hybrid Total |
382
- |--------|----------------|---------------------|--------------|
383
- | **Avg latency** | 220ms | 1,193ms | ~1.4s (sequential) |
384
- | **Avg raw payload** | 42.4 KB | 28.9 KB | 71.3 KB total input |
385
- | **Avg reduced payload** | 3.0 KB | 1.2 KB | **4.2 KB total** (94% reduction) |
386
- | **Token savings** | ~10,103 | ~7,097 | **~17,200 tokens saved / query** |
336
+ | Variable | Required | Description |
337
+ |----------|----------|-------------|
338
+ | `BRAVE_API_KEY` | No | Brave Search Pro API key (enables web/local search tools) |
339
+ | `PRISM_STORAGE` | No | `"local"` (default) or `"supabase"` |
340
+ | `GOOGLE_API_KEY` | No | Google AI / Gemini enables paper analysis, Morning Briefings, compaction |
341
+ | `BRAVE_ANSWERS_API_KEY` | No | Separate Brave Answers key for AI-grounded answers |
342
+ | `SUPABASE_URL` | If cloud mode | Supabase project URL |
343
+ | `SUPABASE_KEY` | If cloud mode | Supabase anon/service key |
344
+ | `PRISM_USER_ID` | No | Multi-tenant user isolation (default: `"default"`) |
345
+ | `PRISM_AUTO_CAPTURE` | No | Set `"true"` to auto-capture HTML snapshots of dev servers |
346
+ | `PRISM_CAPTURE_PORTS` | No | Comma-separated ports to scan (default: `3000,3001,5173,8080`) |
387
347
 
388
- End-to-end pipeline results from [`test_hybrid_search_pipeline.ts`](vertex-ai/test_hybrid_search_pipeline.ts):
348
+ ---
389
349
 
390
- | Pipeline Stage | Results | Latency | Payload |
391
- |----------------|---------|---------|--------|
392
- | Stage 1: Brave Web Search | 5 results | 520ms | 24.1 KB raw |
393
- | Stage 2: Discovery Engine | 5 results | 1,895ms | 23.1 KB raw |
394
- | Stage 3: Merge & Dedup | **9 unique** (1 duplicate removed) | <1ms | 2.6 KB → 1.4 KB |
395
- | Stage 4: Gemini Analysis | Structured summary | 4,919ms | — |
396
- | **Total Pipeline** | **9 merged results** | **7.3s end-to-end** | **~17K tokens saved** |
350
+ ## Progressive Context Loading
397
351
 
398
- > *"The web search results provide practical understanding... the Discovery Engine results delve into specialized and cutting-edge topics from arXiv... Together, the sources provide a holistic perspective, bridging established techniques with advanced research."*
399
- > — Gemini 2.5 Flash analysis output
352
+ Load only what you need saves tokens and speeds up boot:
400
353
 
401
- ### Real-World Comparison: Why the Hybrid Pipeline Matters
354
+ | Level | What You Get | Size | When to Use |
355
+ |-------|-------------|------|-------------|
356
+ | **quick** | Open TODOs + keywords | ~50 tokens | Fast check-in: "what was I working on?" |
357
+ | **standard** | Above + summary + recent decisions + knowledge cache + Git drift | ~200 tokens | **Recommended default** |
358
+ | **deep** | Above + full logs (last 5 sessions) + cross-project knowledge | ~1000+ tokens | After a long break or when you need complete history |
402
359
 
403
- Results from [`test_realworld_comparison.ts`](vertex-ai/test_realworld_comparison.ts) — 3 real AI/ML queries comparing Brave-only vs Hybrid:
360
+ ### Morning Briefing (Automatic)
404
361
 
405
- | Real-World Query | Brave Only | Hybrid | DE Added |
406
- |-----------------|------------|--------|----------|
407
- | *RLHF implementation* (AI engineer) | 10 results (2 academic) | 20 results (12 academic) | **+10 unique papers** |
408
- | *INT8 quantization* (ML deployment) | 10 results (4 academic) | 20 results (14 academic) | **+10 unique papers** |
409
- | *RAG architecture* (enterprise dev) | 10 results (0 academic) | 20 results (10 academic) | **+10 unique papers** |
362
+ If it's been more than 4 hours since your last session, Prism automatically:
363
+ 1. Fetches the 10 most recent uncompacted ledger entries
364
+ 2. Sends a notification: *"🌅 Brewing your Morning Briefing..."*
365
+ 3. Uses Gemini to synthesize a 3-bullet action plan
366
+ 4. Injects the briefing into the `session_load_context` response
410
367
 
411
- **Key finding:** For the RAG query, Brave returned **zero academic sources** only vendor docs (AWS, NVIDIA, IBM, Google Cloud). Discovery Engine filled this gap entirely with 10 peer-reviewed papers including the foundational RAG paper by Lewis et al.
368
+ The agent boots up knowing exactly what to dozero prompting needed.
412
369
 
413
- | Aggregate Metric | Brave Only | Hybrid | Improvement |
414
- |-----------------|------------|--------|-------------|
415
- | **Avg results / query** | 10 | 20 | **+100%** |
416
- | **Avg academic sources** | 2.0 | 12.0 | **+10 per query** |
417
- | **Source overlap** | — | 0% | Fully complementary |
418
- | **Unique DE contributions** | — | 30 total | 10 per query |
370
+ ---
419
371
 
420
- <details>
421
- <summary><strong>Sample output: RAG Architecture query — Brave-only vs Hybrid</strong></summary>
372
+ ## Time Travel (Version History)
422
373
 
423
- **Brave Search returned** (0 academic sources):
424
- ```
425
- [1] 🌐 Retrieval-augmented generation - Wikipedia (en.wikipedia.org)
426
- [2] 🌐 Retrieval-Augmented Generation (RAG) | Pinecone (pinecone.io)
427
- [3] 🌐 Introduction to RAG and Vector Databases (medium.com)
428
- [4] 🌐 What is RAG? - AWS (aws.amazon.com)
429
- [5] 🌐 RAG and vector databases - GitHub (github.com)
430
- [6] 🌐 What is RAG? | Databricks (databricks.com)
431
- [7] 🌐 What is RAG? | NVIDIA (nvidia.com)
432
- [8] 🌐 What is RAG? | IBM (ibm.com)
433
- [9] 🌐 What is RAG? | Confluent (confluent.io)
434
- [10] 🌐 What is RAG? | Google Cloud (cloud.google.com)
435
- ```
374
+ Every successful handoff save creates a snapshot. You can browse and revert any version:
436
375
 
437
- **Discovery Engine added** (10 academic sources, 0 overlap):
438
376
  ```
439
- [+1] 📚 Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks (arxiv.org)
440
- [+2] 📚 Benchmarking Vector, Graph and Hybrid RAG (arxiv.org)
441
- [+3] 📚 HybridRAG: Integrating Knowledge Graphs and Vector Retrieval (arxiv.org)
442
- [+4] 📚 Adversarial Threat Vectors and Risk Mitigation for RAG (arxiv.org)
443
- [+5] 📚 RAGdb: A Zero-Dependency, Embeddable Architecture (arxiv.org)
444
- [+6] 📚 Building Scalable AI-Powered Applications with Cloud Databases (arxiv.org)
445
- [+7] 📚 Federated Retrieval-Augmented Generation (FRAG) (arxiv.org)
446
- [+8] 📚 A Systematic Review of Key RAG Components (arxiv.org)
447
- [+9] 📚 From Traditional RAG to Agentic and Graph RAG (arxiv.org)
448
- [+10] 📚 Accelerating Retrieval-Augmented Generation (arxiv.org)
377
+ v1 v2 v3 v4 (current)
378
+
379
+ memory_checkout(v2) creates v5 with v2's content
449
380
  ```
450
381
 
451
- </details>
452
-
453
- ### 3. Search & Data Extraction Tools
382
+ This is a **non-destructive revert** — like `git revert`, not `git reset`. No history is ever lost.
454
383
 
455
- Seven search/analysis tools plus five session memory & knowledge tools (12 total):
384
+ ### Usage
456
385
 
457
- | Tool | Purpose | Input | Output |
458
- |------|---------|-------|--------|
459
- | `brave_web_search` | Real-time internet search | Query string | Structured search results |
460
- | `brave_local_search` | Location-based POI discovery | Query + location | Business/POI data |
461
- | `brave_web_search_code_mode` | JS extraction over web results | Query + JS transform | Filtered fields |
462
- | `brave_local_search_code_mode` | JS extraction over local results | Query + JS transform | Filtered fields |
463
- | `code_mode_transform` | Universal post-processing | Raw data + JS transform | Normalized output |
464
- | `gemini_research_paper_analysis` | Academic paper analysis | Paper text + analysis type | Structured analysis |
465
- | `brave_answers` | AI-grounded answers | Question | Concise answer |
466
-
467
- **Optional: Session Memory & Knowledge Tools** *(enabled when Supabase is configured)*
468
-
469
- | Tool | Purpose | Input | Output |
470
- |------|---------|-------|--------|
471
- | `session_save_ledger` | Append immutable session log | Project + summary + TODOs | Confirmation |
472
- | `session_save_handoff` | Upsert latest project state | Project + context | Confirmation |
473
- | `session_load_context` | Progressive context loading + knowledge cache | Project + level | Session context + hot keywords |
474
- | `knowledge_search` | Search accumulated knowledge | Keywords, category, or free text | Ranked results |
475
- | `knowledge_forget` | Prune bad/old session memories | Project + filters + dry_run | Deletion report |
476
-
477
- ### 4. Data Pipeline Integrations (Python)
478
-
479
- Python-based automation for API consumption and data manipulation:
480
-
481
- - **Gmail API** — OAuth 2.0 authenticated email data retrieval and parsing
482
- - **Chrome DevTools Protocol** — Programmatic MCP tool introspection and browser automation
483
- - **Cross-MCP Testing** — Integration test suite validating tool interoperability across MCP servers
386
+ ```json
387
+ // Browse all versions
388
+ { "name": "memory_history", "arguments": { "project": "my-app" } }
484
389
 
485
- ### 5. Universal Code Mode Transform
390
+ // Revert to version 2
391
+ { "name": "memory_checkout", "arguments": { "project": "my-app", "version": 2 } }
392
+ ```
486
393
 
487
- A powerful **post-processing layer** designed to normalize and extract specific fields from large MCP outputs. Supports ready-to-use templates for:
394
+ ---
488
395
 
489
- - GitHub Issues / Pull Requests → compact summaries
490
- - Firecrawl scrape results → title + URL extraction
491
- - Chrome DevTools network logs → method + URL + status
492
- - Video transcripts → keyword-filtered timestamp extraction
396
+ ## Agent Telepathy (Multi-Client Sync)
493
397
 
494
- ## Technical Stack
398
+ When Agent A (Cursor) saves a handoff, Agent B (Claude Desktop) gets notified instantly:
495
399
 
496
- | Layer | Technologies |
497
- |-------|-------------|
498
- | **Runtime** | Node.js 18+, TypeScript, `@modelcontextprotocol/sdk` |
499
- | **Cloud AI** | Google Cloud Vertex AI, Discovery Engine, Gemini SDK, Anthropic Vertex SDK |
500
- | **Data Processing** | Python 3.10+, JSON/CSV parsing, JavaScript extraction |
501
- | **APIs** | Brave Search (Pro + Answers), Google Gemini, Gmail, Chrome DevTools, GCP Discovery Engine |
502
- | **Auth & Security** | GCP ADC, OAuth 2.0, AES-encrypted credentials, env-based secrets injection |
503
- | **Testing** | MCP schema validation, cross-server integration tests, Vertex AI verification, hybrid pipeline benchmarks |
504
- | **Tooling** | Git, npm, gcloud CLI, Linux/macOS |
400
+ - **Local Mode:** File-based IPC via SQLite polling
401
+ - **Cloud Mode:** Supabase Realtime (Postgres CDC)
505
402
 
506
- ## Project Structure
403
+ No configuration needed — it just works.
507
404
 
508
- ```
509
- ├── src/
510
- │ ├── server.ts # MCP server core (conditional tool registration)
511
- │ ├── config.ts # Configuration & environment management
512
- │ ├── tools/
513
- │ │ ├── definitions.ts # Search & analysis tool schemas
514
- │ │ ├── handlers.ts # Search & analysis handlers
515
- │ │ ├── sessionMemoryDefinitions.ts # Session memory + knowledge tool schemas
516
- │ │ ├── sessionMemoryHandlers.ts # Session memory + knowledge handlers
517
- │ │ └── index.ts # Tool registration & re-exports
518
- │ └── utils/
519
- │ ├── braveApi.ts # Brave Search REST client
520
- │ ├── googleAi.ts # Google Gemini SDK wrapper
521
- │ ├── executor.ts # QuickJS sandbox executor
522
- │ ├── supabaseApi.ts # Supabase REST client (optional)
523
- │ └── keywordExtractor.ts # Zero-dependency keyword extraction
524
- ├── supabase/
525
- │ └── migrations/
526
- │ ├── 015_session_memory.sql # Session memory schema (tables + RPC)
527
- │ └── 016_knowledge_accumulation.sql # Knowledge indexes, search RPC, cache preload
528
- ├── vertex-ai/
529
- │ ├── verify_discovery_engine.ts # Vertex AI Search index verification
530
- │ ├── test_hybrid_search_pipeline.ts # End-to-end hybrid pipeline test
531
- │ ├── test_pipeline_benchmark.ts # Performance benchmark: Brave vs DE
532
- │ ├── test_realworld_comparison.ts # Real-world side-by-side comparison
533
- │ ├── test_gemini_vertex.py # Gemini model via Vertex AI SDK
534
- │ └── test_claude_vertex.py # Claude model via Vertex AI
535
- ├── index.ts # Server entry point
536
- ├── benchmark.ts # Performance benchmarking suite
537
- ├── test_mcp_schema.js # MCP schema validation tests
538
- ├── test_cross_mcp.js # Cross-MCP integration test suite
539
- ├── package.json # Dependencies & build config
540
- └── tsconfig.json # TypeScript configuration
541
- ```
405
+ ---
542
406
 
543
- ## Getting Started
407
+ ## Reality Drift Detection
544
408
 
545
- ### Prerequisites
546
- - Node.js 18+
547
- - Python 3.10+
548
- - npm
549
- - Google Cloud SDK (`gcloud`) with Vertex AI enabled
409
+ Prism captures Git state (branch + commit SHA) on every handoff save. When the agent loads context, it compares the saved state against the current working directory:
550
410
 
551
- ### Installation
552
- ```bash
553
- git clone https://github.com/dcostenco/prism-mcp.git
554
- cd prism-mcp
555
- npm install
556
- npm run build
557
411
  ```
558
-
559
- ### GCP / Vertex AI Setup
560
- ```bash
561
- # Authenticate for Vertex AI (no API keys needed — uses ADC)
562
- gcloud auth application-default login
563
-
564
- # Optional: set Discovery Engine env vars for hybrid search
565
- export DISCOVERY_ENGINE_PROJECT_ID=<your-gcp-project>
566
- export DISCOVERY_ENGINE_ENGINE_ID=<your-engine-id>
567
- export DISCOVERY_ENGINE_LOCATION=global
568
- export DISCOVERY_ENGINE_COLLECTION=default_collection
569
- export DISCOVERY_ENGINE_SERVING_CONFIG=default_serving_config
412
+ ⚠️ REALITY DRIFT DETECTED for "my-app":
413
+ Branch changed: feature/auth main
414
+ Commit changed: abc1234 → def5678
415
+
416
+ The codebase has been modified since your last session.
417
+ Re-examine before making assumptions.
570
418
  ```
571
419
 
572
- ### Configuration
573
-
574
- All credentials are injected via environment variables or GCP Application Default Credentials — **no API keys are stored in this repository**.
575
-
576
- Required environment variables (set via your shell profile or a `.env` file, which is `.gitignore`’d):
577
-
578
- - `BRAVE_API_KEY` — Brave Search Pro subscription
579
- - `GEMINI_API_KEY` — Google AI Studio API key
580
- - `DISCOVERY_ENGINE_PROJECT_ID` — GCP project with Discovery Engine enabled
581
- - `DISCOVERY_ENGINE_ENGINE_ID` — Your Discovery Engine app/engine ID
582
-
583
- ### Running
584
- ```bash
585
- # MCP Server
586
- npm start
587
-
588
- # Vertex AI Discovery Engine verification
589
- npx ts-node vertex-ai/verify_discovery_engine.ts
590
-
591
- # Vertex AI model tests
592
- python3 vertex-ai/test_gemini_vertex.py
593
- python3 vertex-ai/test_claude_vertex.py
420
+ This prevents the agent from writing code based on stale context.
594
421
 
595
- # Hybrid pipeline test (MCP + Discovery Engine end-to-end)
596
- npx ts-node vertex-ai/test_hybrid_search_pipeline.ts
597
-
598
- # Performance benchmark (Brave Search vs Discovery Engine)
599
- npx ts-node vertex-ai/test_pipeline_benchmark.ts
600
- ```
422
+ ---
601
423
 
602
- ### Claude Desktop Integration
424
+ ## Visual Memory & Auto-Capture
603
425
 
604
- Add the server to your Claude Desktop MCP config (credentials are passed via environment variables):
426
+ ### Manual: Save Screenshots
605
427
 
606
428
  ```json
607
- {
608
- "mcpServers": {
609
- "prism-mcp": {
610
- "command": "node",
611
- "args": ["<path>/build/index.js"],
612
- "env": {
613
- "BRAVE_API_KEY": "${BRAVE_API_KEY}",
614
- "GEMINI_API_KEY": "${GEMINI_API_KEY}",
615
- "DISCOVERY_ENGINE_PROJECT_ID": "${DISCOVERY_ENGINE_PROJECT_ID}",
616
- "DISCOVERY_ENGINE_ENGINE_ID": "${DISCOVERY_ENGINE_ENGINE_ID}",
617
- "SUPABASE_URL": "${SUPABASE_URL}",
618
- "SUPABASE_KEY": "${SUPABASE_KEY}"
619
- }
620
- }
621
- }
622
- }
429
+ { "name": "session_save_image", "arguments": {
430
+ "project": "my-app",
431
+ "image_path": "/path/to/screenshot.png",
432
+ "description": "Login page after CSS fix"
433
+ }}
623
434
  ```
624
435
 
625
- > **Note:** All 12 tools are available when both Brave and Supabase keys are configured. `SUPABASE_URL` and `SUPABASE_KEY` enable the 5 session memory + knowledge tools. Without them, the server runs with 7 search & analysis tools.
626
-
627
- ## Key Design Decisions
436
+ ### Automatic: HTML Snapshots
628
437
 
629
- - **Protocol-first architecture** All tools are exposed through the standardized MCP interface, ensuring compatibility with any MCP-compliant AI client
630
- - **Cloud-native AI** — Vertex AI integration provides enterprise-grade model access with GCP's security, quota management, and multi-region support
631
- - **Multi-model strategy** — Supports Gemini and Claude through the same GCP infrastructure, enabling model selection based on task requirements
632
- - **Separation of concerns** — Tool definitions, handlers, and configuration are cleanly separated for maintainability
633
- - **Security by design** — No hardcoded credentials; all secrets flow through environment variables, ADC, or encrypted stores
634
- - **Extensibility** — New tools can be registered by adding a definition + handler without modifying the server core
635
- - **Optional modules** — Session memory tools only register when Supabase is configured — zero impact on users who don't need them
636
- - **Cross-system interoperability** — Universal transform layer enables output normalization across heterogeneous MCP servers
438
+ Set `PRISM_AUTO_CAPTURE=true` and Prism silently captures your local dev server's HTML on every handoff save. Supported formats: PNG, JPG, WebP, GIF, SVG, HTML.
637
439
 
638
440
  ---
639
441
 
640
- ## Session Memory & Knowledge System
442
+ ## Knowledge Accumulation
641
443
 
642
- Prism's core differentiator: persistent session memory and brain-inspired knowledge accumulation for AI agents — save work logs, hand off state between sessions, progressively load context on boot, search accumulated knowledge, and prune bad memories. This is what makes Prism more than just another search server.
444
+ Every `session_save_ledger` and `session_save_handoff` automatically extracts keywords using lightweight, in-process NLP (~0.020ms/call). No LLM calls, no external dependencies.
643
445
 
644
- ### Knowledge Accumulation System *(v0.3.0)*
645
-
646
- The brain-inspired knowledge layer that turns session data into searchable, manageable institutional memory.
647
-
648
- ```
649
- Session saves → Keywords auto-extracted → GIN-indexed → Searchable at boot
650
-
651
- ┌──────────────┤
652
- ▼ ▼
653
- knowledge_search knowledge_cache
654
- (on-demand) (auto at boot)
655
- ```
656
-
657
- #### How Knowledge Accumulates (Zero Effort)
658
-
659
- Every `session_save_ledger` and `session_save_handoff` call automatically extracts keywords from the text using lightweight, in-process NLP (~0.020ms/call). No LLM calls, no external dependencies.
660
-
661
- **Example:** Saving a ledger entry with summary *"Fixed Stripe webhook race condition using database-backed idempotency keys"* automatically extracts:
662
- - **Keywords:** `stripe`, `webhook`, `race`, `condition`, `database`, `idempotency`, `keys`
446
+ **Example:** Saving *"Fixed Stripe webhook race condition using database-backed idempotency keys"* auto-extracts:
447
+ - **Keywords:** `stripe`, `webhook`, `race`, `condition`, `database`, `idempotency`
663
448
  - **Categories:** `cat:debugging`, `cat:api-integration`
664
449
 
665
- #### `knowledge_search` — Query Accumulated Knowledge
666
-
667
- Search across all sessions by keyword, category, or free text:
450
+ ### Search Knowledge
668
451
 
669
452
  ```json
670
- {
671
- "name": "knowledge_search",
672
- "arguments": {
673
- "project": "ecommerce-api",
674
- "category": "debugging",
675
- "query": "Stripe webhook"
676
- }
677
- }
453
+ { "name": "knowledge_search", "arguments": {
454
+ "project": "ecommerce-api",
455
+ "category": "debugging",
456
+ "query": "Stripe webhook"
457
+ }}
678
458
  ```
679
459
 
680
- **Available categories:** `debugging`, `architecture`, `deployment`, `testing`, `configuration`, `api-integration`, `data-migration`, `security`, `performance`, `documentation`, `ai-ml`, `ui-frontend`, `resume`
681
-
682
- #### `knowledge_forget` — Prune Bad Memories
683
-
684
- Selectively delete outdated or incorrect knowledge, like a brain pruning bad connections:
460
+ ### Forget Bad Memories
685
461
 
686
462
  | Mode | Example | Effect |
687
463
  |------|---------|--------|
688
- | **By project** | `project: "old-app"` | Clear all knowledge for that project |
689
- | **By category** | `project: "my-app", category: "debugging"` | Only forget debugging entries |
690
- | **By age** | `project: "my-app", older_than_days: 30` | Forget entries older than 30 days |
691
- | **Full reset** | `project: "my-app", confirm_all: true, clear_handoff: true` | Wipe everything + handoff state |
464
+ | **By project** | `project: "old-app"` | Clear all knowledge |
465
+ | **By category** | `category: "debugging"` | Forget debugging entries only |
466
+ | **By age** | `older_than_days: 30` | Forget entries older than 30 days |
692
467
  | **Dry run** | `dry_run: true` | Preview what would be deleted |
693
468
 
694
- ```json
695
- {
696
- "name": "knowledge_forget",
697
- "arguments": {
698
- "project": "my-app",
699
- "older_than_days": 30,
700
- "dry_run": true
701
- }
702
- }
703
- ```
704
- **Response:** `🔍 12 ledger entries would be forgotten for project "my-app" older than 30 days. This was a dry run.`
705
-
706
- #### Knowledge Cache Preload (Automatic at Boot)
707
-
708
- When `session_load_context` runs at `standard` or `deep` level, it now automatically includes a `knowledge_cache` section with the brain's hottest pathways — no separate search call needed:
709
-
710
- ```json
711
- {
712
- "level": "standard",
713
- "project": "ecommerce-api",
714
- "knowledge_cache": {
715
- "hot_keywords": ["stripe", "webhook", "idempotency", "subscription", "api"],
716
- "top_categories": ["api-integration", "debugging"],
717
- "total_sessions": 14
718
- }
719
- }
720
- ```
721
-
722
- At `deep` level, you also get **cross-project knowledge** — related sessions from OTHER projects that share keywords with the current one, enabling knowledge transfer across codebases.
723
-
724
- #### Why Prism's Approach Is Different
725
-
726
- Most MCP memory servers require **embedding models**, **graph databases**, or **LLM calls at save time**. Prism takes a fundamentally different approach:
727
-
728
- > **🧠 Zero-cost intelligence.** Knowledge accumulates automatically from data you're already saving — no new infrastructure, no extra API calls, no perceptible latency.
729
-
730
- **5 key benefits no other MCP memory server offers:**
731
-
732
- | # | Benefit | Details |
733
- |---|---|---|
734
- | ⚡ | **40,000× faster writes** | 0.005ms per save vs. 200–500ms for graph/embedding servers. Your agent never waits. |
735
- | 🏗️ | **Zero new infrastructure** | No Neo4j, no FalkorDB, no pgvector, no embedding API. Uses existing Supabase `TEXT[]` columns + PostgreSQL GIN indexes. |
736
- | 🧹 | **Built-in memory pruning** | The only MCP memory with a first-class `knowledge_forget` tool — 4 delete modes + dry_run safety. Others require manual DB operations. |
737
- | 🔥 | **Knowledge cache at boot** | `session_load_context` auto-includes hot keywords and top categories. No separate search call. No other server preloads knowledge. |
738
- | 🔗 | **Cross-project knowledge transfer** | At `deep` level, surfaces relevant sessions from *other* projects via keyword overlap. Graph servers enforce strict isolation — Prism treats cross-pollination as a feature. |
739
-
740
- **Comparison with leading alternatives:**
741
-
742
- ```
743
- Prism Knowledge Graph Graphiti/FalkorDB Hindsight
744
- Write overhead 0.005ms ~200ms ~500ms+ ~300ms
745
- External deps None Neo4j/JSON FalkorDB (Docker) pgvector + embeddings
746
- LLM at save time No No Yes Yes
747
- Auto-categorize 13 cats Schema-dependent Schema-dependent Via LLM
748
- Forget/prune tool ✅ 4 modes ❌ Manual ⚠️ TTL only ❌ None
749
- Cache preload ✅ ❌ ❌ ❌
750
- Cross-project ✅ ❌ ❌ Isolated ❌
751
- ```
752
-
753
- > **Philosophy:** Make the simplest thing that actually works, then make it invisible.
754
-
755
- ### Why Session Memory?
756
-
757
- AI agents forget everything between sessions. Session memory solves this:
758
-
759
- ```
760
- Session 1: Agent works on feature → saves ledger + handoff
761
-
762
- Session 2: Agent boots → loads context ← ─┘ → continues seamlessly
763
- ```
764
-
765
- ### How It Works
766
-
767
- Three complementary tools:
768
-
769
- | Tool | When to Use | What It Does |
770
- |------|-------------|---------------|
771
- | `session_save_ledger` | End of every session | Appends an **immutable** log entry (summary, TODOs, files changed, decisions) |
772
- | `session_save_handoff` | End of every session | **Upserts** the latest project state for next session boot |
773
- | `session_load_context` | Start of every session | **Loads** context at the requested depth level |
774
-
775
- ### Progressive Context Loading
776
-
777
- Load only what you need — saves tokens and speeds up boot:
778
-
779
- | Level | What You Get | Approximate Size | When to Use |
780
- |-------|-------------|-------------------|-------------|
781
- | **quick** | Open TODOs and keywords from the last session | ~50 tokens (very small) | Fast check-ins — "what was I working on?" |
782
- | **standard** | Everything in *quick*, plus a summary of recent work and key decisions | ~200 tokens (small) | **Recommended for most sessions** — gives the agent enough context to continue working |
783
- | **deep** | Everything in *standard*, plus full logs from the last 5 sessions including all files changed | ~1000+ tokens (larger) | After a long break or when you need the complete history |
784
-
785
- ### Real-Life Usage Examples
786
-
787
- #### Example 1: Saving a Session (End of Work)
788
-
789
- After completing a feature implementation session, the agent saves both a ledger entry and a handoff:
790
-
791
- **Save Ledger** — permanent record of what happened:
792
- ```json
793
- {
794
- "name": "session_save_ledger",
795
- "arguments": {
796
- "project": "ecommerce-api",
797
- "conversation_id": "conv-2026-03-18-a1b2c3",
798
- "summary": "Implemented Stripe webhook handler for subscription lifecycle events. Added idempotency keys to prevent duplicate processing. Fixed race condition in concurrent webhook delivery.",
799
- "todos": [
800
- "Add retry logic for failed Stripe API calls (currently fails silently)",
801
- "Write integration tests for subscription upgrade/downgrade flows",
802
- "Update API docs with new webhook endpoint schema"
803
- ],
804
- "files_changed": [
805
- "src/webhooks/stripe.ts",
806
- "src/services/subscription.ts",
807
- "src/middleware/idempotency.ts",
808
- "tests/webhooks/stripe.test.ts"
809
- ],
810
- "decisions": [
811
- "Used database-backed idempotency keys instead of Redis (simpler ops, acceptable latency for webhook volume)",
812
- "Chose to process webhooks synchronously rather than queue — volume is under 100/min",
813
- "Deferred retry logic to next session — needs design review for exponential backoff strategy"
814
- ]
815
- }
816
- }
817
- ```
818
-
819
- **Save Handoff** — live state for next session:
820
- ```json
821
- {
822
- "name": "session_save_handoff",
823
- "arguments": {
824
- "project": "ecommerce-api",
825
- "open_todos": [
826
- "Add retry logic for failed Stripe API calls",
827
- "Write integration tests for subscription flows",
828
- "Update API docs with webhook endpoint schema"
829
- ],
830
- "active_branch": "feature/stripe-webhooks",
831
- "last_summary": "Stripe webhook handler implemented with idempotency. Race condition fixed. Tests passing. Retry logic deferred.",
832
- "key_context": "Webhook endpoint is POST /api/webhooks/stripe. Using stripe.webhooks.constructEvent() for signature verification. Idempotency table is 'webhook_events' with unique constraint on stripe_event_id."
833
- }
834
- }
835
- ```
836
-
837
- #### Example 2: Booting a New Session (Start of Work)
838
-
839
- The next session (possibly hours or days later) loads context to resume:
840
-
841
- **Load Context (L2 — recommended default):**
842
- ```json
843
- {
844
- "name": "session_load_context",
845
- "arguments": {
846
- "project": "ecommerce-api",
847
- "level": "standard"
848
- }
849
- }
850
- ```
851
-
852
- **What the agent gets back:**
853
- ```json
854
- {
855
- "handoff": {
856
- "project": "ecommerce-api",
857
- "open_todos": [
858
- "Add retry logic for failed Stripe API calls",
859
- "Write integration tests for subscription flows",
860
- "Update API docs with webhook endpoint schema"
861
- ],
862
- "active_branch": "feature/stripe-webhooks",
863
- "last_summary": "Stripe webhook handler implemented with idempotency. Race condition fixed. Tests passing. Retry logic deferred.",
864
- "key_context": "Webhook endpoint is POST /api/webhooks/stripe. Using stripe.webhooks.constructEvent() for signature verification. Idempotency table is 'webhook_events' with unique constraint on stripe_event_id."
865
- },
866
- "recent_sessions": [
867
- {
868
- "summary": "Stripe webhook handler implemented with idempotency. Race condition fixed.",
869
- "created_at": "2026-03-18T16:30:00Z"
870
- },
871
- {
872
- "summary": "Set up Stripe SDK integration and customer portal. Created subscription model.",
873
- "created_at": "2026-03-17T14:00:00Z"
874
- },
875
- {
876
- "summary": "Designed payment architecture. Chose Stripe over Paddle for webhook flexibility.",
877
- "created_at": "2026-03-16T10:00:00Z"
878
- }
879
- ]
880
- }
881
- ```
882
-
883
- The agent now knows exactly where to pick up — it can immediately start on the retry logic without asking the user to re-explain the project.
884
-
885
- #### Example 3: Multi-Day Workflow (Full Lifecycle)
886
-
887
- A realistic multi-day development workflow showing how session memory accumulates:
888
-
889
- ```
890
- Day 1 (Monday) — Architecture & Setup
891
- ├── Agent designs auth system architecture
892
- ├── session_save_ledger: "Designed JWT auth with refresh tokens. Chose bcrypt over argon2."
893
- └── session_save_handoff: branch=feature/auth, todos=["implement signup endpoint"]
894
-
895
- Day 2 (Tuesday) — Implementation
896
- ├── session_load_context("standard"): Gets Day 1 handoff + summary
897
- ├── Agent implements signup/login endpoints
898
- ├── session_save_ledger: "Built signup + login. Added rate limiting. 12 tests passing."
899
- └── session_save_handoff: branch=feature/auth, todos=["add password reset flow"]
900
-
901
- Day 3 (Wednesday) — Bug Fix (Different Agent Session)
902
- ├── session_load_context("standard"): Gets Day 2 handoff + Day 1-2 summaries
903
- ├── Agent fixes token refresh race condition
904
- ├── session_save_ledger: "Fixed refresh token rotation bug (was invalidating too early)."
905
- └── session_save_handoff: todos=["add password reset", "deploy to staging"]
906
-
907
- Day 5 (Friday) — Deep Recovery After Break
908
- ├── session_load_context("deep"): Gets FULL history — all summaries, all TODOs, all decisions
909
- ├── Agent sees complete project context despite 2-day gap
910
- └── Continues with password reset implementation
911
- ```
469
+ ---
912
470
 
913
- **A "deep" recovery response** includes aggregated data across all sessions:
914
- ```json
915
- {
916
- "handoff": { "...": "latest state" },
917
- "recent_sessions": [ "...3 most recent..." ],
918
- "all_todos_aggregated": [
919
- "add password reset flow",
920
- "deploy to staging",
921
- "add password complexity validation"
922
- ],
923
- "all_decisions": [
924
- "JWT auth with refresh tokens (Day 1)",
925
- "bcrypt over argon2 for password hashing (Day 1)",
926
- "Rate limiting: 5 attempts per 15 min window (Day 2)",
927
- "Refresh token rotation: invalidate after use, not on issue (Day 3)"
928
- ],
929
- "session_count": 4,
930
- "first_session": "2026-03-16T10:00:00Z",
931
- "last_session": "2026-03-19T09:00:00Z"
932
- }
933
- ```
471
+ ## Supabase Setup (Cloud Mode)
934
472
 
935
- ### Supabase Setup (Step-by-Step)
473
+ <details>
474
+ <summary><strong>Step-by-step Supabase configuration</strong></summary>
936
475
 
937
- #### 1. Create a Supabase Project
476
+ ### 1. Create a Supabase Project
938
477
 
939
478
  1. Go to [supabase.com](https://supabase.com) and sign in (free tier works)
940
- 2. Click **New Project** → choose a name and password → select a region close to you
941
- 3. Wait for the project to be provisioned (~30 seconds)
942
-
943
- #### 2. Apply the Migration
479
+ 2. Click **New Project** → choose a name and password → select a region
480
+ 3. Wait for provisioning (~30 seconds)
944
481
 
945
- 1. In your Supabase dashboard, go to **SQL Editor** (left sidebar)
946
- 2. Click **New query**
947
- 3. Copy the contents of [`supabase/migrations/015_session_memory.sql`](supabase/migrations/015_session_memory.sql) and paste into the editor
948
- 4. Click **Run** (or press `Cmd+Enter`)
949
- 5. You should see: `Success. No rows returned`
482
+ ### 2. Apply Migrations
950
483
 
951
- This creates:
952
- - `session_ledger` table — append-only session logs
953
- - `session_handoffs` table — latest project state (one per project)
954
- - `get_session_context()` RPC function — progressive context loading
484
+ In the SQL Editor, run:
485
+ 1. [`supabase/migrations/015_session_memory.sql`](supabase/migrations/015_session_memory.sql)
486
+ 2. [`supabase/migrations/016_knowledge_accumulation.sql`](supabase/migrations/016_knowledge_accumulation.sql)
955
487
 
956
- #### 3. Get Your Credentials
488
+ ### 3. Get Credentials
957
489
 
958
- 1. Go to **Settings → API** in your Supabase dashboard
959
- 2. Copy the **Project URL** (e.g. `https://abcdefg.supabase.co`)
960
- 3. Copy the **anon public** key (starts with `eyJ...`)
490
+ Go to **Settings → API** and copy:
491
+ - **Project URL** (e.g. `https://abcdefg.supabase.co`)
492
+ - **anon public** key (starts with `eyJ...`)
961
493
 
962
- #### 4. Set Environment Variables
494
+ ### 4. Configure
963
495
 
964
496
  ```bash
965
- # Add to your shell profile (.zshrc, .bashrc) or .env file
966
497
  export SUPABASE_URL="https://your-project.supabase.co"
967
498
  export SUPABASE_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
499
+ export PRISM_STORAGE="supabase"
968
500
  ```
969
501
 
970
- #### 5. Rebuild and Restart
971
-
972
- ```bash
973
- npm run build
974
- # Restart your MCP client (Claude Desktop, etc.)
975
- ```
976
-
977
- On startup you'll see:
978
- ```
979
- Session memory enabled (Supabase configured)
980
- Registering 12 tools (7 base + 5 session memory & knowledge)
981
- ```
982
-
983
- #### 6. Apply Knowledge Accumulation Migration
984
-
985
- 1. In your Supabase dashboard, go to **SQL Editor**
986
- 2. Click **New query**
987
- 3. Copy the contents of [`supabase/migrations/016_knowledge_accumulation.sql`](supabase/migrations/016_knowledge_accumulation.sql)
988
- 4. Click **Run**
989
- 5. You should see: `Success. No rows returned`
990
-
991
- This adds:
992
- - GIN indexes on keywords columns for fast search
993
- - `search_knowledge()` RPC for querying accumulated knowledge
994
- - Enhanced `get_session_context()` with knowledge cache preload
995
-
996
- ### Verifying the Setup
997
-
998
- After configuring, verify the tables exist by running this in the Supabase SQL Editor:
999
-
1000
- ```sql
1001
- -- Should return 3 rows: session_ledger, session_handoffs, get_session_context
1002
- SELECT
1003
- CASE
1004
- WHEN routine_type IS NOT NULL THEN 'function'
1005
- ELSE 'table'
1006
- END AS type,
1007
- COALESCE(table_name, routine_name) AS name
1008
- FROM information_schema.tables
1009
- WHERE table_schema = 'public'
1010
- AND table_name IN ('session_ledger', 'session_handoffs')
1011
- UNION ALL
1012
- SELECT 'function', routine_name
1013
- FROM information_schema.routines
1014
- WHERE routine_schema = 'public'
1015
- AND routine_name = 'get_session_context';
1016
- ```
1017
-
1018
- ### Maintenance Guide
1019
-
1020
- #### Cleaning Up Old Ledger Entries
502
+ ### Security
1021
503
 
1022
- The ledger grows over time. To prune entries older than 30 days:
504
+ 1. **Use the anon key** for MCP server config
505
+ 2. **Enable RLS** on both tables
506
+ 3. **Never commit** your `SUPABASE_KEY` to version control
1023
507
 
1024
- ```sql
1025
- DELETE FROM session_ledger
1026
- WHERE created_at < NOW() - INTERVAL '30 days';
1027
- ```
1028
-
1029
- #### Backing Up Session Data
1030
-
1031
- ```sql
1032
- -- Export all session data as JSON
1033
- SELECT json_agg(t) FROM (
1034
- SELECT * FROM session_ledger ORDER BY created_at
1035
- ) t;
1036
-
1037
- SELECT json_agg(t) FROM (
1038
- SELECT * FROM session_handoffs ORDER BY updated_at
1039
- ) t;
1040
- ```
508
+ </details>
1041
509
 
1042
- #### Restoring from Backup
510
+ ---
1043
511
 
1044
- Paste the JSON arrays into INSERT statements:
512
+ ## Hybrid Search Pipeline (Brave + Vertex AI)
1045
513
 
1046
- ```sql
1047
- INSERT INTO session_ledger (project, conversation_id, summary, todos, files_changed, decisions)
1048
- SELECT project, conversation_id, summary, todos, files_changed, decisions
1049
- FROM json_populate_recordset(NULL::session_ledger, '<paste JSON array>');
1050
- ```
1051
-
1052
- #### Monitoring Table Size
1053
-
1054
- ```sql
1055
- SELECT
1056
- relname AS table_name,
1057
- pg_size_pretty(pg_total_relation_size(relid)) AS total_size,
1058
- n_live_tup AS row_count
1059
- FROM pg_stat_user_tables
1060
- WHERE schemaname = 'public'
1061
- AND relname IN ('session_ledger', 'session_handoffs')
1062
- ORDER BY pg_total_relation_size(relid) DESC;
1063
- ```
514
+ <details>
515
+ <summary><strong>Enterprise search with Vertex AI Discovery Engine</strong></summary>
1064
516
 
1065
- ### Troubleshooting
517
+ Prism can combine **real-time web search** (Brave) with **enterprise-curated search** (Vertex AI Discovery Engine) for a hybrid pipeline achieving **94% context reduction** and **~17K tokens saved per query**.
1066
518
 
1067
- | Symptom | Cause | Fix |
1068
- |---------|-------|-----|
1069
- | `Session memory disabled` on startup | `SUPABASE_URL` or `SUPABASE_KEY` not set | Set both env vars and restart |
1070
- | `Supabase POST failed: 404` | Migration not applied | Run `015_session_memory.sql` in SQL Editor |
1071
- | `Supabase POST failed: 401` | Wrong API key | Use the **anon public** key from Settings → API |
1072
- | `Supabase POST failed: 42501` | RLS blocking inserts | Ensure RLS policies allow inserts (see Security below) |
1073
- | `No session context found` | No prior sessions saved | Expected for new projects — save a ledger entry first |
1074
- | `session_save_handoff` returns empty | First-time upsert | Normal — the handoff is created, subsequent loads will work |
519
+ | Metric | Brave (Web) | Discovery Engine | Hybrid |
520
+ |--------|------------|-----------------|--------|
521
+ | Avg latency | 220ms | 1,193ms | ~1.4s |
522
+ | Raw payload | 42.4 KB | 28.9 KB | 71.3 KB |
523
+ | Reduced payload | 3.0 KB | 1.2 KB | **4.2 KB** (94% reduction) |
524
+ | Token savings | ~10,103 | ~7,097 | **~17,200 / query** |
1075
525
 
1076
- ### Security Recommendations
526
+ See [`vertex-ai/`](vertex-ai/) for setup and benchmarks.
1077
527
 
1078
- 1. **Use the anon key** for MCP server config — it's safe for client-side use
1079
- 2. **Enable Row Level Security (RLS)** on both tables:
528
+ </details>
1080
529
 
1081
- ```sql
1082
- -- Enable RLS
1083
- ALTER TABLE session_ledger ENABLE ROW LEVEL SECURITY;
1084
- ALTER TABLE session_handoffs ENABLE ROW LEVEL SECURITY;
530
+ ---
1085
531
 
1086
- -- Allow inserts and reads for authenticated and anon users
1087
- CREATE POLICY "Allow all for session_ledger" ON session_ledger
1088
- FOR ALL USING (true) WITH CHECK (true);
532
+ ## Project Structure
1089
533
 
1090
- CREATE POLICY "Allow all for session_handoffs" ON session_handoffs
1091
- FOR ALL USING (true) WITH CHECK (true);
1092
534
  ```
1093
-
1094
- 3. **For multi-user setups**, restrict policies to specific projects:
1095
-
1096
- ```sql
1097
- -- Example: only allow access to your own projects
1098
- CREATE POLICY "User-scoped access" ON session_ledger
1099
- FOR ALL USING (project = current_setting('request.jwt.claims')::json->>'project')
1100
- WITH CHECK (project = current_setting('request.jwt.claims')::json->>'project');
535
+ ├── src/
536
+ │ ├── server.ts # MCP server core + Mind Palace HTTP server
537
+ │ ├── config.ts # Environment management
538
+ │ ├── storage/
539
+ │ │ ├── interface.ts # StorageBackend abstraction
540
+ │ │ ├── sqlite.ts # SQLite local storage (libSQL + F32_BLOB)
541
+ │ │ ├── supabase.ts # Supabase cloud storage
542
+ │ │ └── index.ts # Backend factory (auto-selects based on PRISM_STORAGE)
543
+ │ ├── sync/
544
+ │ │ ├── interface.ts # SyncBus abstraction (Telepathy)
545
+ │ │ ├── localSync.ts # File-based IPC for local mode
546
+ │ │ ├── supabaseSync.ts # Supabase Realtime CDC for cloud mode
547
+ │ │ └── factory.ts # Auto-selects sync backend
548
+ │ ├── dashboard/
549
+ │ │ └── ui.ts # Mind Palace glassmorphism HTML template
550
+ │ ├── templates/
551
+ │ │ └── codeMode.ts # 8 pre-built QuickJS extraction templates
552
+ │ ├── tools/
553
+ │ │ ├── definitions.ts # All tool schemas (JSON Schema + type guards)
554
+ │ │ ├── handlers.ts # Search & analysis handlers
555
+ │ │ ├── sessionMemoryDefinitions.ts # Memory + knowledge tool schemas
556
+ │ │ ├── sessionMemoryHandlers.ts # Memory handlers (OCC, Time Travel, Drift, Briefing)
557
+ │ │ └── index.ts # Tool registration & re-exports
558
+ │ └── utils/
559
+ │ ├── braveApi.ts # Brave Search REST client
560
+ │ ├── googleAi.ts # Gemini SDK wrapper
561
+ │ ├── executor.ts # QuickJS sandbox executor
562
+ │ ├── autoCapture.ts # Dev server HTML snapshot utility
563
+ │ ├── git.ts # Git state capture + drift detection
564
+ │ ├── embeddingApi.ts # Embedding generation (Gemini)
565
+ │ └── keywordExtractor.ts # Zero-dependency NLP keyword extraction
566
+ ├── supabase/migrations/ # Cloud mode SQL schemas
567
+ ├── vertex-ai/ # Vertex AI hybrid search pipeline
568
+ ├── index.ts # Server entry point
569
+ └── package.json
1101
570
  ```
1102
571
 
1103
- 4. **Never commit** your `SUPABASE_KEY` to version control — use environment variables
1104
-
1105
572
  ---
1106
573
 
1107
574
  ## License
@@ -1110,4 +577,4 @@ MIT
1110
577
 
1111
578
  ---
1112
579
 
1113
- <sub>**Keywords:** MCP server, Model Context Protocol, Claude Desktop memory, persistent session memory, AI agent memory, Claude context window, MCP session persistence, Cursor MCP server, Windsurf MCP server, Cline MCP server, pgvector semantic search, Supabase MCP, progressive context loading, MCP Prompts, MCP Resources, knowledge management AI, multi-engine search, Brave Search MCP, Gemini analysis, optimistic concurrency control, session handoff, AI agent state management</sub>
580
+ <sub>**Keywords:** MCP server, Model Context Protocol, Claude Desktop memory, persistent session memory, AI agent memory, local-first, SQLite MCP, Mind Palace, time travel, visual memory, agent telepathy, multi-agent sync, reality drift detection, morning briefing, code mode templates, cursor MCP server, windsurf MCP server, cline MCP server, pgvector semantic search, progressive context loading, MCP Prompts, MCP Resources, knowledge management AI, Brave Search MCP, Gemini analysis, optimistic concurrency control, zero config</sub>