Skip to content

Commit 02a52f7

Browse files
committed
feat: fixed mcp
1 parent 0e63960 commit 02a52f7

9 files changed

Lines changed: 874 additions & 21 deletions

File tree

packages/openmemory-js/bin/opm.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,13 @@ for (let i = 1; i < argv.length; i++) {
243243
case 'mcp':
244244
// Start MCP server (requires build)
245245
try {
246-
require('../dist/ai/mcp.js');
246+
const mcp = require('../dist/ai/mcp.js');
247+
if (mcp && mcp.start_mcp_stdio) {
248+
await mcp.start_mcp_stdio();
249+
} else {
250+
console.error('[error] mcp module missing start_mcp_stdio export');
251+
process.exit(1);
252+
}
247253
} catch (e) {
248254
console.error('[error] failed to start mcp server. ensure project is built (npm run build).');
249255
console.error(e.message);

packages/openmemory-js/package-lock.json

Lines changed: 841 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openmemory-js/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openmemory-js",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"author": "nullure",
55
"bin": {
66
"opm": "./bin/opm.js",
@@ -36,6 +36,7 @@
3636
"zod": "^3.25.76"
3737
},
3838
"devDependencies": {
39+
"@types/cheerio": "^0.22.35",
3940
"@types/fluent-ffmpeg": "^2.1.26",
4041
"@types/node": "^20.19.25",
4142
"@types/pg": "^8.15.6",

packages/openmemory-js/src/ai/mcp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ export const mcp = (app: any) => {
421421
const srv_ready = srv
422422
.connect(trans)
423423
.then(() => {
424-
console.log("[MCP] Server started and transport connected");
424+
console.error("[MCP] Server started and transport connected");
425425
})
426426
.catch((error) => {
427427
console.error("[MCP] Failed to initialize transport:", error);
@@ -436,7 +436,7 @@ export const mcp = (app: any) => {
436436
send_err(res, -32600, "Request body must be a JSON object");
437437
return;
438438
}
439-
console.log("[MCP] Incoming request:", JSON.stringify(pay));
439+
console.error("[MCP] Incoming request:", JSON.stringify(pay));
440440
set_hdrs(res);
441441
await trans.handleRequest(req, res, pay);
442442
} catch (error) {

packages/openmemory-js/src/core/db.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ if (is_pg) {
142142
const admin = pool("postgres");
143143
try {
144144
await admin.query(`CREATE DATABASE ${db_name}`);
145-
console.log(`[DB] Created ${db_name}`);
145+
console.error(`[DB] Created ${db_name}`);
146146
} catch (e: any) {
147147
if (e.code !== "42P04") throw e;
148148
} finally {
@@ -202,11 +202,11 @@ if (is_pg) {
202202
// Initialize VectorStore
203203
if (env.vector_backend === "valkey") {
204204
vector_store = new ValkeyVectorStore();
205-
console.log("[DB] Using Valkey VectorStore");
205+
console.error("[DB] Using Valkey VectorStore");
206206
} else {
207207
const vt = process.env.OM_VECTOR_TABLE || "openmemory_vectors";
208208
vector_store = new PostgresVectorStore({ run_async, get_async, all_async }, v.replace(/"/g, ""));
209-
console.log(`[DB] Using Postgres VectorStore with table: ${v}`);
209+
console.error(`[DB] Using Postgres VectorStore with table: ${v}`);
210210
}
211211
};
212212
init().catch((err) => {
@@ -551,10 +551,10 @@ if (is_pg) {
551551

552552
if (env.vector_backend === "valkey") {
553553
vector_store = new ValkeyVectorStore();
554-
console.log("[DB] Using Valkey VectorStore");
554+
console.error("[DB] Using Valkey VectorStore");
555555
} else {
556556
vector_store = new PostgresVectorStore({ run_async, get_async, all_async }, sqlite_vector_table);
557-
console.log(`[DB] Using SQLite VectorStore with table: ${sqlite_vector_table}`);
557+
console.error(`[DB] Using SQLite VectorStore with table: ${sqlite_vector_table}`);
558558
}
559559

560560
// Simple Mutex for transaction serialization

packages/openmemory-js/src/server/routes/sources.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* generic webhook endpoint for source-specific payloads
99
*/
1010

11-
import * as sources from "../sources";
11+
import * as sources from "../../sources";
1212

1313
export function src(app: any) {
1414
// list available sources
@@ -61,7 +61,7 @@ export function src(app: any) {
6161
}
6262

6363
try {
64-
const { ingest_document } = await import("../../ops/ingest");
64+
const { ingestDocument } = await import("../../ops/ingest");
6565

6666
// handle different github events
6767
let content = "";
@@ -85,7 +85,7 @@ export function src(app: any) {
8585
}
8686

8787
if (content) {
88-
const result = await ingest_document("text", content, meta);
88+
const result = await ingestDocument("text", content, meta);
8989
res.json({ ok: true, memory_id: result.root_memory_id, event: event_type });
9090
} else {
9191
res.json({ ok: true, skipped: true, reason: "no content" });
@@ -100,9 +100,9 @@ export function src(app: any) {
100100
const payload = req.body;
101101

102102
try {
103-
const { ingest_document } = await import("../../ops/ingest");
103+
const { ingestDocument } = await import("../../ops/ingest");
104104
const content = JSON.stringify(payload, null, 2);
105-
const result = await ingest_document("text", content, { source: "notion_webhook" });
105+
const result = await ingestDocument("text", content, { source: "notion_webhook" });
106106
res.json({ ok: true, memory_id: result.root_memory_id });
107107
} catch (e: any) {
108108
res.status(500).json({ error: e.message });

packages/openmemory-js/src/sources/base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export abstract class base_source {
216216
}
217217

218218
async ingest_all(filters?: Record<string, any>): Promise<string[]> {
219-
const { ingest_document } = await import('../ops/ingest');
219+
const { ingestDocument } = await import('../ops/ingest');
220220

221221
const items = await this.list_items(filters);
222222
const ids: string[] = [];
@@ -228,7 +228,7 @@ export abstract class base_source {
228228
const item = items[i];
229229
try {
230230
const content = await this.fetch_item(item.id);
231-
const result = await ingest_document(
231+
const result = await ingestDocument(
232232
content.type || 'text',
233233
content.data || content.text || '',
234234
{ source: this.name, ...content.meta },

packages/openmemory-js/src/sources/onedrive.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ export class onedrive_source extends base_source {
7171
let next_url: string | null = url;
7272

7373
while (next_url) {
74-
const resp = await fetch(next_url, {
74+
const resp: Response = await fetch(next_url, {
7575
headers: { Authorization: `Bearer ${this.access_token}` }
7676
});
7777

7878
if (!resp.ok) throw new Error(`http ${resp.status}: ${resp.statusText}`);
7979

80-
const data = await resp.json();
80+
const data: any = await resp.json();
8181

8282
for (const item of data.value || []) {
8383
results.push({

packages/openmemory-js/src/sources/web_crawler.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
* no auth required for public urls
55
*/
66

7-
import { base_source, source_config_error, source_item, source_content } from './base';
7+
import { base_source, source_config_error, source_item, source_content, source_config } from './base';
8+
9+
export interface web_crawler_config extends source_config {
10+
max_pages?: number;
11+
max_depth?: number;
12+
timeout?: number;
13+
}
814

915
export class web_crawler_source extends base_source {
1016
name = 'web_crawler';
@@ -16,7 +22,7 @@ export class web_crawler_source extends base_source {
1622

1723
constructor(
1824
user_id?: string,
19-
config?: { max_pages?: number; max_depth?: number; timeout?: number } & Record<string, any>
25+
config?: web_crawler_config
2026
) {
2127
super(user_id, config);
2228
this.max_pages = config?.max_pages || 50;

0 commit comments

Comments
 (0)