fossel 1.0.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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +74 -0
  3. package/dist/index.js +388 -0
  4. package/package.json +31 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 vignesh Gopikrishnan
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 ADDED
@@ -0,0 +1,74 @@
1
+ # Fossyl
2
+
3
+ Fossyl is a local MCP (Model Context Protocol) memory server for open-source contributors. It stores project-specific context such as reviewer preferences, bug fixes, conventions, decisions, and issue notes in a local SQLite database with FTS5 search.
4
+
5
+ ## Features
6
+
7
+ - Persistent local memory in SQLite (`~/.fossyl/memory.db`)
8
+ - Full-text search with SQLite FTS5
9
+ - Repo-aware context retrieval grouped by memory type
10
+ - Simple delete workflow by memory id
11
+ - Local `stdio` MCP server for tools such as Cursor and Claude Desktop
12
+
13
+ ## Memory Types
14
+
15
+ - `convention`
16
+ - `bug_fix`
17
+ - `reviewer_pattern`
18
+ - `decision`
19
+ - `issue`
20
+ - `general`
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ npm install
26
+ ```
27
+
28
+ ## Development
29
+
30
+ ```bash
31
+ npm run dev
32
+ ```
33
+
34
+ This starts the local MCP server over stdio.
35
+
36
+ ## Build
37
+
38
+ ```bash
39
+ npm run build
40
+ ```
41
+
42
+ ## Run Built Server
43
+
44
+ ```bash
45
+ npm run start
46
+ ```
47
+
48
+ ## MCP Tools
49
+
50
+ - `store_context`: Save a new memory for a repository.
51
+ - `get_repo_context`: Fetch recent memories for a repository, grouped by type.
52
+ - `search_memory`: Full-text search memories across all repos or a single repo.
53
+ - `delete_memory`: Delete a memory by id.
54
+
55
+ ## Cursor MCP Config
56
+
57
+ Add this to your Cursor MCP configuration:
58
+
59
+ ```json
60
+ {
61
+ "mcpServers": {
62
+ "fossel": {
63
+ "command": "npx",
64
+ "args": ["-y", "fossel"]
65
+ }
66
+ }
67
+ }
68
+ ```
69
+
70
+ ## Notes
71
+
72
+ - Fossyl is local-first: data remains on your machine.
73
+ - FTS5 is used for V1 search (no `sqlite-vec`).
74
+ - Optional: set `FOSSYL_DB_PATH` to override the default database path for testing.
package/dist/index.js ADDED
@@ -0,0 +1,388 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { homedir } from "os";
5
+ import { join } from "path";
6
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
7
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
8
+
9
+ // src/db/client.ts
10
+ import Database from "better-sqlite3";
11
+ import { mkdirSync } from "fs";
12
+ import { dirname } from "path";
13
+ var MEMORY_TYPES = [
14
+ "convention",
15
+ "bug_fix",
16
+ "reviewer_pattern",
17
+ "decision",
18
+ "issue",
19
+ "general"
20
+ ];
21
+ var dbInstance = null;
22
+ var SCHEMA_SQL = `
23
+ CREATE TABLE IF NOT EXISTS memories (
24
+ id TEXT PRIMARY KEY,
25
+ repo TEXT NOT NULL,
26
+ type TEXT NOT NULL CHECK (type IN ('convention', 'bug_fix', 'reviewer_pattern', 'decision', 'issue', 'general')),
27
+ note TEXT NOT NULL,
28
+ tags TEXT NOT NULL DEFAULT '[]',
29
+ created_at INTEGER NOT NULL,
30
+ updated_at INTEGER NOT NULL
31
+ );
32
+
33
+ CREATE INDEX IF NOT EXISTS idx_memories_repo ON memories (repo);
34
+ CREATE INDEX IF NOT EXISTS idx_memories_created_at ON memories (created_at DESC);
35
+
36
+ CREATE VIRTUAL TABLE IF NOT EXISTS memories_fts USING fts5(
37
+ repo,
38
+ note,
39
+ content = 'memories',
40
+ content_rowid = 'rowid'
41
+ );
42
+
43
+ CREATE TRIGGER IF NOT EXISTS memories_ai AFTER INSERT ON memories BEGIN
44
+ INSERT INTO memories_fts(rowid, repo, note) VALUES (new.rowid, new.repo, new.note);
45
+ END;
46
+
47
+ CREATE TRIGGER IF NOT EXISTS memories_ad AFTER DELETE ON memories BEGIN
48
+ INSERT INTO memories_fts(memories_fts, rowid, repo, note) VALUES ('delete', old.rowid, old.repo, old.note);
49
+ END;
50
+
51
+ CREATE TRIGGER IF NOT EXISTS memories_au AFTER UPDATE ON memories BEGIN
52
+ INSERT INTO memories_fts(memories_fts, rowid, repo, note) VALUES ('delete', old.rowid, old.repo, old.note);
53
+ INSERT INTO memories_fts(rowid, repo, note) VALUES (new.rowid, new.repo, new.note);
54
+ END;
55
+ `;
56
+ function initDb(dbPath) {
57
+ if (dbInstance) {
58
+ return dbInstance;
59
+ }
60
+ mkdirSync(dirname(dbPath), { recursive: true });
61
+ const db = new Database(dbPath);
62
+ db.pragma("journal_mode = WAL");
63
+ db.pragma("foreign_keys = ON");
64
+ db.exec(SCHEMA_SQL);
65
+ dbInstance = db;
66
+ return db;
67
+ }
68
+ function getDb() {
69
+ if (!dbInstance) {
70
+ throw new Error("Database has not been initialized. Call initDb() first.");
71
+ }
72
+ return dbInstance;
73
+ }
74
+
75
+ // src/tools/delete.ts
76
+ import { z } from "zod";
77
+ var deleteMemoryInputSchema = {
78
+ id: z.string().trim().min(1, "id is required")
79
+ };
80
+ function registerDeleteMemoryTool(server) {
81
+ server.registerTool(
82
+ "delete_memory",
83
+ {
84
+ description: "Delete a memory from storage by id.",
85
+ inputSchema: deleteMemoryInputSchema
86
+ },
87
+ async ({ id }) => {
88
+ try {
89
+ const db = getDb();
90
+ const row = db.prepare("SELECT id FROM memories WHERE id = ?").get(id);
91
+ if (!row) {
92
+ return {
93
+ isError: true,
94
+ content: [
95
+ {
96
+ type: "text",
97
+ text: `Memory ${id} not found.`
98
+ }
99
+ ]
100
+ };
101
+ }
102
+ const deleteTx = db.transaction((memoryId) => {
103
+ db.prepare("DELETE FROM memories WHERE id = ?").run(memoryId);
104
+ });
105
+ deleteTx(id);
106
+ return {
107
+ content: [
108
+ {
109
+ type: "text",
110
+ text: `Deleted memory ${id}.`
111
+ }
112
+ ]
113
+ };
114
+ } catch (error) {
115
+ const message = error instanceof Error ? error.message : "Unknown error while deleting memory.";
116
+ return {
117
+ isError: true,
118
+ content: [
119
+ {
120
+ type: "text",
121
+ text: `Failed to delete memory: ${message}`
122
+ }
123
+ ]
124
+ };
125
+ }
126
+ }
127
+ );
128
+ }
129
+
130
+ // src/tools/get-repo.ts
131
+ import { z as z2 } from "zod";
132
+ var getRepoContextInputSchema = {
133
+ repo: z2.string().trim().min(1, "repo is required"),
134
+ limit: z2.number().int().positive().max(100).default(10)
135
+ };
136
+ function parseTags(raw) {
137
+ try {
138
+ const parsed = JSON.parse(raw);
139
+ return Array.isArray(parsed) ? parsed.filter((value) => typeof value === "string") : [];
140
+ } catch {
141
+ return [];
142
+ }
143
+ }
144
+ function formatTypeHeading(type) {
145
+ return type.split("_").map((part) => part[0]?.toUpperCase() + part.slice(1)).join(" ");
146
+ }
147
+ function registerGetRepoContextTool(server) {
148
+ server.registerTool(
149
+ "get_repo_context",
150
+ {
151
+ description: "Get recent memories for a repository grouped by memory type.",
152
+ inputSchema: getRepoContextInputSchema
153
+ },
154
+ async ({ repo, limit }) => {
155
+ try {
156
+ const db = getDb();
157
+ const rows = db.prepare(
158
+ `
159
+ SELECT id, repo, type, note, tags, created_at, updated_at
160
+ FROM memories
161
+ WHERE repo = ?
162
+ ORDER BY updated_at DESC
163
+ LIMIT ?
164
+ `
165
+ ).all(repo, limit);
166
+ if (rows.length === 0) {
167
+ return {
168
+ content: [
169
+ {
170
+ type: "text",
171
+ text: `No memories found for ${repo}.`
172
+ }
173
+ ]
174
+ };
175
+ }
176
+ const grouped = /* @__PURE__ */ new Map();
177
+ for (const memory of rows) {
178
+ const tags = parseTags(memory.tags);
179
+ const tagSuffix = tags.length > 0 ? ` [tags: ${tags.join(", ")}]` : "";
180
+ const item = `- (${memory.id}) ${memory.note}${tagSuffix}`;
181
+ const existing = grouped.get(memory.type) ?? [];
182
+ existing.push(item);
183
+ grouped.set(memory.type, existing);
184
+ }
185
+ const sections = [];
186
+ for (const type of MEMORY_TYPES) {
187
+ const entries = grouped.get(type);
188
+ if (!entries || entries.length === 0) {
189
+ continue;
190
+ }
191
+ sections.push(`${formatTypeHeading(type)}
192
+ ${entries.join("\n")}`);
193
+ }
194
+ return {
195
+ content: [
196
+ {
197
+ type: "text",
198
+ text: `Repository context for ${repo}
199
+ Total memories: ${rows.length}
200
+
201
+ ${sections.join("\n\n")}`
202
+ }
203
+ ]
204
+ };
205
+ } catch (error) {
206
+ const message = error instanceof Error ? error.message : "Unknown error while retrieving repository context.";
207
+ return {
208
+ isError: true,
209
+ content: [
210
+ {
211
+ type: "text",
212
+ text: `Failed to fetch repository context: ${message}`
213
+ }
214
+ ]
215
+ };
216
+ }
217
+ }
218
+ );
219
+ }
220
+
221
+ // src/tools/search.ts
222
+ import { z as z3 } from "zod";
223
+ var searchMemoryInputSchema = {
224
+ query: z3.string().trim().min(1, "query is required"),
225
+ repo: z3.string().trim().min(1).optional(),
226
+ limit: z3.number().int().positive().max(50).default(5)
227
+ };
228
+ function normalizeFtsQuery(query) {
229
+ const terms = query.trim().split(/\s+/).map((term) => term.replaceAll('"', '""')).filter(Boolean);
230
+ if (terms.length === 0) {
231
+ throw new Error("query must contain searchable text");
232
+ }
233
+ return terms.map((term) => `"${term}"`).join(" AND ");
234
+ }
235
+ function parseTags2(raw) {
236
+ try {
237
+ const parsed = JSON.parse(raw);
238
+ return Array.isArray(parsed) ? parsed.filter((value) => typeof value === "string") : [];
239
+ } catch {
240
+ return [];
241
+ }
242
+ }
243
+ function registerSearchMemoryTool(server) {
244
+ server.registerTool(
245
+ "search_memory",
246
+ {
247
+ description: "Search memories using full-text search with optional repository filtering.",
248
+ inputSchema: searchMemoryInputSchema
249
+ },
250
+ async ({ query, repo, limit }) => {
251
+ try {
252
+ const db = getDb();
253
+ const ftsQuery = normalizeFtsQuery(query);
254
+ const rows = repo ? db.prepare(
255
+ `
256
+ SELECT m.id, m.repo, m.type, m.note, m.tags, m.created_at, m.updated_at, bm25(memories_fts) AS rank
257
+ FROM memories_fts
258
+ JOIN memories AS m ON m.rowid = memories_fts.rowid
259
+ WHERE memories_fts MATCH ? AND m.repo = ?
260
+ ORDER BY rank
261
+ LIMIT ?
262
+ `
263
+ ).all(ftsQuery, repo, limit) : db.prepare(
264
+ `
265
+ SELECT m.id, m.repo, m.type, m.note, m.tags, m.created_at, m.updated_at, bm25(memories_fts) AS rank
266
+ FROM memories_fts
267
+ JOIN memories AS m ON m.rowid = memories_fts.rowid
268
+ WHERE memories_fts MATCH ?
269
+ ORDER BY rank
270
+ LIMIT ?
271
+ `
272
+ ).all(ftsQuery, limit);
273
+ if (rows.length === 0) {
274
+ return {
275
+ content: [
276
+ {
277
+ type: "text",
278
+ text: repo ? `No memories matched "${query}" in ${repo}.` : `No memories matched "${query}".`
279
+ }
280
+ ]
281
+ };
282
+ }
283
+ const formatted = rows.map((row, index) => {
284
+ const tags = parseTags2(row.tags);
285
+ const tagsText = tags.length > 0 ? ` | tags: ${tags.join(", ")}` : "";
286
+ return `${index + 1}. [${row.repo}] ${row.type} (${row.id})
287
+ ${row.note}${tagsText}`;
288
+ }).join("\n\n");
289
+ return {
290
+ content: [
291
+ {
292
+ type: "text",
293
+ text: `Search results for "${query}"${repo ? ` in ${repo}` : ""}:
294
+
295
+ ${formatted}`
296
+ }
297
+ ]
298
+ };
299
+ } catch (error) {
300
+ const message = error instanceof Error ? error.message : "Unknown error while searching memory.";
301
+ return {
302
+ isError: true,
303
+ content: [
304
+ {
305
+ type: "text",
306
+ text: `Failed to search memories: ${message}`
307
+ }
308
+ ]
309
+ };
310
+ }
311
+ }
312
+ );
313
+ }
314
+
315
+ // src/tools/store.ts
316
+ import { nanoid } from "nanoid";
317
+ import { z as z4 } from "zod";
318
+ var storeContextInputSchema = {
319
+ repo: z4.string().trim().min(1, "repo is required"),
320
+ type: z4.enum(MEMORY_TYPES),
321
+ note: z4.string().trim().min(1, "note is required"),
322
+ tags: z4.array(z4.string().trim().min(1)).optional()
323
+ };
324
+ function registerStoreContextTool(server) {
325
+ server.registerTool(
326
+ "store_context",
327
+ {
328
+ description: "Store repository-specific contributor context such as bug fixes, conventions, and decisions.",
329
+ inputSchema: storeContextInputSchema
330
+ },
331
+ async ({ repo, type, note, tags }) => {
332
+ try {
333
+ const db = getDb();
334
+ const now = Math.floor(Date.now() / 1e3);
335
+ const id = nanoid();
336
+ const normalizedTags = Array.from(
337
+ new Set((tags ?? []).map((tag) => tag.trim()).filter(Boolean))
338
+ );
339
+ db.prepare(
340
+ `
341
+ INSERT INTO memories (id, repo, type, note, tags, created_at, updated_at)
342
+ VALUES (?, ?, ?, ?, ?, ?, ?)
343
+ `
344
+ ).run(id, repo, type, note, JSON.stringify(normalizedTags), now, now);
345
+ return {
346
+ content: [
347
+ {
348
+ type: "text",
349
+ text: `Stored memory ${id} for ${repo} (${type}).`
350
+ }
351
+ ]
352
+ };
353
+ } catch (error) {
354
+ const message = error instanceof Error ? error.message : "Unknown error while storing memory.";
355
+ return {
356
+ isError: true,
357
+ content: [
358
+ {
359
+ type: "text",
360
+ text: `Failed to store memory: ${message}`
361
+ }
362
+ ]
363
+ };
364
+ }
365
+ }
366
+ );
367
+ }
368
+
369
+ // src/index.ts
370
+ async function main() {
371
+ const dbPath = process.env.FOSSYL_DB_PATH?.trim() || join(homedir(), ".fossyl", "memory.db");
372
+ initDb(dbPath);
373
+ const server = new McpServer({
374
+ name: "fossel",
375
+ version: "1.0.0"
376
+ });
377
+ registerStoreContextTool(server);
378
+ registerGetRepoContextTool(server);
379
+ registerSearchMemoryTool(server);
380
+ registerDeleteMemoryTool(server);
381
+ const transport = new StdioServerTransport();
382
+ await server.connect(transport);
383
+ }
384
+ main().catch((error) => {
385
+ const message = error instanceof Error ? error.message : String(error);
386
+ console.error(`Fossyl server failed to start: ${message}`);
387
+ process.exit(1);
388
+ });
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "fossel",
3
+ "version": "1.0.0",
4
+ "description": "Local MCP memory server for open-source contributors",
5
+ "type": "module",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "bin": {
10
+ "fossel": "dist/index.js"
11
+ },
12
+ "scripts": {
13
+ "build": "tsup",
14
+ "dev": "tsx src/index.ts",
15
+ "start": "node dist/index.js",
16
+ "smoke": "tsx scripts/smoke.ts"
17
+ },
18
+ "dependencies": {
19
+ "@modelcontextprotocol/sdk": "latest",
20
+ "better-sqlite3": "latest",
21
+ "nanoid": "latest",
22
+ "zod": "latest"
23
+ },
24
+ "devDependencies": {
25
+ "@types/better-sqlite3": "latest",
26
+ "@types/node": "latest",
27
+ "tsup": "latest",
28
+ "tsx": "latest",
29
+ "typescript": "latest"
30
+ }
31
+ }