@postnesia/mcp 0.1.6 → 0.1.8

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 (2) hide show
  1. package/dist/index.js +57 -5
  2. package/package.json +9 -9
package/dist/index.js CHANGED
@@ -6,7 +6,8 @@
6
6
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
7
7
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
8
8
  import { z } from "zod";
9
- import { getDb, queries, createMemory } from "@postnesia/db";
9
+ import { getDb, closeDb, createMemory } from "@postnesia/db";
10
+ import queries from "@postnesia/db/queries";
10
11
  import { embed } from "@postnesia/db/embeddings";
11
12
  import { logAccess } from "@postnesia/db/access";
12
13
  import { runConsolidation } from "@postnesia/db/importance";
@@ -25,7 +26,10 @@ server.registerTool("memory_search", {
25
26
  limit: z.number().optional().describe("Maximum results to return (default: 10)"),
26
27
  },
27
28
  }, async ({ query, limit = 10 }) => {
28
- const embedding = await embed(query);
29
+ const [embedding] = await embed(query);
30
+ if (!embedding) {
31
+ throw new ReferenceError('Unable to create query embedding');
32
+ }
29
33
  const results = queries.vectorSearch(db).all(Buffer.from(embedding.buffer), limit);
30
34
  for (const result of results) {
31
35
  logAccess(result.id, "search");
@@ -47,7 +51,10 @@ server.registerTool("memory_add", {
47
51
  },
48
52
  }, async ({ content, contentL1, type, importance, tags, context, core }) => {
49
53
  const content_l1 = contentL1 || content.slice(0, 200);
50
- const embedding = await embed(content);
54
+ const [embedding] = await embed(content);
55
+ if (!embedding) {
56
+ throw new ReferenceError('Unable to create query embedding');
57
+ }
51
58
  const id = createMemory(db, {
52
59
  timestamp: new Date().toISOString(),
53
60
  content,
@@ -81,7 +88,10 @@ server.registerTool("memory_update_core", {
81
88
  throw new Error(`Memory #${memoryId} not found`);
82
89
  if (!existing.core)
83
90
  throw new Error(`Memory #${memoryId} is not a core memory. Use memory_add with supersedes_id for regular memories.`);
84
- const embedding = await embed(content);
91
+ const [embedding] = await embed(content);
92
+ if (!embedding) {
93
+ throw new ReferenceError('Unable to create query embedding');
94
+ }
85
95
  db.prepare(`
86
96
  UPDATE memory
87
97
  SET content = ?, content_l1 = ?, updated_at = datetime('now')
@@ -154,6 +164,45 @@ server.registerTool("memory_relationships", {
154
164
  content: [{ type: "text", text: JSON.stringify(relationships, null, 2) }],
155
165
  };
156
166
  });
167
+ server.registerTool("memory_link", {
168
+ description: "Explicitly create a typed relationship between two memories",
169
+ inputSchema: {
170
+ fromId: z.number().describe("Source memory ID"),
171
+ toId: z.number().describe("Target memory ID"),
172
+ type: z.enum(["related", "supersedes", "supports", "contradicts", "derives_from"])
173
+ .describe("Relationship type"),
174
+ },
175
+ }, async ({ fromId, toId, type }) => {
176
+ const from = db.prepare("SELECT id FROM memory WHERE id = ?").get(fromId);
177
+ if (!from)
178
+ throw new Error(`Memory #${fromId} not found`);
179
+ const to = db.prepare("SELECT id FROM memory WHERE id = ?").get(toId);
180
+ if (!to)
181
+ throw new Error(`Memory #${toId} not found`);
182
+ const existing = queries.findRelationshipBetween(db).get(fromId, toId, type);
183
+ if (existing) {
184
+ return { content: [{ type: "text", text: `Relationship already exists (id: ${existing.id})` }] };
185
+ }
186
+ const result = queries.insertRelationship(db).run(fromId, toId, type);
187
+ const id = Number(result.lastInsertRowid);
188
+ return {
189
+ content: [{ type: "text", text: `Created relationship #${id}: #${fromId} -[${type}]-> #${toId}` }],
190
+ };
191
+ });
192
+ server.registerTool("memory_unlink", {
193
+ description: "Remove a relationship between two memories by relationship ID",
194
+ inputSchema: {
195
+ relationshipId: z.number().describe("Relationship ID to delete"),
196
+ },
197
+ }, async ({ relationshipId }) => {
198
+ const existing = db.prepare("SELECT id FROM relationship WHERE id = ?").get(relationshipId);
199
+ if (!existing)
200
+ throw new Error(`Relationship #${relationshipId} not found`);
201
+ queries.deleteRelationship(db).run(relationshipId);
202
+ return {
203
+ content: [{ type: "text", text: `Deleted relationship #${relationshipId}` }],
204
+ };
205
+ });
157
206
  // ---------------------------------------------------------------------------
158
207
  // journal tools
159
208
  // ---------------------------------------------------------------------------
@@ -193,7 +242,7 @@ server.registerTool("task_create", {
193
242
  inputSchema: {
194
243
  title: z.string().describe("Short task title"),
195
244
  description: z.string().optional().describe("Detailed description of what needs to be done"),
196
- session_id: z.string().optional().describe("Project or feature label to group related tasks (e.g. 'openmind-mcp', 'auth-refactor')"),
245
+ session_id: z.string().optional().describe("Project or feature label to group related tasks (e.g. 'postnesia-mcp', 'auth-refactor')"),
197
246
  memory_id: z.number().optional().describe("Optional ID of a related memory"),
198
247
  },
199
248
  }, async ({ title, description, session_id, memory_id }) => {
@@ -271,5 +320,8 @@ async function main() {
271
320
  }
272
321
  main().catch((error) => {
273
322
  console.error("Fatal error:", error);
323
+ closeDb();
274
324
  process.exit(1);
275
325
  });
326
+ process.on('SIGINT', () => { closeDb(); process.exit(0); });
327
+ process.on('SIGTERM', () => { closeDb(); process.exit(0); });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postnesia/mcp",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "An MCP server to interact with the Postnesia database",
5
5
  "type": "module",
6
6
  "private": false,
@@ -8,21 +8,21 @@
8
8
  "dist"
9
9
  ],
10
10
  "bin": {
11
- "postnesia-mcp": "./dist/index.js"
11
+ "pn-mcp": "./dist/index.js"
12
+ },
13
+ "scripts": {
14
+ "build": "pnpm clean && tsc -p tsconfig.json",
15
+ "clean": "rm -rf ./dist",
16
+ "start": "tsx src/index.ts"
12
17
  },
13
18
  "dependencies": {
14
19
  "@modelcontextprotocol/sdk": "^1.26.0",
15
- "@postnesia/db": "^0.1.5",
20
+ "@postnesia/db": "workspace:*",
16
21
  "zod": "^4.3.6"
17
22
  },
18
23
  "devDependencies": {
19
24
  "@types/node": "^22.10.5",
20
25
  "tsx": "^4.19.2",
21
26
  "typescript": "^5.7.3"
22
- },
23
- "scripts": {
24
- "build": "pnpm clean && tsc -p tsconfig.json",
25
- "clean": "rm -rf ./dist",
26
- "start": "tsx src/index.ts"
27
27
  }
28
- }
28
+ }