promptgraph-mcp 2.9.12 → 2.9.14
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/index.js +42 -2
- package/indexer.js +22 -15
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -106,7 +106,7 @@ if (COMMAND_MAP[args[0]]) {
|
|
|
106
106
|
// ── MCP server mode (no CLI command) ──
|
|
107
107
|
const { Server } = await import('@modelcontextprotocol/sdk/server/index.js');
|
|
108
108
|
const { StdioServerTransport } = await import('@modelcontextprotocol/sdk/server/stdio.js');
|
|
109
|
-
const { CallToolRequestSchema, ListToolsRequestSchema } = await import('@modelcontextprotocol/sdk/types.js');
|
|
109
|
+
const { CallToolRequestSchema, ListToolsRequestSchema, ListPromptsRequestSchema, GetPromptRequestSchema } = await import('@modelcontextprotocol/sdk/types.js');
|
|
110
110
|
const { search, getContext, getCallers, getCallees, getImpact, listAll } = await import('./search.js');
|
|
111
111
|
const { loadConfig: _loadConfig, saveConfig: _saveConfig } = await import('./config.js');
|
|
112
112
|
const { startWatcher } = await import('./watcher.js');
|
|
@@ -116,7 +116,7 @@ const { createRequire } = await import('module');
|
|
|
116
116
|
const pkg = createRequire(import.meta.url)('./package.json');
|
|
117
117
|
const server = new Server(
|
|
118
118
|
{ name: 'promptgraph', version: pkg.version },
|
|
119
|
-
{ capabilities: { tools: {} } }
|
|
119
|
+
{ capabilities: { tools: {}, prompts: {} } }
|
|
120
120
|
);
|
|
121
121
|
|
|
122
122
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
@@ -332,6 +332,46 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
332
332
|
}
|
|
333
333
|
});
|
|
334
334
|
|
|
335
|
+
server.setRequestHandler(ListPromptsRequestSchema, async () => ({
|
|
336
|
+
prompts: [
|
|
337
|
+
{
|
|
338
|
+
name: 'pg',
|
|
339
|
+
description: 'Search skills and load the best match for your task',
|
|
340
|
+
arguments: [{ name: 'query', description: 'What you want to do', required: true }],
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
name: 'pg-list',
|
|
344
|
+
description: 'List all indexed skills',
|
|
345
|
+
arguments: [],
|
|
346
|
+
},
|
|
347
|
+
],
|
|
348
|
+
}));
|
|
349
|
+
|
|
350
|
+
server.setRequestHandler(GetPromptRequestSchema, async (request) => {
|
|
351
|
+
const { name, arguments: args } = request.params;
|
|
352
|
+
if (name === 'pg') {
|
|
353
|
+
const query = args?.query || '';
|
|
354
|
+
const results = await search(query, 3);
|
|
355
|
+
if (!results.length) return { messages: [{ role: 'user', content: { type: 'text', text: `No skills found for: ${query}` } }] };
|
|
356
|
+
const top = results[0];
|
|
357
|
+
const fs = await import('fs');
|
|
358
|
+
let content = '';
|
|
359
|
+
try { content = fs.readFileSync(top.path, 'utf8'); } catch {}
|
|
360
|
+
return {
|
|
361
|
+
messages: [{
|
|
362
|
+
role: 'user',
|
|
363
|
+
content: { type: 'text', text: `# Skill: ${top.name} (score: ${top.score?.toFixed(2)})\n\n${content}` },
|
|
364
|
+
}],
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
if (name === 'pg-list') {
|
|
368
|
+
const skills = await listAll();
|
|
369
|
+
const text = skills.map(s => `- **${s.name}** — ${s.description || ''}`).join('\n');
|
|
370
|
+
return { messages: [{ role: 'user', content: { type: 'text', text: text || 'No skills indexed.' } }] };
|
|
371
|
+
}
|
|
372
|
+
throw new Error(`Unknown prompt: ${name}`);
|
|
373
|
+
});
|
|
374
|
+
|
|
335
375
|
startWatcher();
|
|
336
376
|
|
|
337
377
|
const transport = new StdioServerTransport();
|
package/indexer.js
CHANGED
|
@@ -53,15 +53,7 @@ export async function indexBatch(db, skills, { fast = false } = {}) {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
if (!fast && allChunks.length) {
|
|
58
|
-
const texts = allChunks.map(c => c.text);
|
|
59
|
-
process.stdout.write(` Embedding ${texts.length} chunks...`);
|
|
60
|
-
embeddings = await embedBatch(texts);
|
|
61
|
-
process.stdout.write('\r' + ' '.repeat(40) + '\r');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// pass 1: upsert all skills + chunks (no edges yet)
|
|
56
|
+
// pass 1: upsert all skills metadata first (so chunks can reference them)
|
|
65
57
|
db.transaction(() => {
|
|
66
58
|
for (const skill of skills) {
|
|
67
59
|
const id = skillId(skill.source, skill.name);
|
|
@@ -72,14 +64,29 @@ export async function indexBatch(db, skills, { fast = false } = {}) {
|
|
|
72
64
|
deleteEdges.run(id);
|
|
73
65
|
}
|
|
74
66
|
}
|
|
75
|
-
if (!fast) {
|
|
76
|
-
for (let i = 0; i < allChunks.length; i++) {
|
|
77
|
-
const { id, chunkIndex, text } = allChunks[i];
|
|
78
|
-
upsertChunk.run(id, chunkIndex, text, vecToBlob(embeddings[i]));
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
67
|
})();
|
|
82
68
|
|
|
69
|
+
// pass 1b: embed in batches of 50 with progress bar, save each batch immediately
|
|
70
|
+
if (!fast && allChunks.length) {
|
|
71
|
+
const EMBED_BATCH = 50;
|
|
72
|
+
const total = allChunks.length;
|
|
73
|
+
for (let i = 0; i < total; i += EMBED_BATCH) {
|
|
74
|
+
const batch = allChunks.slice(i, i + EMBED_BATCH);
|
|
75
|
+
const texts = batch.map(c => c.text);
|
|
76
|
+
const vecs = await embedBatch(texts);
|
|
77
|
+
db.transaction(() => {
|
|
78
|
+
for (let j = 0; j < batch.length; j++) {
|
|
79
|
+
const { id, chunkIndex, text } = batch[j];
|
|
80
|
+
upsertChunk.run(id, chunkIndex, text, vecToBlob(vecs[j]));
|
|
81
|
+
}
|
|
82
|
+
})();
|
|
83
|
+
const done = Math.min(i + EMBED_BATCH, total);
|
|
84
|
+
const pct = Math.round(done / total * 100);
|
|
85
|
+
process.stdout.write(`\r Embedding chunks... ${done}/${total} (${pct}%) `);
|
|
86
|
+
}
|
|
87
|
+
process.stdout.write('\r' + ' '.repeat(50) + '\r');
|
|
88
|
+
}
|
|
89
|
+
|
|
83
90
|
// pass 2: resolve edges after all skills in batch are committed
|
|
84
91
|
const resolveSameSource = db.prepare("SELECT id FROM skills WHERE name = ? AND source = ? LIMIT 1");
|
|
85
92
|
const resolveAny = db.prepare("SELECT id FROM skills WHERE name = ? ORDER BY id LIMIT 1");
|