promptgraph-mcp 1.5.20 → 1.5.21

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 (3) hide show
  1. package/index.js +16 -11
  2. package/marketplace.js +37 -6
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -1,15 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
3
- import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
- import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
5
- import { search, getContext, getCallers, getCallees, getImpact, listAll } from './search.js';
6
- import { indexAll } from './indexer.js';
7
- import { startWatcher } from './watcher.js';
8
- import { promptConfig } from './config.js';
9
- import { importFromGitHub } from './github-import.js';
10
- import { detectPlatforms, PLATFORMS } from './platform.js';
11
- import { browseMarketplace, installSkill, publishSkill, getTopRated, recordUse, recordSuccess, recordFail, browseBundles, installBundle } from './marketplace.js';
12
-
2
+ // Only lightweight imports at top. Heavy modules (fastembed/ONNX, vectra,
3
+ // better-sqlite3) are dynamically imported inside the command that needs them,
4
+ // so fast CLI commands (help, marketplace) start instantly.
13
5
  import { colors, banner, success, error, info, section, table } from './cli.js';
14
6
  import boxen from 'boxen';
15
7
  import chalk from 'chalk';
@@ -222,11 +214,13 @@ if (args[0] === 'validate') {
222
214
  }
223
215
 
224
216
  if (args[0] === 'import') {
217
+ const { importFromGitHub } = await import('./github-import.js');
225
218
  await importFromGitHub(args[1]);
226
219
  process.exit(0);
227
220
  }
228
221
 
229
222
  if (args[0] === 'setup') {
223
+ const { detectPlatforms, PLATFORMS } = await import('./platform.js');
230
224
  const platformId = args[1];
231
225
  if (!platformId) {
232
226
  section('Detected platforms');
@@ -243,6 +237,8 @@ if (args[0] === 'setup') {
243
237
  }
244
238
 
245
239
  if (args[0] === 'init') {
240
+ const { promptConfig } = await import('./config.js');
241
+ const { indexAll } = await import('./indexer.js');
246
242
  const config = await promptConfig();
247
243
  await indexAll();
248
244
  console.log();
@@ -257,10 +253,19 @@ if (args[0] === 'init') {
257
253
  }
258
254
 
259
255
  if (args[0] === 'reindex') {
256
+ const { indexAll } = await import('./indexer.js');
260
257
  await indexAll();
261
258
  process.exit(0);
262
259
  }
263
260
 
261
+ // ── MCP server mode (no CLI command) ──
262
+ const { Server } = await import('@modelcontextprotocol/sdk/server/index.js');
263
+ const { StdioServerTransport } = await import('@modelcontextprotocol/sdk/server/stdio.js');
264
+ const { CallToolRequestSchema, ListToolsRequestSchema } = await import('@modelcontextprotocol/sdk/types.js');
265
+ const { search, getContext, getCallers, getCallees, getImpact, listAll } = await import('./search.js');
266
+ const { startWatcher } = await import('./watcher.js');
267
+ const { browseMarketplace, installSkill, publishSkill, getTopRated, recordUse, recordSuccess, recordFail, browseBundles, installBundle } = await import('./marketplace.js');
268
+
264
269
  const server = new Server(
265
270
  { name: 'promptgraph', version: '1.0.0' },
266
271
  { capabilities: { tools: {} } }
package/marketplace.js CHANGED
@@ -16,10 +16,10 @@ export function codeFor(id) {
16
16
  return 'pg-' + createHash('md5').update(String(id)).digest('hex').slice(0, 6);
17
17
  }
18
18
 
19
- // Robust fetch: try undici fetch, fall back to node:https (works where undici fails on Windows)
19
+ // node:https GET reliable and fast on Windows (undici fetch can hang ~10s there).
20
20
  function httpGet(url) {
21
21
  return new Promise((resolve, reject) => {
22
- https.get(url, { headers: { 'User-Agent': 'promptgraph-mcp' } }, (res) => {
22
+ const req = https.get(url, { headers: { 'User-Agent': 'promptgraph-mcp' }, timeout: 8000, family: 4 }, (res) => {
23
23
  if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
24
24
  return httpGet(res.headers.location).then(resolve, reject);
25
25
  }
@@ -31,20 +31,51 @@ function httpGet(url) {
31
31
  res.setEncoding('utf8');
32
32
  res.on('data', c => data += c);
33
33
  res.on('end', () => resolve(data));
34
- }).on('error', reject);
34
+ });
35
+ req.on('timeout', () => { req.destroy(new Error('request timed out')); });
36
+ req.on('error', reject);
35
37
  });
36
38
  }
37
39
 
38
- async function fetchText(url) {
40
+ // Primary path is httpGet (fast/reliable on Windows); undici fetch only as fallback.
41
+ async function rawFetch(url) {
39
42
  try {
43
+ return await httpGet(url);
44
+ } catch {
40
45
  const res = await fetch(url, { headers: { 'User-Agent': 'promptgraph-mcp' } });
41
46
  if (!res.ok) throw new Error(`HTTP ${res.status}`);
42
47
  return await res.text();
43
- } catch {
44
- return await httpGet(url);
45
48
  }
46
49
  }
47
50
 
51
+ // Disk cache for the registry (network to GitHub raw can be slow on some networks).
52
+ const CACHE_DIR = path.join(os.homedir(), '.claude', '.promptgraph');
53
+ const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
54
+
55
+ async function fetchText(url) {
56
+ const cacheFile = path.join(CACHE_DIR, 'registry-cache.json');
57
+ const isRegistry = url === REGISTRY_URL;
58
+
59
+ if (isRegistry && fs.existsSync(cacheFile)) {
60
+ try {
61
+ const stat = fs.statSync(cacheFile);
62
+ if (Date.now() - stat.mtimeMs < CACHE_TTL) {
63
+ return fs.readFileSync(cacheFile, 'utf8');
64
+ }
65
+ } catch {}
66
+ }
67
+
68
+ const text = await rawFetch(url);
69
+
70
+ if (isRegistry) {
71
+ try {
72
+ fs.mkdirSync(CACHE_DIR, { recursive: true });
73
+ fs.writeFileSync(cacheFile, text);
74
+ } catch {}
75
+ }
76
+ return text;
77
+ }
78
+
48
79
  export async function browseMarketplace(topK = 20) {
49
80
  try {
50
81
  const text = await fetchText(REGISTRY_URL);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "promptgraph-mcp",
3
- "version": "1.5.20",
3
+ "version": "1.5.21",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "bin": {