cf-memory-mcp 3.8.3 → 3.8.5

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.
@@ -302,49 +302,41 @@ class IncrementalIndexer {
302
302
  // Initial index
303
303
  await this.index();
304
304
 
305
- // Watch for changes
306
- const chokidar = await this.loadChokidar();
307
-
308
- const watcher = chokidar.watch(this.projectPath, {
309
- ignored: this.exclude,
310
- persistent: true,
311
- ignoreInitial: true
312
- });
313
-
314
- let debounceTimer = null;
315
-
316
- const handleChange = async () => {
317
- if (debounceTimer) clearTimeout(debounceTimer);
318
- debounceTimer = setTimeout(async () => {
319
- console.log('\nšŸ”„ Changes detected, re-indexing...');
320
- await this.index();
321
- console.log('');
322
- }, 1000);
305
+ // Use Node's built-in fs.watch (no external deps needed)
306
+ const fs = require('fs');
307
+ const watchDir = (dir) => {
308
+ let watcher;
309
+ try {
310
+ watcher = fs.watch(dir, { recursive: true }, (eventType, filename) => {
311
+ if (filename) {
312
+ this.handleFileChange(dir, filename);
313
+ }
314
+ });
315
+ } catch (err) {
316
+ // Ignore errors for now
317
+ }
318
+ return watcher;
323
319
  };
324
320
 
325
- watcher
326
- .on('add', path => handleChange())
327
- .on('change', path => handleChange())
328
- .on('unlink', path => handleChange());
321
+ const watcher = watchDir(this.projectPath);
329
322
 
330
323
  // Keep process alive
331
324
  process.on('SIGINT', () => {
332
325
  console.log('\nšŸ‘‹ Stopping watcher...');
333
- watcher.close();
326
+ if (watcher) watcher.close();
334
327
  process.exit(0);
335
328
  });
336
329
  }
337
330
 
338
- async loadChokidar() {
339
- try {
340
- return require('chokidar');
341
- } catch (err) {
342
- console.log('Installing chokidar for file watching...');
343
- const { execSync } = require('child_process');
344
- execSync('npm install chokidar --save-dev', { cwd: __dirname, stdio: 'inherit' });
345
- return require('chokidar');
346
- }
331
+ handleFileChange(baseDir, filename) {
332
+ // Debounce rapid changes
333
+ if (this._debounceTimer) clearTimeout(this._debounceTimer);
334
+ this._debounceTimer = setTimeout(async () => {
335
+ console.log(`\nšŸ”„ File changed: ${filename}`);
336
+ await this.index();
337
+ }, 1000);
347
338
  }
339
+
348
340
  }
349
341
 
350
342
  // CLI
@@ -355,8 +347,19 @@ async function main() {
355
347
  }
356
348
 
357
349
  const args = process.argv.slice(2);
358
- const command = args[0];
359
- const projectPath = args[1] || '.';
350
+
351
+ // Detect command from how the script was called (cf-memory-index vs cf-memory-watch)
352
+ const scriptName = path.basename(process.argv[1]);
353
+ let command = args[0];
354
+ let projectPath = args[1] || '.';
355
+
356
+ if (scriptName.includes('watch')) {
357
+ command = 'watch';
358
+ projectPath = args[0] || '.';
359
+ } else if (scriptName.includes('index')) {
360
+ command = 'index';
361
+ projectPath = args[0] || '.';
362
+ }
360
363
 
361
364
  const options = {
362
365
  dryRun: args.includes('--dry-run'),
@@ -388,7 +391,12 @@ Environment:
388
391
  }
389
392
  }
390
393
 
391
- main().catch(err => {
392
- console.error('Error:', err.message);
393
- process.exit(1);
394
- });
394
+ // Export for programmatic use
395
+ if (require.main === module) {
396
+ main().catch(err => {
397
+ console.error('Error:', err.message);
398
+ process.exit(1);
399
+ });
400
+ }
401
+
402
+ module.exports = { IncrementalIndexer };
@@ -45,6 +45,7 @@ class CFMemoryMCP {
45
45
  this.legacyServerUrl = LEGACY_SERVER_URL;
46
46
  this.userAgent = `cf-memory-mcp/${PACKAGE_VERSION} (${os.platform()} ${os.arch()}; Node.js ${process.version})`;
47
47
  this.useStreamableHttp = true; // Try Streamable HTTP first
48
+ this.autoWatcher = null; // Background file watcher
48
49
 
49
50
  // Handle process termination gracefully
50
51
  process.on('SIGINT', () => this.shutdown('SIGINT'));
@@ -91,12 +92,46 @@ class CFMemoryMCP {
91
92
  try {
92
93
  // Skip connectivity test in MCP mode - it will be tested when first request is made
93
94
  this.logDebug('Starting MCP message processing...');
95
+
96
+ // Start auto-watcher if CF_MEMORY_AUTO_WATCH is set
97
+ if (process.env.CF_MEMORY_AUTO_WATCH === '1' || process.env.CF_MEMORY_AUTO_WATCH === 'true') {
98
+ this.startAutoWatcher();
99
+ }
100
+
94
101
  await this.processStdio();
95
102
  } catch (error) {
96
103
  this.logError('Failed to start MCP server:', error);
97
104
  process.exit(1);
98
105
  }
99
106
  }
107
+
108
+ /**
109
+ * Start auto-watching files for changes
110
+ */
111
+ async startAutoWatcher() {
112
+ // Use CF_MEMORY_WATCH_PATH if set, otherwise use current working directory
113
+ const watchPath = process.env.CF_MEMORY_WATCH_PATH || process.cwd();
114
+ const projectName = process.env.CF_MEMORY_PROJECT_NAME || path.basename(watchPath);
115
+
116
+ this.logDebug(`Starting auto-watch for: ${watchPath} (${projectName})`);
117
+
118
+ try {
119
+ // Dynamically import the indexer
120
+ const { IncrementalIndexer } = require('./cf-memory-mcp-indexer.js');
121
+ this.autoWatcher = new IncrementalIndexer(watchPath, {
122
+ name: projectName
123
+ });
124
+
125
+ // Start watching in background
126
+ this.autoWatcher.watch().catch(err => {
127
+ this.logError('Auto-watch error:', err);
128
+ });
129
+
130
+ this.logDebug('Auto-watch started successfully');
131
+ } catch (err) {
132
+ this.logError('Failed to start auto-watch:', err);
133
+ }
134
+ }
100
135
 
101
136
  /**
102
137
  * Test connectivity to the Cloudflare Worker
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cf-memory-mcp",
3
- "version": "3.8.3",
3
+ "version": "3.8.5",
4
4
  "description": "Best-in-class MCP server with CONTEXTUAL CHUNKING (Anthropic-style, 35-67% better retrieval), Optimized LLM stack (Llama-3.1-8B), BGE-M3 embeddings, Query Expansion Caching, Hybrid Embedding Strategy, and Unified Project Intelligence",
5
5
  "main": "bin/cf-memory-mcp.js",
6
6
  "bin": {