forget-me-not-mcp 0.0.0-stage → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +169 -2
- package/dist/backup.js +33 -0
- package/dist/db.js +97 -0
- package/dist/embedder.js +59 -0
- package/dist/index.js +62 -0
- package/dist/logger.js +33 -0
- package/dist/semantic.js +200 -0
- package/dist/server.js +176 -0
- package/dist/store.js +250 -0
- package/package.json +52 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ranga Surendra
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,170 @@
|
|
|
1
|
-
#
|
|
1
|
+
# forget-me-not-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A local MCP server that gives Claude Code a memory across sessions. Claude can save decisions, non-obvious error fixes, project facts and your preferences, then find them again in later sessions. Search combines keywords (exact error codes, names) with meaning, so "where is the backend hosted" finds "We deploy the API to Azure Container Apps".
|
|
4
|
+
|
|
5
|
+
Everything is kept in one SQLite file on your machine. The embedding model runs inside the server, so there's no Ollama, no API key and no cloud service, and your memories never leave your computer.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- Node.js 22 or later
|
|
10
|
+
- Claude Code
|
|
11
|
+
|
|
12
|
+
The SQLite driver ships ready-made binaries for Windows, macOS and Linux (x64 and arm64), so no compiler is needed.
|
|
13
|
+
|
|
14
|
+
## Quick start
|
|
15
|
+
|
|
16
|
+
Register the server with Claude Code. `npx` downloads it on first use.
|
|
17
|
+
|
|
18
|
+
**macOS / Linux**
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
claude mcp add memory -s user -- npx -y forget-me-not-mcp
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
**Windows (PowerShell)**
|
|
25
|
+
|
|
26
|
+
```powershell
|
|
27
|
+
claude mcp add memory -s user -- cmd /c npx -y forget-me-not-mcp
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
On Windows `npx` is a `.cmd` script, so it has to be started through `cmd /c`.
|
|
31
|
+
|
|
32
|
+
Check that it connected:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
claude mcp list
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Then tell Claude when to use it. Add this to `~/.claude/CLAUDE.md` (all projects) or to a project's `CLAUDE.md`. Without these rules, Claude rarely calls the tools.
|
|
39
|
+
|
|
40
|
+
```markdown
|
|
41
|
+
## Memory
|
|
42
|
+
- At the start of a task, call `get_context` for the current project (the repo folder name), then `search` for the topic.
|
|
43
|
+
- Save with `remember` when a decision is made, a non-obvious bug is fixed, or I state a lasting fact.
|
|
44
|
+
- When a fact changes, use `supersede`, never a duplicate `remember`.
|
|
45
|
+
- Don't save secrets, keys, connection strings or temporary state.
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Enable it only in some projects
|
|
49
|
+
|
|
50
|
+
`-s user` turns the server on in every project. To turn it on only in chosen projects, run the `claude mcp add` command from each project's root with a narrower scope:
|
|
51
|
+
|
|
52
|
+
| Scope | Flag | Stored in | Shared through git? |
|
|
53
|
+
| --- | --- | --- | --- |
|
|
54
|
+
| Local (default) | `-s local` | your `~/.claude.json`, under that project | No |
|
|
55
|
+
| Project | `-s project` | `.mcp.json` in the project root | Yes, if you commit it |
|
|
56
|
+
|
|
57
|
+
With project scope, the resulting `.mcp.json` looks like this. Claude Code asks you to approve it the first time you open the project.
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"mcpServers": {
|
|
62
|
+
"memory": {
|
|
63
|
+
"type": "stdio",
|
|
64
|
+
"command": "cmd",
|
|
65
|
+
"args": ["/c", "npx", "-y", "forget-me-not-mcp"]
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
On macOS and Linux, use `"command": "npx"` and `"args": ["-y", "forget-me-not-mcp"]`.
|
|
72
|
+
|
|
73
|
+
When the server is on only in some projects, put the usage rules in each of those projects' `CLAUDE.md`, not the user-level one. Also name the project there, for example ``This project's memory name is `my-app`. Pass it as `project` on every memory tool call.``
|
|
74
|
+
|
|
75
|
+
## Tools
|
|
76
|
+
|
|
77
|
+
| Tool | Purpose |
|
|
78
|
+
| --- | --- |
|
|
79
|
+
| `remember` | Save a memory (`content`, `type`, optional `project`, `tags`, `pinned`) |
|
|
80
|
+
| `search` | Hybrid keyword + semantic search over active memories, best match first. Filters: `project`, `type`, `include_global`, `limit` |
|
|
81
|
+
| `get_context` | Pinned and most recent memories for a project (plus global ones), for the start of a session |
|
|
82
|
+
| `update_memory` | Edit content, tags, type or pinning in place |
|
|
83
|
+
| `supersede` | Replace a memory with a new one. The old one is hidden from search but kept |
|
|
84
|
+
| `forget` | Soft-delete a memory by id |
|
|
85
|
+
| `history` | Show the earlier versions a memory replaced |
|
|
86
|
+
| `link` / `related` | Record relations between named things (`api` uses `postgres`) and list them |
|
|
87
|
+
| `export` | Write all active memories to a Markdown file and return its path |
|
|
88
|
+
| `status` | Server version, memory counts, and whether semantic search is ready |
|
|
89
|
+
|
|
90
|
+
Memory types are `decision`, `fact`, `error_fix`, `preference` and `note`. A memory saved without a project is global and shows up in every project's search and context.
|
|
91
|
+
|
|
92
|
+
## Semantic search
|
|
93
|
+
|
|
94
|
+
Each memory is turned into a 768-number vector by [nomic-embed-text-v1.5](https://huggingface.co/nomic-ai/nomic-embed-text-v1.5), run in-process by [Transformers.js](https://huggingface.co/docs/transformers.js) on ONNX Runtime. The vectors are stored in the same SQLite file.
|
|
95
|
+
|
|
96
|
+
A search runs two retrievers and merges their rankings (reciprocal rank fusion):
|
|
97
|
+
|
|
98
|
+
- **Keyword** (SQLite FTS5, BM25) is best for exact terms: `SQLITE_BUSY`, file names, library names.
|
|
99
|
+
- **Semantic** (cosine similarity) is best for reworded questions: "how are bills created" finds "Customer invoices are generated nightly".
|
|
100
|
+
|
|
101
|
+
Each result has a `match` field (`keyword`, `semantic` or `both`) and, for semantic matches, a `similarity` score. Semantic matches below 0.45 similarity are dropped, so an unrelated question returns nothing rather than the nearest unrelated memory.
|
|
102
|
+
|
|
103
|
+
**What to expect:**
|
|
104
|
+
|
|
105
|
+
- **First run:** the model (about 130 MB) is downloaded from Hugging Face into `~/.claude/memory/models`. After that it works offline. The server answers immediately during the download; search is keyword-only until the model is ready.
|
|
106
|
+
- **Speed:** loading from cache takes under a second, and a search takes about 10 ms.
|
|
107
|
+
- **Memory use:** about 400 MB of RAM per running server with the model loaded, against about 70 MB keyword-only. Each open Claude Code session runs its own server.
|
|
108
|
+
- **Install size:** Transformers.js and ONNX Runtime add roughly 450 MB to the install, because they include binaries for every platform. They are optional dependencies: if they fail to install, the server still runs keyword-only.
|
|
109
|
+
- **Existing memories** are embedded automatically in the background. Edited memories are re-embedded.
|
|
110
|
+
- **No model available** (offline first run, or an unsupported platform): search falls back to keyword-only and `status` shows the reason. It retries every 5 minutes.
|
|
111
|
+
|
|
112
|
+
To turn semantic search off, set `MEMORY_EMBEDDINGS=off`.
|
|
113
|
+
|
|
114
|
+
## Where data is kept
|
|
115
|
+
|
|
116
|
+
By default everything is in `~/.claude/memory/` (`%USERPROFILE%\.claude\memory\` on Windows):
|
|
117
|
+
|
|
118
|
+
| Path | What |
|
|
119
|
+
| --- | --- |
|
|
120
|
+
| `memory.db` | The SQLite database |
|
|
121
|
+
| `backups/memory-YYYYMMDD.db` | One backup per day, taken when the server starts. The newest 7 are kept |
|
|
122
|
+
| `exports/*.md` | Files written by the `export` tool |
|
|
123
|
+
| `memory-mcp.log` | Log file, rotated at 5 MB |
|
|
124
|
+
| `models/` | The cached embedding model, shared by all databases on the machine |
|
|
125
|
+
|
|
126
|
+
Settings, passed with `-e NAME=value` on `claude mcp add` or in `env` in `.mcp.json`:
|
|
127
|
+
|
|
128
|
+
| Variable | Default |
|
|
129
|
+
| --- | --- |
|
|
130
|
+
| `MEMORY_DB_PATH` | `~/.claude/memory/memory.db` |
|
|
131
|
+
| `MEMORY_EXPORT_DIR` | `exports` next to the database |
|
|
132
|
+
| `MEMORY_LOG_PATH` | `memory-mcp.log` next to the database |
|
|
133
|
+
| `MEMORY_BACKUP` | Set to `off` to turn off the daily backup |
|
|
134
|
+
| `MEMORY_EMBEDDINGS` | Set to `off` for keyword-only search (no model download) |
|
|
135
|
+
| `MEMORY_MODEL_DIR` | `~/.claude/memory/models` |
|
|
136
|
+
| `MEMORY_EMBED_DTYPE` | `q8` (quantised, ~130 MB). `fp32` is slightly more accurate and about 4 times larger |
|
|
137
|
+
| `MEMORY_MIN_SIMILARITY` | `0.45`. Semantic matches below this are dropped |
|
|
138
|
+
|
|
139
|
+
To keep a project's memories in a separate file, give that project its own `MEMORY_DB_PATH`.
|
|
140
|
+
|
|
141
|
+
Limits: up to 8,000 characters of content and 500 characters of tags per memory.
|
|
142
|
+
|
|
143
|
+
## Development
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
npm install
|
|
147
|
+
npm run build
|
|
148
|
+
npm test
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
To run a local build instead of the published package, register it with `node <path-to-repo>/dist/index.js` in place of the `npx` command.
|
|
152
|
+
|
|
153
|
+
The code is in `src/`:
|
|
154
|
+
|
|
155
|
+
| File | What it does |
|
|
156
|
+
| --- | --- |
|
|
157
|
+
| `index.ts` | Entry point: settings, logging, backup, stdio transport |
|
|
158
|
+
| `server.ts` | MCP tool definitions |
|
|
159
|
+
| `store.ts` | All queries: remember, keyword search, supersede, export |
|
|
160
|
+
| `semantic.ts` | Background embedding, vector search, and fusion with keyword results |
|
|
161
|
+
| `embedder.ts` | The nomic-embed-text model, behind an interface so it can be swapped |
|
|
162
|
+
| `db.ts` | Database connection and schema migrations |
|
|
163
|
+
| `backup.ts` | Daily backup |
|
|
164
|
+
| `logger.ts` | File logger. stdout is reserved for the MCP protocol, so nothing is printed there |
|
|
165
|
+
|
|
166
|
+
To change the schema, add a new SQL string to `MIGRATIONS` in `src/db.ts`. Never edit one that has already shipped.
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
MIT
|
package/dist/backup.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { log } from "./logger.js";
|
|
4
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
5
|
+
/**
|
|
6
|
+
* Take at most one backup per day, keep the newest `keep` copies.
|
|
7
|
+
* Runs at server start-up instead of a scheduled task: Claude Code launches
|
|
8
|
+
* the server whenever a session starts, which is often enough for a local DB.
|
|
9
|
+
* `db.backup()` uses SQLite's online backup API, so it is safe while the
|
|
10
|
+
* database is open (a plain file copy of a WAL database is not).
|
|
11
|
+
*/
|
|
12
|
+
export async function dailyBackup(db, backupDir, keep = 7) {
|
|
13
|
+
fs.mkdirSync(backupDir, { recursive: true });
|
|
14
|
+
const existing = fs
|
|
15
|
+
.readdirSync(backupDir)
|
|
16
|
+
.filter((f) => /^memory-\d{8}\.db$/.test(f))
|
|
17
|
+
.sort();
|
|
18
|
+
const newest = existing.at(-1);
|
|
19
|
+
if (newest && Date.now() - fs.statSync(path.join(backupDir, newest)).mtimeMs < DAY_MS)
|
|
20
|
+
return null;
|
|
21
|
+
const stamp = new Date().toISOString().slice(0, 10).replace(/-/g, "");
|
|
22
|
+
const target = path.join(backupDir, `memory-${stamp}.db`);
|
|
23
|
+
await db.backup(target);
|
|
24
|
+
log("info", `backup written to ${target}`);
|
|
25
|
+
const all = fs
|
|
26
|
+
.readdirSync(backupDir)
|
|
27
|
+
.filter((f) => /^memory-\d{8}\.db$/.test(f))
|
|
28
|
+
.sort();
|
|
29
|
+
for (const old of all.slice(0, Math.max(0, all.length - keep))) {
|
|
30
|
+
fs.rmSync(path.join(backupDir, old));
|
|
31
|
+
}
|
|
32
|
+
return target;
|
|
33
|
+
}
|
package/dist/db.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import Database from "better-sqlite3";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
/**
|
|
5
|
+
* Ordered list of migrations. Each entry moves the schema from version i to i+1.
|
|
6
|
+
* The current version lives in SQLite's built-in `PRAGMA user_version`, so no
|
|
7
|
+
* bookkeeping table is needed. Never edit a shipped migration; append a new one.
|
|
8
|
+
*/
|
|
9
|
+
const MIGRATIONS = [
|
|
10
|
+
// v1 — schema from the implementation plan, plus `pinned` for get_context.
|
|
11
|
+
`
|
|
12
|
+
CREATE TABLE memories (
|
|
13
|
+
id INTEGER PRIMARY KEY,
|
|
14
|
+
project TEXT,
|
|
15
|
+
type TEXT NOT NULL CHECK (type IN ('decision','fact','error_fix','preference','note')),
|
|
16
|
+
content TEXT NOT NULL,
|
|
17
|
+
tags TEXT,
|
|
18
|
+
status TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('active','superseded','deleted')),
|
|
19
|
+
pinned INTEGER NOT NULL DEFAULT 0,
|
|
20
|
+
supersedes_id INTEGER REFERENCES memories(id),
|
|
21
|
+
created_at TEXT NOT NULL,
|
|
22
|
+
updated_at TEXT NOT NULL
|
|
23
|
+
);
|
|
24
|
+
CREATE INDEX idx_memories_project_status ON memories(project, status, updated_at);
|
|
25
|
+
|
|
26
|
+
CREATE VIRTUAL TABLE memories_fts USING fts5(
|
|
27
|
+
content, tags, content='memories', content_rowid='id', tokenize='unicode61'
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
-- External-content FTS tables are not maintained automatically; these
|
|
31
|
+
-- triggers keep the index in sync with the base table.
|
|
32
|
+
CREATE TRIGGER memories_ai AFTER INSERT ON memories BEGIN
|
|
33
|
+
INSERT INTO memories_fts(rowid, content, tags) VALUES (new.id, new.content, new.tags);
|
|
34
|
+
END;
|
|
35
|
+
CREATE TRIGGER memories_ad AFTER DELETE ON memories BEGIN
|
|
36
|
+
INSERT INTO memories_fts(memories_fts, rowid, content, tags) VALUES ('delete', old.id, old.content, old.tags);
|
|
37
|
+
END;
|
|
38
|
+
CREATE TRIGGER memories_au AFTER UPDATE OF content, tags ON memories BEGIN
|
|
39
|
+
INSERT INTO memories_fts(memories_fts, rowid, content, tags) VALUES ('delete', old.id, old.content, old.tags);
|
|
40
|
+
INSERT INTO memories_fts(rowid, content, tags) VALUES (new.id, new.content, new.tags);
|
|
41
|
+
END;
|
|
42
|
+
|
|
43
|
+
CREATE TABLE entities (
|
|
44
|
+
id INTEGER PRIMARY KEY,
|
|
45
|
+
name TEXT NOT NULL UNIQUE,
|
|
46
|
+
kind TEXT
|
|
47
|
+
);
|
|
48
|
+
CREATE TABLE relations (
|
|
49
|
+
from_id INTEGER NOT NULL REFERENCES entities(id),
|
|
50
|
+
to_id INTEGER NOT NULL REFERENCES entities(id),
|
|
51
|
+
label TEXT NOT NULL,
|
|
52
|
+
created_at TEXT NOT NULL,
|
|
53
|
+
UNIQUE (from_id, to_id, label)
|
|
54
|
+
);
|
|
55
|
+
`,
|
|
56
|
+
// v2 — semantic search. One vector per memory, stored as a little-endian
|
|
57
|
+
// Float32 BLOB. `model` records which model produced it, so switching models
|
|
58
|
+
// makes old vectors stale (they are skipped and re-embedded).
|
|
59
|
+
`
|
|
60
|
+
CREATE TABLE memory_embeddings (
|
|
61
|
+
memory_id INTEGER PRIMARY KEY REFERENCES memories(id) ON DELETE CASCADE,
|
|
62
|
+
model TEXT NOT NULL,
|
|
63
|
+
dim INTEGER NOT NULL,
|
|
64
|
+
embedding BLOB NOT NULL,
|
|
65
|
+
created_at TEXT NOT NULL
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
-- Editing content invalidates the vector; the background indexer re-embeds it.
|
|
69
|
+
CREATE TRIGGER memories_embedding_stale AFTER UPDATE OF content ON memories
|
|
70
|
+
WHEN old.content IS NOT new.content BEGIN
|
|
71
|
+
DELETE FROM memory_embeddings WHERE memory_id = old.id;
|
|
72
|
+
END;
|
|
73
|
+
`,
|
|
74
|
+
];
|
|
75
|
+
export function openDb(dbPath) {
|
|
76
|
+
if (dbPath !== ":memory:") {
|
|
77
|
+
fs.mkdirSync(path.dirname(dbPath), { recursive: true });
|
|
78
|
+
}
|
|
79
|
+
const db = new Database(dbPath);
|
|
80
|
+
db.pragma("journal_mode = WAL"); // readers never block the single writer
|
|
81
|
+
db.pragma("foreign_keys = ON");
|
|
82
|
+
db.pragma("busy_timeout = 5000"); // two Claude sessions may share the file
|
|
83
|
+
migrate(db);
|
|
84
|
+
return db;
|
|
85
|
+
}
|
|
86
|
+
export function migrate(db) {
|
|
87
|
+
const current = db.pragma("user_version", { simple: true });
|
|
88
|
+
for (let v = current; v < MIGRATIONS.length; v++) {
|
|
89
|
+
db.transaction(() => {
|
|
90
|
+
db.exec(MIGRATIONS[v]);
|
|
91
|
+
db.pragma(`user_version = ${v + 1}`);
|
|
92
|
+
})();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export function schemaVersion() {
|
|
96
|
+
return MIGRATIONS.length;
|
|
97
|
+
}
|
package/dist/embedder.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* nomic-embed-text-v1.5 run in-process with Transformers.js (ONNX Runtime).
|
|
3
|
+
* No Ollama or Python: the model is downloaded from Hugging Face on first use
|
|
4
|
+
* and cached under `cacheDir`; after that it works offline.
|
|
5
|
+
*
|
|
6
|
+
* Nomic models are trained with task prefixes: documents must be embedded as
|
|
7
|
+
* "search_document: ..." and queries as "search_query: ...". Leaving them out
|
|
8
|
+
* noticeably hurts retrieval quality.
|
|
9
|
+
*/
|
|
10
|
+
export class NomicEmbedder {
|
|
11
|
+
opts;
|
|
12
|
+
static MODEL_ID = "nomic-ai/nomic-embed-text-v1.5";
|
|
13
|
+
dim = 768;
|
|
14
|
+
model;
|
|
15
|
+
extractor = null;
|
|
16
|
+
loading = null;
|
|
17
|
+
constructor(opts) {
|
|
18
|
+
this.opts = opts;
|
|
19
|
+
this.model = `${NomicEmbedder.MODEL_ID}:${opts.dtype ?? "q8"}`;
|
|
20
|
+
}
|
|
21
|
+
init() {
|
|
22
|
+
this.loading ??= (async () => {
|
|
23
|
+
// Dynamic import: the package is an optional dependency, and loading
|
|
24
|
+
// ONNX Runtime costs startup time we don't want on the MCP handshake.
|
|
25
|
+
const { pipeline, env } = await import("@huggingface/transformers");
|
|
26
|
+
env.cacheDir = this.opts.cacheDir;
|
|
27
|
+
const pipe = await pipeline("feature-extraction", NomicEmbedder.MODEL_ID, {
|
|
28
|
+
dtype: (this.opts.dtype ?? "q8"),
|
|
29
|
+
});
|
|
30
|
+
this.extractor = pipe;
|
|
31
|
+
})().catch((err) => {
|
|
32
|
+
this.loading = null; // allow a later retry
|
|
33
|
+
throw err;
|
|
34
|
+
});
|
|
35
|
+
return this.loading;
|
|
36
|
+
}
|
|
37
|
+
async embed(texts, kind) {
|
|
38
|
+
await this.init();
|
|
39
|
+
const prefix = kind === "document" ? "search_document: " : "search_query: ";
|
|
40
|
+
const out = await this.extractor(texts.map((t) => prefix + t), { pooling: "mean", normalize: true });
|
|
41
|
+
return out.tolist().map((v) => Float32Array.from(v));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** Float32Array <-> SQLite BLOB. */
|
|
45
|
+
export function toBlob(v) {
|
|
46
|
+
return Buffer.from(v.buffer, v.byteOffset, v.byteLength);
|
|
47
|
+
}
|
|
48
|
+
export function fromBlob(b) {
|
|
49
|
+
// Copy: a Buffer slice may not be 4-byte aligned, which Float32Array requires.
|
|
50
|
+
const copy = new Uint8Array(b.byteLength);
|
|
51
|
+
copy.set(b);
|
|
52
|
+
return new Float32Array(copy.buffer);
|
|
53
|
+
}
|
|
54
|
+
export function dot(a, b) {
|
|
55
|
+
let s = 0;
|
|
56
|
+
for (let i = 0; i < a.length; i++)
|
|
57
|
+
s += a[i] * b[i];
|
|
58
|
+
return s;
|
|
59
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { openDb } from "./db.js";
|
|
7
|
+
import { MemoryStore } from "./store.js";
|
|
8
|
+
import { createServer } from "./server.js";
|
|
9
|
+
import { initLogger, log } from "./logger.js";
|
|
10
|
+
import { dailyBackup } from "./backup.js";
|
|
11
|
+
import { NomicEmbedder } from "./embedder.js";
|
|
12
|
+
import { SemanticIndex } from "./semantic.js";
|
|
13
|
+
// Read the version from package.json (one level above dist/) so it can't drift.
|
|
14
|
+
const VERSION = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
15
|
+
const dbPath = process.env.MEMORY_DB_PATH || path.join(os.homedir(), ".claude", "memory", "memory.db");
|
|
16
|
+
const dataDir = path.dirname(dbPath);
|
|
17
|
+
initLogger(process.env.MEMORY_LOG_PATH || path.join(dataDir, "memory-mcp.log"));
|
|
18
|
+
async function main() {
|
|
19
|
+
const db = openDb(dbPath);
|
|
20
|
+
log("info", `forget-me-not-mcp ${VERSION} started`, { dbPath, pid: process.pid });
|
|
21
|
+
const store = new MemoryStore(db);
|
|
22
|
+
// Semantic search: on unless MEMORY_EMBEDDINGS=off. The model cache is shared
|
|
23
|
+
// by all databases on the machine, so separate per-project DBs don't each
|
|
24
|
+
// download their own copy.
|
|
25
|
+
const embedder = process.env.MEMORY_EMBEDDINGS === "off"
|
|
26
|
+
? null
|
|
27
|
+
: new NomicEmbedder({
|
|
28
|
+
cacheDir: process.env.MEMORY_MODEL_DIR || path.join(os.homedir(), ".claude", "memory", "models"),
|
|
29
|
+
dtype: process.env.MEMORY_EMBED_DTYPE || "q8",
|
|
30
|
+
});
|
|
31
|
+
const minSimilarity = Number(process.env.MEMORY_MIN_SIMILARITY);
|
|
32
|
+
const semantic = new SemanticIndex(db, store, embedder, {
|
|
33
|
+
minSimilarity: Number.isFinite(minSimilarity) && process.env.MEMORY_MIN_SIMILARITY ? minSimilarity : undefined,
|
|
34
|
+
});
|
|
35
|
+
const server = createServer(store, semantic, {
|
|
36
|
+
version: VERSION,
|
|
37
|
+
exportDir: process.env.MEMORY_EXPORT_DIR || path.join(dataDir, "exports"),
|
|
38
|
+
});
|
|
39
|
+
if (process.env.MEMORY_BACKUP !== "off") {
|
|
40
|
+
// Fire and forget: never delay the handshake with Claude Code.
|
|
41
|
+
dailyBackup(db, path.join(dataDir, "backups")).catch((e) => log("warn", "backup failed", e));
|
|
42
|
+
}
|
|
43
|
+
const shutdown = () => {
|
|
44
|
+
try {
|
|
45
|
+
db.close();
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
process.exit(0);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
process.on("SIGINT", shutdown);
|
|
52
|
+
process.on("SIGTERM", shutdown);
|
|
53
|
+
process.stdin.on("close", shutdown); // Claude Code closes stdin when the session ends
|
|
54
|
+
await server.connect(new StdioServerTransport());
|
|
55
|
+
// Load the model only after the handshake, so Claude Code never waits on it.
|
|
56
|
+
// Failures are logged and search stays keyword-only.
|
|
57
|
+
semantic.start().catch(() => { });
|
|
58
|
+
}
|
|
59
|
+
main().catch((err) => {
|
|
60
|
+
log("error", "fatal", err);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
});
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* File logger. stdout carries the MCP JSON-RPC stream, so anything written
|
|
5
|
+
* there (console.log included) corrupts the protocol. Logs go to a file;
|
|
6
|
+
* stderr is used only as a fallback because Claude Code shows it as diagnostics.
|
|
7
|
+
*/
|
|
8
|
+
let logFile = null;
|
|
9
|
+
const MAX_LOG_BYTES = 5 * 1024 * 1024;
|
|
10
|
+
export function initLogger(file) {
|
|
11
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
12
|
+
try {
|
|
13
|
+
if (fs.statSync(file).size > MAX_LOG_BYTES)
|
|
14
|
+
fs.renameSync(file, `${file}.1`);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
/* no existing log */
|
|
18
|
+
}
|
|
19
|
+
logFile = file;
|
|
20
|
+
}
|
|
21
|
+
export function log(level, msg, extra) {
|
|
22
|
+
const line = `${new Date().toISOString()} ${level.toUpperCase()} ${msg}${extra === undefined ? "" : " " + (extra instanceof Error ? extra.stack : JSON.stringify(extra))}\n`;
|
|
23
|
+
if (logFile) {
|
|
24
|
+
try {
|
|
25
|
+
fs.appendFileSync(logFile, line);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
/* fall through */
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
process.stderr.write(line);
|
|
33
|
+
}
|
package/dist/semantic.js
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { dot, fromBlob, toBlob } from "./embedder.js";
|
|
2
|
+
import { log } from "./logger.js";
|
|
3
|
+
/** Standard RRF constant; dampens the advantage of rank 1 over rank 2. */
|
|
4
|
+
const RRF_K = 60;
|
|
5
|
+
/** Candidates taken from each retriever before fusion. */
|
|
6
|
+
const CANDIDATES = 50;
|
|
7
|
+
const toMemory = (r) => ({ ...r, pinned: r.pinned === 1 });
|
|
8
|
+
/**
|
|
9
|
+
* Hybrid retrieval over the memory store.
|
|
10
|
+
*
|
|
11
|
+
* - Keyword (FTS5/BM25) and semantic (embedding cosine) results are merged with
|
|
12
|
+
* reciprocal rank fusion, so neither score scale has to be calibrated.
|
|
13
|
+
* - The model loads in the background. Until it's ready, search quietly falls
|
|
14
|
+
* back to keyword-only, so the MCP server is usable from the first second.
|
|
15
|
+
* - Vectors are compared by brute force in JS. At personal-memory scale
|
|
16
|
+
* (thousands of rows) that takes a few milliseconds and needs no extension.
|
|
17
|
+
*/
|
|
18
|
+
export class SemanticIndex {
|
|
19
|
+
db;
|
|
20
|
+
store;
|
|
21
|
+
embedder;
|
|
22
|
+
status;
|
|
23
|
+
ready = null;
|
|
24
|
+
lastError = null;
|
|
25
|
+
failedAt = 0;
|
|
26
|
+
indexing = null;
|
|
27
|
+
rerun = false;
|
|
28
|
+
opts;
|
|
29
|
+
constructor(db, store, embedder, opts = {}) {
|
|
30
|
+
this.db = db;
|
|
31
|
+
this.store = store;
|
|
32
|
+
this.embedder = embedder;
|
|
33
|
+
this.status = embedder ? "loading" : "off";
|
|
34
|
+
this.opts = {
|
|
35
|
+
minSimilarity: opts.minSimilarity ?? 0.45,
|
|
36
|
+
readyWaitMs: opts.readyWaitMs ?? 5000,
|
|
37
|
+
batchSize: opts.batchSize ?? 32,
|
|
38
|
+
retryAfterMs: opts.retryAfterMs ?? 5 * 60 * 1000,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
info() {
|
|
42
|
+
const counts = this.embedder
|
|
43
|
+
? this.db
|
|
44
|
+
.prepare(`SELECT COUNT(*) AS active,
|
|
45
|
+
SUM(CASE WHEN e.model = @model THEN 1 ELSE 0 END) AS embedded
|
|
46
|
+
FROM memories m LEFT JOIN memory_embeddings e ON e.memory_id = m.id
|
|
47
|
+
WHERE m.status = 'active'`)
|
|
48
|
+
.get({ model: this.embedder.model })
|
|
49
|
+
: null;
|
|
50
|
+
return {
|
|
51
|
+
status: this.status,
|
|
52
|
+
model: this.embedder?.model ?? null,
|
|
53
|
+
...(counts ? { active: counts.active, embedded: counts.embedded ?? 0 } : {}),
|
|
54
|
+
...(this.lastError ? { error: this.lastError } : {}),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** Start loading the model (no-op if loading, loaded, or recently failed). Then backfill. */
|
|
58
|
+
start() {
|
|
59
|
+
if (!this.embedder)
|
|
60
|
+
return Promise.resolve();
|
|
61
|
+
if (this.ready)
|
|
62
|
+
return this.ready;
|
|
63
|
+
if (this.status === "error" && Date.now() - this.failedAt < this.opts.retryAfterMs) {
|
|
64
|
+
return Promise.reject(new Error(this.lastError ?? "embedder unavailable"));
|
|
65
|
+
}
|
|
66
|
+
this.status = "loading";
|
|
67
|
+
const started = Date.now();
|
|
68
|
+
this.ready = this.embedder.init().then(() => {
|
|
69
|
+
this.status = "ready";
|
|
70
|
+
this.lastError = null;
|
|
71
|
+
log("info", `embedder ${this.embedder.model} ready in ${Date.now() - started} ms`);
|
|
72
|
+
this.schedule();
|
|
73
|
+
}, (err) => {
|
|
74
|
+
this.status = "error";
|
|
75
|
+
this.failedAt = Date.now();
|
|
76
|
+
this.lastError = err instanceof Error ? err.message : String(err);
|
|
77
|
+
this.ready = null;
|
|
78
|
+
log("warn", "embedder failed to load; search is keyword-only", err);
|
|
79
|
+
throw err;
|
|
80
|
+
});
|
|
81
|
+
return this.ready;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Embed every active memory that has no vector for the current model.
|
|
85
|
+
* Call after any write; repeated calls while running coalesce into one more pass.
|
|
86
|
+
*/
|
|
87
|
+
schedule() {
|
|
88
|
+
if (!this.embedder || this.status !== "ready")
|
|
89
|
+
return Promise.resolve();
|
|
90
|
+
if (this.indexing) {
|
|
91
|
+
this.rerun = true;
|
|
92
|
+
return this.indexing;
|
|
93
|
+
}
|
|
94
|
+
this.indexing = (async () => {
|
|
95
|
+
do {
|
|
96
|
+
this.rerun = false;
|
|
97
|
+
await this.indexPending();
|
|
98
|
+
} while (this.rerun);
|
|
99
|
+
})()
|
|
100
|
+
.catch((err) => log("error", "embedding backfill failed", err))
|
|
101
|
+
.finally(() => {
|
|
102
|
+
this.indexing = null;
|
|
103
|
+
});
|
|
104
|
+
return this.indexing;
|
|
105
|
+
}
|
|
106
|
+
async indexPending() {
|
|
107
|
+
const embedder = this.embedder;
|
|
108
|
+
const pending = this.db.prepare(`SELECT m.id, m.content FROM memories m
|
|
109
|
+
LEFT JOIN memory_embeddings e ON e.memory_id = m.id AND e.model = @model
|
|
110
|
+
WHERE m.status = 'active' AND e.memory_id IS NULL AND m.id > @after
|
|
111
|
+
ORDER BY m.id LIMIT @limit`);
|
|
112
|
+
// Only store the vector if the content is still what we embedded; an edit
|
|
113
|
+
// during the (async) embed call must not leave a stale vector behind.
|
|
114
|
+
const upsert = this.db.prepare(`INSERT OR REPLACE INTO memory_embeddings (memory_id, model, dim, embedding, created_at)
|
|
115
|
+
SELECT @id, @model, @dim, @embedding, @now
|
|
116
|
+
WHERE EXISTS (SELECT 1 FROM memories WHERE id = @id AND content = @content)`);
|
|
117
|
+
let total = 0;
|
|
118
|
+
// Walk forward by id so a row whose insert was skipped (edited mid-embed)
|
|
119
|
+
// can't stall the loop; the write that edited it schedules another pass.
|
|
120
|
+
let after = 0;
|
|
121
|
+
for (;;) {
|
|
122
|
+
const rows = pending.all({ model: embedder.model, limit: this.opts.batchSize, after });
|
|
123
|
+
if (!rows.length)
|
|
124
|
+
break;
|
|
125
|
+
const vectors = await embedder.embed(rows.map((r) => r.content), "document");
|
|
126
|
+
const now = new Date().toISOString();
|
|
127
|
+
this.db.transaction(() => {
|
|
128
|
+
rows.forEach((r, i) => {
|
|
129
|
+
upsert.run({ id: r.id, model: embedder.model, dim: vectors[i].length, embedding: toBlob(vectors[i]), content: r.content, now });
|
|
130
|
+
});
|
|
131
|
+
})();
|
|
132
|
+
after = rows[rows.length - 1].id;
|
|
133
|
+
total += rows.length;
|
|
134
|
+
}
|
|
135
|
+
if (total)
|
|
136
|
+
log("info", `embedded ${total} memories`);
|
|
137
|
+
}
|
|
138
|
+
/** Cosine top-k over active memories that match the filters. */
|
|
139
|
+
vectorSearch(query, input, k) {
|
|
140
|
+
const { where, params } = this.store.filterClauses(input);
|
|
141
|
+
const rows = this.db
|
|
142
|
+
.prepare(`SELECT m.*, e.embedding AS _embedding FROM memories m
|
|
143
|
+
JOIN memory_embeddings e ON e.memory_id = m.id AND e.model = @model
|
|
144
|
+
WHERE ${where.join(" AND ")}`)
|
|
145
|
+
.all({ ...params, model: this.embedder.model });
|
|
146
|
+
return rows
|
|
147
|
+
.map(({ _embedding, ...r }) => ({ memory: toMemory(r), similarity: dot(query, fromBlob(_embedding)) }))
|
|
148
|
+
.filter((h) => h.similarity >= this.opts.minSimilarity)
|
|
149
|
+
.sort((a, b) => b.similarity - a.similarity)
|
|
150
|
+
.slice(0, k);
|
|
151
|
+
}
|
|
152
|
+
/** Wait for the model if it's loading, but never longer than readyWaitMs. */
|
|
153
|
+
async waitReady() {
|
|
154
|
+
if (this.status === "ready")
|
|
155
|
+
return true;
|
|
156
|
+
if (!this.embedder)
|
|
157
|
+
return false;
|
|
158
|
+
const ready = this.start().then(() => true, () => false);
|
|
159
|
+
const timeout = new Promise((r) => setTimeout(r, this.opts.readyWaitMs, false).unref());
|
|
160
|
+
return Promise.race([ready, timeout]);
|
|
161
|
+
}
|
|
162
|
+
async search(input) {
|
|
163
|
+
const limit = Math.min(Math.max(input.limit ?? 10, 1), 50);
|
|
164
|
+
const keyword = this.store.search({ ...input, limit: CANDIDATES });
|
|
165
|
+
let semantic = [];
|
|
166
|
+
if (await this.waitReady()) {
|
|
167
|
+
try {
|
|
168
|
+
const [q] = await this.embedder.embed([input.query], "query");
|
|
169
|
+
semantic = this.vectorSearch(q, input, CANDIDATES);
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
log("warn", "query embedding failed; keyword-only result", err);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// Reciprocal rank fusion: score = Σ 1 / (k + rank) over the lists an item appears in.
|
|
176
|
+
const fused = new Map();
|
|
177
|
+
keyword.forEach((m, rank) => {
|
|
178
|
+
const { score: _bm25, ...memory } = m;
|
|
179
|
+
fused.set(m.id, { ...memory, score: 1 / (RRF_K + rank + 1), match: "keyword" });
|
|
180
|
+
});
|
|
181
|
+
semantic.forEach(({ memory, similarity }, rank) => {
|
|
182
|
+
const add = 1 / (RRF_K + rank + 1);
|
|
183
|
+
const hit = fused.get(memory.id);
|
|
184
|
+
const sim = Math.round(similarity * 1000) / 1000;
|
|
185
|
+
if (hit) {
|
|
186
|
+
hit.score += add;
|
|
187
|
+
hit.match = "both";
|
|
188
|
+
hit.similarity = sim;
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
fused.set(memory.id, { ...memory, score: add, match: "semantic", similarity: sim });
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
const results = [...fused.values()]
|
|
195
|
+
.sort((a, b) => b.score - a.score || b.updated_at.localeCompare(a.updated_at))
|
|
196
|
+
.slice(0, limit)
|
|
197
|
+
.map((r) => ({ ...r, score: Math.round(r.score * 10000) / 10000 }));
|
|
198
|
+
return { semantic: this.status, results };
|
|
199
|
+
}
|
|
200
|
+
}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { MemoryError, MEMORY_TYPES, MAX_CONTENT_CHARS } from "./store.js";
|
|
6
|
+
import { log } from "./logger.js";
|
|
7
|
+
const typeSchema = z.enum(MEMORY_TYPES);
|
|
8
|
+
const tagsSchema = z
|
|
9
|
+
.union([z.string(), z.array(z.string())])
|
|
10
|
+
.describe('Comma-separated string or array, e.g. "auth,jwt"');
|
|
11
|
+
const projectSchema = z
|
|
12
|
+
.string()
|
|
13
|
+
.describe("Project name, usually the repo folder name. Omit for a global memory that applies everywhere.");
|
|
14
|
+
/** Compact view for the model: drops noise fields, keeps what it needs to act. */
|
|
15
|
+
function brief(m) {
|
|
16
|
+
return {
|
|
17
|
+
id: m.id,
|
|
18
|
+
project: m.project,
|
|
19
|
+
type: m.type,
|
|
20
|
+
content: m.content,
|
|
21
|
+
tags: m.tags,
|
|
22
|
+
...(m.pinned ? { pinned: true } : {}),
|
|
23
|
+
...(m.status !== "active" ? { status: m.status } : {}),
|
|
24
|
+
...(m.supersedes_id ? { supersedes_id: m.supersedes_id } : {}),
|
|
25
|
+
updated: m.updated_at.slice(0, 10),
|
|
26
|
+
...(m.score !== undefined ? { score: m.score } : {}),
|
|
27
|
+
...(m.match ? { match: m.match } : {}),
|
|
28
|
+
...(m.similarity !== undefined ? { similarity: m.similarity } : {}),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const ok = (data) => ({ content: [{ type: "text", text: JSON.stringify(data, null, 2) }] });
|
|
32
|
+
/** Wrap a handler so expected errors come back as tool errors, not crashes. */
|
|
33
|
+
function handle(name, fn) {
|
|
34
|
+
return async (args) => {
|
|
35
|
+
try {
|
|
36
|
+
return ok(await fn(args));
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
40
|
+
if (!(err instanceof MemoryError))
|
|
41
|
+
log("error", `tool ${name} failed`, err);
|
|
42
|
+
return { isError: true, content: [{ type: "text", text: msg }] };
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export function createServer(store, semantic, opts) {
|
|
47
|
+
/** Fire-and-forget: embed new or edited memories in the background. */
|
|
48
|
+
const reindex = (result) => {
|
|
49
|
+
void semantic.schedule();
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
const server = new McpServer({ name: "forget-me-not", version: opts.version }, {
|
|
53
|
+
instructions: "Persistent memory across Claude Code sessions. Call get_context at the start of a task, search before " +
|
|
54
|
+
"re-investigating something, remember lasting decisions/fixes/facts, and use supersede (not remember) " +
|
|
55
|
+
"when a stored fact changes. Never store secrets, keys, tokens or connection strings.",
|
|
56
|
+
});
|
|
57
|
+
server.registerTool("remember", {
|
|
58
|
+
title: "Remember",
|
|
59
|
+
description: `Save a lasting memory: a decision and its reason, a non-obvious error fix, a project fact, or a user preference. ` +
|
|
60
|
+
`Write it so it makes sense with no other context (max ${MAX_CONTENT_CHARS} chars). Search first; if a memory ` +
|
|
61
|
+
`on the same point exists, use supersede or update_memory instead of creating a duplicate.`,
|
|
62
|
+
inputSchema: {
|
|
63
|
+
content: z.string().min(1),
|
|
64
|
+
type: typeSchema.describe("decision | fact | error_fix | preference | note"),
|
|
65
|
+
project: projectSchema.optional(),
|
|
66
|
+
tags: tagsSchema.optional(),
|
|
67
|
+
pinned: z.boolean().optional().describe("Pinned memories are always returned by get_context"),
|
|
68
|
+
},
|
|
69
|
+
}, handle("remember", (a) => reindex(brief(store.remember(a)))));
|
|
70
|
+
server.registerTool("search", {
|
|
71
|
+
title: "Search memories",
|
|
72
|
+
description: "Hybrid search over active memories: keyword (exact terms, error codes, names) plus semantic (meaning), " +
|
|
73
|
+
"merged by rank. Natural-language questions work; include distinctive terms when you have them. Each result " +
|
|
74
|
+
"says whether it matched by keyword, semantic or both. When project is given, global memories are included " +
|
|
75
|
+
"unless include_global is false.",
|
|
76
|
+
inputSchema: {
|
|
77
|
+
query: z.string().min(1),
|
|
78
|
+
project: projectSchema.optional(),
|
|
79
|
+
type: typeSchema.optional(),
|
|
80
|
+
include_global: z.boolean().optional(),
|
|
81
|
+
limit: z.number().int().min(1).max(50).optional(),
|
|
82
|
+
},
|
|
83
|
+
}, handle("search", async (a) => {
|
|
84
|
+
const { semantic: status, results } = await semantic.search({ ...a, includeGlobal: a.include_global });
|
|
85
|
+
return { count: results.length, semantic: status, results: results.map(brief) };
|
|
86
|
+
}));
|
|
87
|
+
server.registerTool("get_context", {
|
|
88
|
+
title: "Get project context",
|
|
89
|
+
description: "Pinned memories plus the most recently updated ones for a project (and global ones). Call at the start of a session.",
|
|
90
|
+
inputSchema: {
|
|
91
|
+
project: projectSchema.optional(),
|
|
92
|
+
limit: z.number().int().min(1).max(100).optional().describe("Max recent (non-pinned) memories, default 20"),
|
|
93
|
+
},
|
|
94
|
+
}, handle("get_context", (a) => {
|
|
95
|
+
const { pinned, recent } = store.getContext(a.project, a.limit);
|
|
96
|
+
return { pinned: pinned.map(brief), recent: recent.map(brief) };
|
|
97
|
+
}));
|
|
98
|
+
server.registerTool("update_memory", {
|
|
99
|
+
title: "Update memory",
|
|
100
|
+
description: "Edit an active memory in place: fix wording, tags, type or pinning. If the underlying fact changed, use supersede so history is kept.",
|
|
101
|
+
inputSchema: {
|
|
102
|
+
id: z.number().int(),
|
|
103
|
+
content: z.string().min(1).optional(),
|
|
104
|
+
tags: tagsSchema.optional(),
|
|
105
|
+
type: typeSchema.optional(),
|
|
106
|
+
pinned: z.boolean().optional(),
|
|
107
|
+
},
|
|
108
|
+
}, handle("update_memory", ({ id, ...changes }) => reindex(brief(store.update(id, changes)))));
|
|
109
|
+
server.registerTool("supersede", {
|
|
110
|
+
title: "Supersede memory",
|
|
111
|
+
description: "Replace an outdated memory with a new one. The old one is marked superseded and disappears from search; " +
|
|
112
|
+
"project is inherited, and type/tags/pinned are inherited unless given.",
|
|
113
|
+
inputSchema: {
|
|
114
|
+
old_id: z.number().int(),
|
|
115
|
+
content: z.string().min(1),
|
|
116
|
+
type: typeSchema.optional(),
|
|
117
|
+
tags: tagsSchema.optional(),
|
|
118
|
+
pinned: z.boolean().optional(),
|
|
119
|
+
},
|
|
120
|
+
}, handle("supersede", ({ old_id, ...input }) => {
|
|
121
|
+
const r = store.supersede(old_id, input);
|
|
122
|
+
return reindex({ superseded: brief(r.old), new: brief(r.new) });
|
|
123
|
+
}));
|
|
124
|
+
server.registerTool("forget", {
|
|
125
|
+
title: "Forget memory",
|
|
126
|
+
description: "Soft-delete a memory by id. It no longer appears anywhere but stays in the database file.",
|
|
127
|
+
inputSchema: { id: z.number().int() },
|
|
128
|
+
}, handle("forget", ({ id }) => ({ forgotten: brief(store.forget(id)) })));
|
|
129
|
+
server.registerTool("history", {
|
|
130
|
+
title: "Memory history",
|
|
131
|
+
description: "Show how a memory evolved: the memory and every older version it superseded, newest first.",
|
|
132
|
+
inputSchema: { id: z.number().int() },
|
|
133
|
+
}, handle("history", ({ id }) => store.history(id).map(brief)));
|
|
134
|
+
server.registerTool("link", {
|
|
135
|
+
title: "Link entities",
|
|
136
|
+
description: 'Record a relation between two named entities, e.g. ("rashitantra" project) -uses-> ("postgres" technology), ' +
|
|
137
|
+
'or a memory as "memory:42". Entities are created on first use. Returns all relations of the "from" entity.',
|
|
138
|
+
inputSchema: {
|
|
139
|
+
from: z.string().min(1),
|
|
140
|
+
to: z.string().min(1),
|
|
141
|
+
label: z.string().min(1).describe('Relation verb, e.g. "uses", "decided", "depends_on", "fixed_by"'),
|
|
142
|
+
from_kind: z.string().optional(),
|
|
143
|
+
to_kind: z.string().optional(),
|
|
144
|
+
},
|
|
145
|
+
}, handle("link", (a) => {
|
|
146
|
+
const r = store.link({ name: a.from, kind: a.from_kind }, { name: a.to, kind: a.to_kind }, a.label);
|
|
147
|
+
return { created: r.created, relations: store.related(a.from) };
|
|
148
|
+
}));
|
|
149
|
+
server.registerTool("related", {
|
|
150
|
+
title: "Related entities",
|
|
151
|
+
description: "List all relations that touch an entity, in either direction.",
|
|
152
|
+
inputSchema: { name: z.string().min(1) },
|
|
153
|
+
}, handle("related", ({ name }) => store.related(name)));
|
|
154
|
+
server.registerTool("status", {
|
|
155
|
+
title: "Memory status",
|
|
156
|
+
description: "Server version, memory counts by status, and whether semantic search is ready (model, how many memories are embedded).",
|
|
157
|
+
inputSchema: {},
|
|
158
|
+
}, handle("status", () => ({
|
|
159
|
+
version: opts.version,
|
|
160
|
+
memories: Object.fromEntries(store.stats().map((s) => [s.status, s.n])),
|
|
161
|
+
semantic: semantic.info(),
|
|
162
|
+
})));
|
|
163
|
+
server.registerTool("export", {
|
|
164
|
+
title: "Export to Markdown",
|
|
165
|
+
description: "Write all active memories (optionally one project) to a Markdown file for review. Returns the file path.",
|
|
166
|
+
inputSchema: { project: projectSchema.optional() },
|
|
167
|
+
}, handle("export", ({ project }) => {
|
|
168
|
+
const { markdown, count } = store.exportMarkdown(project);
|
|
169
|
+
fs.mkdirSync(opts.exportDir, { recursive: true });
|
|
170
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
171
|
+
const file = path.join(opts.exportDir, `memories-${project ? project.replace(/[^\w.-]/g, "_") + "-" : ""}${stamp}.md`);
|
|
172
|
+
fs.writeFileSync(file, markdown, "utf8");
|
|
173
|
+
return { file, count };
|
|
174
|
+
}));
|
|
175
|
+
return server;
|
|
176
|
+
}
|
package/dist/store.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
export const MEMORY_TYPES = ["decision", "fact", "error_fix", "preference", "note"];
|
|
2
|
+
export const MAX_CONTENT_CHARS = 8000;
|
|
3
|
+
export const MAX_TAGS_CHARS = 500;
|
|
4
|
+
export class MemoryError extends Error {
|
|
5
|
+
}
|
|
6
|
+
const now = () => new Date().toISOString();
|
|
7
|
+
const toMemory = (r) => ({ ...r, pinned: r.pinned === 1 });
|
|
8
|
+
/** Normalise "a, B ,a" -> "a,b"; null when empty. */
|
|
9
|
+
export function normaliseTags(tags) {
|
|
10
|
+
if (tags == null)
|
|
11
|
+
return null;
|
|
12
|
+
const list = (Array.isArray(tags) ? tags : tags.split(","))
|
|
13
|
+
.map((t) => t.trim().toLowerCase())
|
|
14
|
+
.filter(Boolean);
|
|
15
|
+
const unique = [...new Set(list)];
|
|
16
|
+
return unique.length ? unique.join(",") : null;
|
|
17
|
+
}
|
|
18
|
+
/** Projects are compared case-insensitively; store them trimmed + lower-case. */
|
|
19
|
+
export function normaliseProject(project) {
|
|
20
|
+
const p = project?.trim().toLowerCase();
|
|
21
|
+
return p ? p : null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Turn free text into a safe FTS5 MATCH expression.
|
|
25
|
+
* Every token is wrapped in double quotes so characters such as `-`, `:`, `*`
|
|
26
|
+
* or `(` (common in error codes and file paths) are treated as text, not as
|
|
27
|
+
* FTS5 query syntax. Returns null if nothing searchable remains.
|
|
28
|
+
*/
|
|
29
|
+
export function buildFtsQuery(text, op) {
|
|
30
|
+
let tokens = text
|
|
31
|
+
.split(/\s+/)
|
|
32
|
+
.map((t) => t.replace(/"/g, "").trim())
|
|
33
|
+
.filter((t) => /[\p{L}\p{N}]/u.test(t));
|
|
34
|
+
// In OR mode a single filler word ("the", "is") would match almost every
|
|
35
|
+
// memory, so drop them — unless that leaves nothing to search for.
|
|
36
|
+
if (op === "OR") {
|
|
37
|
+
const meaningful = tokens.filter((t) => !STOPWORDS.has(t.toLowerCase()));
|
|
38
|
+
if (meaningful.length)
|
|
39
|
+
tokens = meaningful;
|
|
40
|
+
}
|
|
41
|
+
if (!tokens.length)
|
|
42
|
+
return null;
|
|
43
|
+
return tokens.map((t) => `"${t}"`).join(` ${op} `);
|
|
44
|
+
}
|
|
45
|
+
const STOPWORDS = new Set(("a an and are as at be but by can do does for from get got has have how i if in into is it its me my no not of on or " +
|
|
46
|
+
"our should so that the their them there these this to too was we were what when where which who why will with would you your")
|
|
47
|
+
.split(" "));
|
|
48
|
+
function checkContent(content) {
|
|
49
|
+
const c = content.trim();
|
|
50
|
+
if (!c)
|
|
51
|
+
throw new MemoryError("content must not be empty");
|
|
52
|
+
if (c.length > MAX_CONTENT_CHARS) {
|
|
53
|
+
throw new MemoryError(`content is ${c.length} chars; the limit is ${MAX_CONTENT_CHARS}. Split it or summarise it.`);
|
|
54
|
+
}
|
|
55
|
+
return c;
|
|
56
|
+
}
|
|
57
|
+
function checkTags(tags) {
|
|
58
|
+
if (tags && tags.length > MAX_TAGS_CHARS)
|
|
59
|
+
throw new MemoryError(`tags exceed ${MAX_TAGS_CHARS} chars`);
|
|
60
|
+
return tags;
|
|
61
|
+
}
|
|
62
|
+
export class MemoryStore {
|
|
63
|
+
db;
|
|
64
|
+
constructor(db) {
|
|
65
|
+
this.db = db;
|
|
66
|
+
}
|
|
67
|
+
get(id) {
|
|
68
|
+
const r = this.db.prepare("SELECT * FROM memories WHERE id = ?").get(id);
|
|
69
|
+
return r && toMemory(r);
|
|
70
|
+
}
|
|
71
|
+
require(id, mustBeActive = true) {
|
|
72
|
+
const m = this.get(id);
|
|
73
|
+
if (!m || m.status === "deleted")
|
|
74
|
+
throw new MemoryError(`memory ${id} not found`);
|
|
75
|
+
if (mustBeActive && m.status !== "active") {
|
|
76
|
+
throw new MemoryError(`memory ${id} is ${m.status}; act on the memory that replaced it instead`);
|
|
77
|
+
}
|
|
78
|
+
return m;
|
|
79
|
+
}
|
|
80
|
+
remember(input, supersedesId = null) {
|
|
81
|
+
const ts = now();
|
|
82
|
+
const info = this.db
|
|
83
|
+
.prepare(`INSERT INTO memories (project, type, content, tags, pinned, supersedes_id, created_at, updated_at)
|
|
84
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
85
|
+
.run(normaliseProject(input.project), input.type, checkContent(input.content), checkTags(normaliseTags(input.tags)), input.pinned ? 1 : 0, supersedesId, ts, ts);
|
|
86
|
+
return this.get(Number(info.lastInsertRowid));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Keyword search over active memories, ranked by BM25.
|
|
90
|
+
* Tries an AND of all terms first (precise); if that finds nothing, retries
|
|
91
|
+
* with OR so a partially matching query still recalls something.
|
|
92
|
+
*/
|
|
93
|
+
/**
|
|
94
|
+
* WHERE clauses (against alias `m`) and parameters for the search filters.
|
|
95
|
+
* Shared by keyword and semantic search so both honour the same scope.
|
|
96
|
+
*/
|
|
97
|
+
filterClauses(input) {
|
|
98
|
+
const project = normaliseProject(input.project);
|
|
99
|
+
const includeGlobal = input.includeGlobal ?? true;
|
|
100
|
+
const where = ["m.status = 'active'"];
|
|
101
|
+
if (project)
|
|
102
|
+
where.push(includeGlobal ? "(m.project = @project OR m.project IS NULL)" : "m.project = @project");
|
|
103
|
+
if (input.type)
|
|
104
|
+
where.push("m.type = @type");
|
|
105
|
+
return { where, params: { project, type: input.type ?? null } };
|
|
106
|
+
}
|
|
107
|
+
search(input) {
|
|
108
|
+
const limit = Math.min(Math.max(input.limit ?? 10, 1), 50);
|
|
109
|
+
const { where: filters, params } = this.filterClauses(input);
|
|
110
|
+
const project = params.project;
|
|
111
|
+
const where = [...filters, "memories_fts MATCH @q"];
|
|
112
|
+
// bm25() is lower-is-better; weight content 1.0 and tags 0.5. A small boost
|
|
113
|
+
// for the requested project so its rows beat equally relevant global ones.
|
|
114
|
+
const sql = `
|
|
115
|
+
SELECT m.*, -bm25(memories_fts, 1.0, 0.5) + (CASE WHEN m.project = @project THEN 0.5 ELSE 0 END) AS score
|
|
116
|
+
FROM memories_fts JOIN memories m ON m.id = memories_fts.rowid
|
|
117
|
+
WHERE ${where.join(" AND ")}
|
|
118
|
+
ORDER BY score DESC, m.updated_at DESC
|
|
119
|
+
LIMIT @limit`;
|
|
120
|
+
const stmt = this.db.prepare(sql);
|
|
121
|
+
for (const op of ["AND", "OR"]) {
|
|
122
|
+
const q = buildFtsQuery(input.query, op);
|
|
123
|
+
if (!q)
|
|
124
|
+
return [];
|
|
125
|
+
const rows = stmt.all({ q, project, type: input.type ?? null, limit });
|
|
126
|
+
if (rows.length || op === "OR") {
|
|
127
|
+
return rows.map((r) => ({ ...toMemory(r), score: Math.round(r.score * 1000) / 1000 }));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return [];
|
|
131
|
+
}
|
|
132
|
+
/** Pinned memories first, then the most recently touched, for session start. */
|
|
133
|
+
getContext(project, limit = 20) {
|
|
134
|
+
const p = normaliseProject(project);
|
|
135
|
+
const scope = p ? "(project = @p OR project IS NULL)" : "project IS NULL";
|
|
136
|
+
const pinned = this.db
|
|
137
|
+
.prepare(`SELECT * FROM memories WHERE status = 'active' AND pinned = 1 AND ${scope} ORDER BY updated_at DESC`)
|
|
138
|
+
.all({ p });
|
|
139
|
+
const recent = this.db
|
|
140
|
+
.prepare(`SELECT * FROM memories WHERE status = 'active' AND pinned = 0 AND ${scope}
|
|
141
|
+
ORDER BY (project IS NULL) ASC, updated_at DESC LIMIT @limit`)
|
|
142
|
+
.all({ p, limit: Math.min(Math.max(limit, 1), 100) });
|
|
143
|
+
return { pinned: pinned.map(toMemory), recent: recent.map(toMemory) };
|
|
144
|
+
}
|
|
145
|
+
update(id, changes) {
|
|
146
|
+
const m = this.require(id);
|
|
147
|
+
const content = changes.content !== undefined ? checkContent(changes.content) : m.content;
|
|
148
|
+
const tags = changes.tags !== undefined ? checkTags(normaliseTags(changes.tags)) : m.tags;
|
|
149
|
+
const pinned = changes.pinned !== undefined ? (changes.pinned ? 1 : 0) : m.pinned ? 1 : 0;
|
|
150
|
+
const type = changes.type ?? m.type;
|
|
151
|
+
this.db
|
|
152
|
+
.prepare("UPDATE memories SET content = ?, tags = ?, pinned = ?, type = ?, updated_at = ? WHERE id = ?")
|
|
153
|
+
.run(content, tags, pinned, type, now(), id);
|
|
154
|
+
return this.get(id);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Replace an active memory with a new one in a single transaction. Fields
|
|
158
|
+
* not given (project, type, tags, pinned) are inherited from the old row.
|
|
159
|
+
*/
|
|
160
|
+
supersede(oldId, input) {
|
|
161
|
+
return this.db.transaction(() => {
|
|
162
|
+
const old = this.require(oldId);
|
|
163
|
+
const created = this.remember({
|
|
164
|
+
project: old.project,
|
|
165
|
+
type: input.type ?? old.type,
|
|
166
|
+
content: input.content,
|
|
167
|
+
tags: input.tags !== undefined ? input.tags : old.tags,
|
|
168
|
+
pinned: input.pinned ?? old.pinned,
|
|
169
|
+
}, oldId);
|
|
170
|
+
this.db
|
|
171
|
+
.prepare("UPDATE memories SET status = 'superseded', pinned = 0, updated_at = ? WHERE id = ?")
|
|
172
|
+
.run(now(), oldId);
|
|
173
|
+
return { old: this.get(oldId), new: created };
|
|
174
|
+
})();
|
|
175
|
+
}
|
|
176
|
+
/** Soft delete: the row stays for audit but never appears in search again. */
|
|
177
|
+
forget(id) {
|
|
178
|
+
this.require(id, false);
|
|
179
|
+
this.db.prepare("UPDATE memories SET status = 'deleted', pinned = 0, updated_at = ? WHERE id = ?").run(now(), id);
|
|
180
|
+
return this.get(id);
|
|
181
|
+
}
|
|
182
|
+
/** Walk supersedes_id back from a memory to show how a fact evolved. */
|
|
183
|
+
history(id) {
|
|
184
|
+
const chain = [];
|
|
185
|
+
let cur = this.get(id);
|
|
186
|
+
while (cur && chain.length < 100) {
|
|
187
|
+
chain.push(cur);
|
|
188
|
+
cur = cur.supersedes_id ? this.get(cur.supersedes_id) : undefined;
|
|
189
|
+
}
|
|
190
|
+
return chain;
|
|
191
|
+
}
|
|
192
|
+
link(from, to, label) {
|
|
193
|
+
const upsert = this.db.prepare(`INSERT INTO entities (name, kind) VALUES (@name, @kind)
|
|
194
|
+
ON CONFLICT(name) DO UPDATE SET kind = COALESCE(excluded.kind, entities.kind)
|
|
195
|
+
RETURNING id, name, kind`);
|
|
196
|
+
return this.db.transaction(() => {
|
|
197
|
+
const f = upsert.get({ name: from.name.trim(), kind: from.kind ?? null });
|
|
198
|
+
const t = upsert.get({ name: to.name.trim(), kind: to.kind ?? null });
|
|
199
|
+
const info = this.db
|
|
200
|
+
.prepare("INSERT OR IGNORE INTO relations (from_id, to_id, label, created_at) VALUES (?, ?, ?, ?)")
|
|
201
|
+
.run(f.id, t.id, label.trim(), now());
|
|
202
|
+
return { from: f, to: t, label: label.trim(), created: info.changes > 0 };
|
|
203
|
+
})();
|
|
204
|
+
}
|
|
205
|
+
/** Relations touching an entity, in either direction. */
|
|
206
|
+
related(name) {
|
|
207
|
+
return this.db
|
|
208
|
+
.prepare(`SELECT ef.name AS "from", r.label AS label, et.name AS "to"
|
|
209
|
+
FROM relations r JOIN entities ef ON ef.id = r.from_id JOIN entities et ON et.id = r.to_id
|
|
210
|
+
WHERE ef.name = @n OR et.name = @n ORDER BY r.created_at`)
|
|
211
|
+
.all({ n: name.trim() });
|
|
212
|
+
}
|
|
213
|
+
listActive(project) {
|
|
214
|
+
const p = normaliseProject(project);
|
|
215
|
+
const rows = (p
|
|
216
|
+
? this.db.prepare("SELECT * FROM memories WHERE status = 'active' AND project = ? ORDER BY project, type, updated_at DESC").all(p)
|
|
217
|
+
: this.db.prepare("SELECT * FROM memories WHERE status = 'active' ORDER BY project IS NOT NULL, project, type, updated_at DESC").all());
|
|
218
|
+
return rows.map(toMemory);
|
|
219
|
+
}
|
|
220
|
+
/** Render active memories as Markdown grouped by project, then type. */
|
|
221
|
+
exportMarkdown(project) {
|
|
222
|
+
const rows = this.listActive(project);
|
|
223
|
+
const lines = [`# Memory export`, ``, `Generated ${now()} · ${rows.length} active memories`, ``];
|
|
224
|
+
let lastProject;
|
|
225
|
+
let lastType;
|
|
226
|
+
for (const m of rows) {
|
|
227
|
+
if (m.project !== lastProject) {
|
|
228
|
+
lines.push(`## ${m.project ?? "Global"}`, ``);
|
|
229
|
+
lastProject = m.project;
|
|
230
|
+
lastType = undefined;
|
|
231
|
+
}
|
|
232
|
+
if (m.type !== lastType) {
|
|
233
|
+
lines.push(`### ${m.type}`, ``);
|
|
234
|
+
lastType = m.type;
|
|
235
|
+
}
|
|
236
|
+
const meta = [`#${m.id}`, m.pinned ? "📌" : "", m.tags ? `tags: ${m.tags}` : "", m.updated_at.slice(0, 10)]
|
|
237
|
+
.filter(Boolean)
|
|
238
|
+
.join(" · ");
|
|
239
|
+
const body = m.content.replace(/\n/g, "\n ");
|
|
240
|
+
lines.push(`- ${body}`, ` <sub>${meta}</sub>`);
|
|
241
|
+
}
|
|
242
|
+
lines.push(``);
|
|
243
|
+
return { markdown: lines.join("\n"), count: rows.length };
|
|
244
|
+
}
|
|
245
|
+
stats() {
|
|
246
|
+
return this.db
|
|
247
|
+
.prepare("SELECT status, COUNT(*) AS n FROM memories GROUP BY status")
|
|
248
|
+
.all();
|
|
249
|
+
}
|
|
250
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "forget-me-not-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Local memory MCP server for Claude Code: decisions, fixes and project facts that persist across sessions, stored in SQLite with hybrid keyword + semantic search.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"mcp",
|
|
7
|
+
"model-context-protocol",
|
|
8
|
+
"claude",
|
|
9
|
+
"claude-code",
|
|
10
|
+
"memory",
|
|
11
|
+
"sqlite",
|
|
12
|
+
"fts5",
|
|
13
|
+
"ai-agent",
|
|
14
|
+
"embeddings",
|
|
15
|
+
"semantic-search",
|
|
16
|
+
"nomic-embed-text"
|
|
17
|
+
],
|
|
18
|
+
"author": "Ranga Surendra",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"bin": {
|
|
22
|
+
"forget-me-not-mcp": "dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"clean": "node -e \"fs.rmSync('dist',{recursive:true,force:true})\"",
|
|
31
|
+
"build": "npm run clean && tsc",
|
|
32
|
+
"test": "vitest run",
|
|
33
|
+
"dev": "tsc --watch",
|
|
34
|
+
"start": "node dist/index.js",
|
|
35
|
+
"prepublishOnly": "npm run build && npm test"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=22"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
42
|
+
"better-sqlite3": "^13.2.0",
|
|
43
|
+
"zod": "^4.6.7"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/better-sqlite3": "^9.6.0",
|
|
47
|
+
"@types/node": "^26.6.6",
|
|
48
|
+
"typescript": "^7.0.2",
|
|
49
|
+
"vitest": "^5.1.0"
|
|
50
|
+
},
|
|
51
|
+
"optionalDependencies": {
|
|
52
|
+
"@huggingface/transformers": "^4.3.2"
|
|
53
|
+
}
|
|
54
|
+
}
|