atlas-mcp 0.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 (54) hide show
  1. package/.env.example +32 -0
  2. package/README.md +282 -0
  3. package/package.json +72 -0
  4. package/public/app/assets/app-CxbS1w9p.js +3981 -0
  5. package/public/app/assets/index-BA6nxCuI.css +1 -0
  6. package/public/app/assets/index-BXmIRrQH.js +177 -0
  7. package/public/app/index.html +27 -0
  8. package/public/assets/brain-atlas.LICENSE.txt +16 -0
  9. package/public/assets/brain-atlas.glb +0 -0
  10. package/public/assets/brain.obj +27282 -0
  11. package/public/fonts/DepartureMono-Regular.woff +0 -0
  12. package/public/fonts/DepartureMono-Regular.woff2 +0 -0
  13. package/scripts/sync-memory-vectors.js +46 -0
  14. package/src/audit.js +9 -0
  15. package/src/cli/args.js +87 -0
  16. package/src/cli/commands/add.js +103 -0
  17. package/src/cli/commands/config.js +228 -0
  18. package/src/cli/commands/delete.js +75 -0
  19. package/src/cli/commands/entities.js +39 -0
  20. package/src/cli/commands/entity.js +47 -0
  21. package/src/cli/commands/get.js +46 -0
  22. package/src/cli/commands/list.js +53 -0
  23. package/src/cli/commands/related.js +56 -0
  24. package/src/cli/commands/search.js +68 -0
  25. package/src/cli/commands/update.js +58 -0
  26. package/src/cli/deps.js +114 -0
  27. package/src/cli/env-file.js +44 -0
  28. package/src/cli/format.js +246 -0
  29. package/src/cli.js +187 -0
  30. package/src/cognitive-worker.js +381 -0
  31. package/src/db.js +2674 -0
  32. package/src/extraction-context.js +31 -0
  33. package/src/ingestion-service.js +387 -0
  34. package/src/ingestion-worker.js +225 -0
  35. package/src/llm-config.js +31 -0
  36. package/src/llm.js +789 -0
  37. package/src/logger.js +51 -0
  38. package/src/mcp-server.js +577 -0
  39. package/src/memory-comparison.js +421 -0
  40. package/src/related-memories.js +232 -0
  41. package/src/run-cognitive-worker.js +12 -0
  42. package/src/run-ingestion-worker.js +13 -0
  43. package/src/run-vector-worker.js +12 -0
  44. package/src/schemas.js +413 -0
  45. package/src/semantic-validation.js +430 -0
  46. package/src/server.js +827 -0
  47. package/src/shared/brain-regions.js +61 -0
  48. package/src/shared/entity-lens.js +249 -0
  49. package/src/shared/memory-placement.js +171 -0
  50. package/src/shared/memory-search.js +55 -0
  51. package/src/shared/region-anchors.js +112 -0
  52. package/src/shared/region-mapper.js +247 -0
  53. package/src/vector-store.js +546 -0
  54. package/src/vector-worker.js +71 -0
package/.env.example ADDED
@@ -0,0 +1,32 @@
1
+ LLM_PROVIDER=tokenrouter
2
+ TOKENROUTER_API_KEY=your-key-here
3
+ OPENROUTER_API_KEY=your-key-here
4
+ LLM_TIMEOUT_MS=30000
5
+ LLM_MAX_RETRIES=2
6
+
7
+ ATLAS_MODE=local
8
+ PORT=3000
9
+ LOG_LEVEL=info
10
+ ENGRAM_DB_PATH=./engram.db
11
+ LANCEDB_PATH=./lancedb
12
+ LANCEDB_TABLE=atlas_memories
13
+
14
+ # Supabase project settings. Never use the service role key in the browser.
15
+ SUPABASE_URL=https://your-project-ref.supabase.co
16
+ SUPABASE_PUBLISHABLE_KEY=your-publishable-key
17
+ AUTH_ENABLED=false
18
+
19
+ EMBEDDING_MODEL=Xenova/all-MiniLM-L6-v2
20
+ EMBEDDING_DIMENSIONS=384
21
+ EMBEDDING_DTYPE=q8
22
+
23
+ # Reserved for the future managed Atlas service. Cloud mode is not available yet.
24
+ # ATLAS_MODE=cloud
25
+ # ATLAS_API_URL=https://api.example.com
26
+ # ATLAS_API_KEY=your-atlas-api-key
27
+
28
+ # Legacy direct-Qdrant compatibility only. Local mode does not require these.
29
+ # QDRANT_URL=https://your-cluster-id.region.cloud-provider.cloud.qdrant.io:6333
30
+ # QDRANT_API_KEY=your-qdrant-database-api-key
31
+ # QDRANT_COLLECTION=atlas_memories
32
+ # QDRANT_TIMEOUT_MS=10000
package/README.md ADDED
@@ -0,0 +1,282 @@
1
+ <div align="center">
2
+
3
+ # Atlas
4
+
5
+ **Semantic memory layer with a 3D atlas and MCP integration.**
6
+
7
+ SQLite is the source of truth. Vectors are embedded locally. Memories are typed, deduplicated, and mapped to brain regions.
8
+
9
+ </div>
10
+
11
+ ---
12
+
13
+ ## Install and use the CLI
14
+
15
+ Requires Node.js 18 or newer. The package installs two commands:
16
+
17
+ - `atlas` — the command-line memory client
18
+ - `atlas-mcp` — the MCP server
19
+
20
+ The package is not published to the public npm registry yet. Install the latest
21
+ version directly from GitHub for regular terminal use:
22
+
23
+ ```bash
24
+ npm install --global github:sidmanale643/Atlas
25
+ atlas --version
26
+ ```
27
+
28
+ Or run the CLI without a permanent install through `npx`:
29
+
30
+ ```bash
31
+ npx --yes --package github:sidmanale643/Atlas atlas --version
32
+ ```
33
+
34
+ When using the CLI through `npx`, replace `atlas` in the examples below with
35
+ `npx --yes --package github:sidmanale643/Atlas atlas`. After `atlas-mcp` is
36
+ published to npm, the shorter no-install form will be
37
+ `npx --yes --package atlas-mcp atlas`.
38
+
39
+ ### Configure Atlas
40
+
41
+ Atlas reads configuration from environment variables and from `.env` in the
42
+ current directory. Its SQLite database and LanceDB index also default to that
43
+ directory, so create a dedicated data directory and run commands from there:
44
+
45
+ ```bash
46
+ mkdir -p ~/.neurogram
47
+ cd ~/.neurogram
48
+
49
+ atlas config provider tokenrouter
50
+ atlas config apikey tokenrouter YOUR_TOKENROUTER_API_KEY
51
+ atlas config
52
+ ```
53
+
54
+ To use OpenRouter instead:
55
+
56
+ ```bash
57
+ atlas config provider openrouter
58
+ atlas config apikey openrouter YOUR_OPENROUTER_API_KEY
59
+ ```
60
+
61
+ The configuration commands create `~/.neurogram/.env`. API keys are masked in
62
+ normal `atlas config` output. You can also set individual values:
63
+
64
+ ```bash
65
+ atlas config set ENGRAM_DB_PATH ~/.neurogram/engram.db
66
+ atlas config set LANCEDB_PATH ~/.neurogram/lancedb
67
+ atlas config model YOUR_MODEL_NAME # optional provider model override
68
+ atlas config get LLM_PROVIDER
69
+ ```
70
+
71
+ Shell environment variables take precedence over values in `.env`. If you run
72
+ Atlas from different directories, use absolute database/index paths or keep
73
+ running it from the same data directory.
74
+
75
+ ### Store and recall memories
76
+
77
+ The first vector operation downloads the local embedding model and may take a
78
+ little longer. Adding memories also requires the LLM provider key configured
79
+ above.
80
+
81
+ ```bash
82
+ cd ~/.neurogram
83
+
84
+ atlas add "I prefer dark roast coffee" --type preference --title "Coffee"
85
+ atlas list
86
+ atlas search "coffee preference"
87
+ atlas get MEMORY_ID
88
+ atlas related MEMORY_ID
89
+ ```
90
+
91
+ Use `--json` with commands for machine-readable output, and run
92
+ `atlas <command> --help` for all options. Other commands include `entities`,
93
+ `entity`, `update`, and `delete`.
94
+
95
+ ### Run directly from the repository
96
+
97
+ ```bash
98
+ npm install
99
+ cp .env.example .env
100
+ # Add TOKENROUTER_API_KEY or OPENROUTER_API_KEY
101
+ npm start # Express on http://localhost:3000
102
+ ```
103
+
104
+ The default `ATLAS_MODE=local` runs everything on-machine: SQLite for memory,
105
+ LanceDB for vectors, and Transformers.js for embeddings.
106
+
107
+ ### Frontend (Atlas UI)
108
+
109
+ ```bash
110
+ npm run dev # backend on :3000
111
+ npm run dev:web # Vite on :5173, proxies /api to :3000
112
+ ```
113
+
114
+ Run both for the 3D brain visualization. Reserve `npm run build:web` for production builds.
115
+
116
+ ### Optional auth
117
+
118
+ Set `AUTH_ENABLED=true` and provide `SUPABASE_URL` + `SUPABASE_PUBLISHABLE_KEY`. All `/api` routes verify the access token. Off by default.
119
+
120
+ ### Persistent paths
121
+
122
+ ```dotenv
123
+ ATLAS_MODE=local
124
+ ENGRAM_DB_PATH=/var/data/neurogram/engram.db
125
+ LANCEDB_PATH=/var/data/neurogram/lancedb
126
+ LANCEDB_TABLE=atlas_memories
127
+ ```
128
+
129
+ ---
130
+
131
+ ## MCP server
132
+
133
+ Stdiod MCP server exposing the memory store to any compatible client (Claude Desktop, Cursor, etc.).
134
+
135
+ ```bash
136
+ npx atlas-mcp # no clone required
137
+ npm run mcp # from this repo
138
+ ```
139
+
140
+ ### Tools
141
+
142
+ | Tool | Description |
143
+ |------|-------------|
144
+ | `add_memory` | Write a typed memory; deduplicates against semantic candidates |
145
+ | `list_memories` | Recent memories |
146
+ | `get_memory` | One memory with entities, links, region activations |
147
+ | `search_memories` | Semantic search across text and summaries |
148
+ | `get_related_memories` | Connections from shared entities + similarity |
149
+ | `find_entities` | People, places, concepts |
150
+ | `get_entity_memories` | Memories linked to an entity |
151
+ | `update_memory_summary` | Rewrite the summary |
152
+ | `delete_memory` | Remove permanently |
153
+
154
+ `add_memory` requires an LLM API key. Read-only tools do not. The server logs to **stderr**; stdout is reserved for the protocol.
155
+
156
+ ### Client config
157
+
158
+ ```json
159
+ {
160
+ "mcpServers": {
161
+ "neurogram": {
162
+ "command": "node",
163
+ "args": ["/absolute/path/to/neurogram/src/mcp-server.js"],
164
+ "env": {
165
+ "ATLAS_MODE": "local",
166
+ "ENGRAM_DB_PATH": "/absolute/path/to/neurogram-data/engram.db",
167
+ "LANCEDB_PATH": "/absolute/path/to/neurogram-data/lancedb",
168
+ "LLM_PROVIDER": "tokenrouter",
169
+ "TOKENROUTER_API_KEY": "your-key-here"
170
+ }
171
+ }
172
+ }
173
+ }
174
+ ```
175
+
176
+ From a repository checkout, use `npm run cli -- <command>` or run `npm link` to
177
+ expose the `atlas` and `atlas-mcp` commands globally.
178
+
179
+ ---
180
+
181
+ ## Write pipeline
182
+
183
+ `add_memory` runs four steps:
184
+
185
+ 1. **Extract** — LLM pulls entities, relationships, summary, region weights, emotional tone.
186
+ 2. **Embed** — local sentence-transformer model produces the vector, offline.
187
+ 3. **Compare** — score up to 5 semantic candidates. High-confidence matches update the existing memory; equivalent input is returned unchanged; distinct input creates a new node.
188
+ 4. **Persist** — SQLite gets the canonical record, LanceDB gets the vector.
189
+
190
+ The response includes `action`, `memory`, `matchedMemoryId`, `confidence`, and `reason`.
191
+
192
+ Entity linking is conservative: ambiguous matches stay separate. Related-memory links are derived at read time, not stored as manual edges.
193
+
194
+ ---
195
+
196
+ ## Atlas (3D brain)
197
+
198
+ Every memory leaves a footprint across 11 regions: hippocampus, prefrontal, associationCortex, temporalCortex, basalGanglia, cerebellum, motorCortex, amygdala, insula, entorhinal, parietalCortex. Region mapping is deterministic and lives in `src/shared/region-mapper.js`.
199
+
200
+ Hippocampal activations include a bilateral footprint: `hemispheres.left` + `hemispheres.right` equals the parent region's `weight`. Other regions omit `hemispheres`.
201
+
202
+ ---
203
+
204
+ ## Environment
205
+
206
+ | Variable | Required | Description |
207
+ |----------|:--------:|-------------|
208
+ | `ATLAS_MODE` | No | `local` (default). `cloud` reserved. |
209
+ | `LLM_PROVIDER` | No | `tokenrouter` (default) or `openrouter` |
210
+ | `LLM_MODEL` | No | Override provider default |
211
+ | `TOKENROUTER_API_KEY` | ★ | Required if using TokenRouter |
212
+ | `OPENROUTER_API_KEY` | ★ | Required if using OpenRouter |
213
+ | `ENGRAM_DB_PATH` | No | SQLite path (default `./engram.db`) |
214
+ | `LANCEDB_PATH` | No | Vector index dir (default `./lancedb`) |
215
+ | `LANCEDB_TABLE` | No | Vector table (default `atlas_memories`) |
216
+ | `SUPABASE_URL` | No | Auth provider URL |
217
+ | `SUPABASE_PUBLISHABLE_KEY` | No | Auth provider publishable key |
218
+ | `EMBEDDING_MODEL` | No | Transformers.js model override |
219
+ | `EMBEDDING_DIMENSIONS` | No | Vector size (default `384`) |
220
+ | `EMBEDDING_DTYPE` | No | ONNX dtype (default `q8`) |
221
+
222
+ ★ Required only for the selected provider.
223
+
224
+ Legacy `QDRANT_*` vars remain for direct-Qdrant setups. Not required in local mode.
225
+
226
+ ---
227
+
228
+ ## Architecture
229
+
230
+ ```
231
+ src/
232
+ server.js Express HTTP API
233
+ mcp-server.js MCP stdio server
234
+ db.js SQLite schema + queries + migrations
235
+ llm.js Extraction, comparison, write decisions
236
+ schemas.js Zod schemas for extraction/memory/comparison
237
+ vector-store.js LanceDB (default) + Qdrant (legacy) + Transformers.js embeddings
238
+ ingestion-service.js Unified ingestion (HTTP + MCP)
239
+ cognitive-worker.js Background annotation worker
240
+ shared/ region-mapper, brain-regions
241
+
242
+ web/src/
243
+ App.tsx Routes: Landing, Atlas, Catalog, Compare, Graph
244
+ viz/brain/ Three.js 3D brain (~3600 lines, legacy)
245
+ viz/graph/ Force graph hook
246
+ pages/ Route components (TypeScript)
247
+ components/ Shared UI
248
+ lib/ API client, types, motion utils
249
+ theme/ CSS design tokens
250
+ ```
251
+
252
+ ESM throughout. No TypeScript in `src/` — only `web/src/`.
253
+
254
+ ---
255
+
256
+ ## Testing
257
+
258
+ ```bash
259
+ npm test
260
+ ```
261
+
262
+ Runs `node --test tests/*.test.js`. Built-in test runner; tests import directly from `src/`.
263
+
264
+ ---
265
+
266
+ ## Gotchas
267
+
268
+ - `engram.db` is local and not portable across machines without also syncing the vector index.
269
+ - Run `npm run qdrant:sync` once when switching vector stores or after bulk SQLite imports.
270
+ - `add_memory` requires an LLM API key. Read-only tools work without one.
271
+ - Memory IDs: legacy `mem_*` short IDs and new UUIDv4 both exist.
272
+
273
+ ---
274
+
275
+ ## License
276
+
277
+ MIT.
278
+
279
+ The optimized brain atlas is derived from the Human Reference Atlas v1.3
280
+ 3D Male Allen Brain by the HuBMAP Consortium, licensed under
281
+ [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). Source and modification
282
+ details are recorded in `public/assets/brain-atlas.LICENSE.txt`.
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "atlas-mcp",
3
+ "version": "0.1.0",
4
+ "description": "Brain-inspired semantic memory system and MCP server",
5
+ "author": "sidmanale",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/sidmanale643/Atlas"
10
+ },
11
+ "type": "module",
12
+ "engines": {
13
+ "node": ">=18"
14
+ },
15
+ "files": [
16
+ "src/",
17
+ "public/",
18
+ "scripts/sync-memory-vectors.js",
19
+ ".env.example"
20
+ ],
21
+ "bin": {
22
+ "atlas": "./src/cli.js",
23
+ "atlas-mcp": "./src/mcp-server.js"
24
+ },
25
+ "scripts": {
26
+ "start": "node src/server.js",
27
+ "dev": "node --watch src/server.js",
28
+ "dev:web": "vite",
29
+ "build:web": "vite build",
30
+ "build:brain-atlas": "node scripts/build-brain-atlas.js",
31
+ "mcp": "node src/mcp-server.js",
32
+ "cli": "node src/cli.js",
33
+ "qdrant:sync": "node scripts/sync-memory-vectors.js",
34
+ "worker:cognitive": "node src/run-cognitive-worker.js",
35
+ "worker:vector": "node src/run-vector-worker.js",
36
+ "worker:ingestion": "node src/run-ingestion-worker.js",
37
+ "audit": "node src/audit.js",
38
+ "eval:v3": "node scripts/evaluate-extraction-v3.js",
39
+ "test": "node --test tests/*.test.js"
40
+ },
41
+ "dependencies": {
42
+ "@huggingface/transformers": "^4.2.0",
43
+ "@lancedb/lancedb": "^0.30.0",
44
+ "@modelcontextprotocol/sdk": "^1.29.0",
45
+ "@qdrant/js-client-rest": "^1.18.0",
46
+ "@supabase/supabase-js": "^2.108.1",
47
+ "apache-arrow": "^18.1.0",
48
+ "better-sqlite3": "^12.10.0",
49
+ "dotenv": "^16.4.7",
50
+ "express": "^4.21.2",
51
+ "zod": "^4.4.3"
52
+ },
53
+ "devDependencies": {
54
+ "@gltf-transform/core": "^4.4.0",
55
+ "@gltf-transform/extensions": "^4.4.0",
56
+ "@gltf-transform/functions": "^4.4.0",
57
+ "@types/d3": "^7.4.3",
58
+ "@types/react": "^18.3.12",
59
+ "@types/react-dom": "^18.3.1",
60
+ "@types/three": "^0.177.0",
61
+ "@vitejs/plugin-react": "^4.3.4",
62
+ "d3": "^7.9.0",
63
+ "framer-motion": "^11.18.2",
64
+ "meshoptimizer": "^0.24.0",
65
+ "react": "^18.3.1",
66
+ "react-dom": "^18.3.1",
67
+ "react-router-dom": "^6.28.0",
68
+ "three": "^0.177.0",
69
+ "typescript": "^5.6.3",
70
+ "vite": "^5.4.11"
71
+ }
72
+ }