prism-mcp-server 1.5.0 → 2.1.0

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