@wonderwhy-er/desktop-commander 0.2.23 → 0.2.24

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 (59) hide show
  1. package/README.md +14 -55
  2. package/dist/custom-stdio.d.ts +1 -0
  3. package/dist/custom-stdio.js +19 -0
  4. package/dist/handlers/filesystem-handlers.d.ts +4 -0
  5. package/dist/handlers/filesystem-handlers.js +120 -14
  6. package/dist/handlers/node-handlers.d.ts +6 -0
  7. package/dist/handlers/node-handlers.js +73 -0
  8. package/dist/index.js +5 -3
  9. package/dist/search-manager.d.ts +25 -0
  10. package/dist/search-manager.js +212 -0
  11. package/dist/server.js +160 -73
  12. package/dist/terminal-manager.d.ts +56 -2
  13. package/dist/terminal-manager.js +169 -13
  14. package/dist/tools/edit.d.ts +28 -4
  15. package/dist/tools/edit.js +87 -4
  16. package/dist/tools/filesystem.d.ts +23 -12
  17. package/dist/tools/filesystem.js +201 -416
  18. package/dist/tools/improved-process-tools.d.ts +2 -2
  19. package/dist/tools/improved-process-tools.js +244 -214
  20. package/dist/tools/mime-types.d.ts +1 -0
  21. package/dist/tools/mime-types.js +7 -0
  22. package/dist/tools/pdf/extract-images.d.ts +34 -0
  23. package/dist/tools/pdf/extract-images.js +132 -0
  24. package/dist/tools/pdf/index.d.ts +6 -0
  25. package/dist/tools/pdf/index.js +3 -0
  26. package/dist/tools/pdf/lib/pdf2md.d.ts +36 -0
  27. package/dist/tools/pdf/lib/pdf2md.js +76 -0
  28. package/dist/tools/pdf/manipulations.d.ts +13 -0
  29. package/dist/tools/pdf/manipulations.js +96 -0
  30. package/dist/tools/pdf/markdown.d.ts +7 -0
  31. package/dist/tools/pdf/markdown.js +37 -0
  32. package/dist/tools/pdf/utils.d.ts +12 -0
  33. package/dist/tools/pdf/utils.js +34 -0
  34. package/dist/tools/schemas.d.ts +167 -12
  35. package/dist/tools/schemas.js +54 -5
  36. package/dist/types.d.ts +2 -1
  37. package/dist/utils/feature-flags.js +7 -4
  38. package/dist/utils/files/base.d.ts +167 -0
  39. package/dist/utils/files/base.js +5 -0
  40. package/dist/utils/files/binary.d.ts +21 -0
  41. package/dist/utils/files/binary.js +65 -0
  42. package/dist/utils/files/excel.d.ts +24 -0
  43. package/dist/utils/files/excel.js +416 -0
  44. package/dist/utils/files/factory.d.ts +40 -0
  45. package/dist/utils/files/factory.js +101 -0
  46. package/dist/utils/files/image.d.ts +21 -0
  47. package/dist/utils/files/image.js +78 -0
  48. package/dist/utils/files/index.d.ts +10 -0
  49. package/dist/utils/files/index.js +13 -0
  50. package/dist/utils/files/pdf.d.ts +32 -0
  51. package/dist/utils/files/pdf.js +142 -0
  52. package/dist/utils/files/text.d.ts +63 -0
  53. package/dist/utils/files/text.js +357 -0
  54. package/dist/utils/ripgrep-resolver.js +3 -2
  55. package/dist/utils/system-info.d.ts +5 -0
  56. package/dist/utils/system-info.js +71 -3
  57. package/dist/version.d.ts +1 -1
  58. package/dist/version.js +1 -1
  59. package/package.json +14 -3
@@ -1,8 +1,10 @@
1
1
  import { spawn } from 'child_process';
2
2
  import path from 'path';
3
+ import fs from 'fs/promises';
3
4
  import { validatePath } from './tools/filesystem.js';
4
5
  import { capture } from './utils/capture.js';
5
6
  import { getRipgrepPath } from './utils/ripgrep-resolver.js';
7
+ import { isExcelFile } from './utils/files/index.js';
6
8
  /**
7
9
  * Search Session Manager - handles ripgrep processes like terminal sessions
8
10
  * Supports both file search and content search with progressive results
@@ -85,7 +87,26 @@ import { getRipgrepPath } from './utils/ripgrep-resolver.js';
85
87
  requestedPath: options.rootPath,
86
88
  validatedPath: validPath
87
89
  });
90
+ // For content searches, only search Excel files when contextually relevant:
91
+ // - filePattern explicitly targets Excel files (*.xlsx, *.xls, etc.)
92
+ // - or rootPath is an Excel file itself
93
+ const shouldSearchExcel = options.searchType === 'content' &&
94
+ this.shouldIncludeExcelSearch(options.filePattern, validPath);
95
+ if (shouldSearchExcel) {
96
+ this.searchExcelFiles(validPath, options.pattern, options.ignoreCase !== false, options.maxResults, options.filePattern // Pass filePattern to filter Excel files too
97
+ ).then(excelResults => {
98
+ // Add Excel results to session (merged after initial response)
99
+ for (const result of excelResults) {
100
+ session.results.push(result);
101
+ session.totalMatches++;
102
+ }
103
+ }).catch((err) => {
104
+ // Log Excel search errors but don't fail the whole search
105
+ capture('excel_search_error', { error: err instanceof Error ? err.message : String(err) });
106
+ });
107
+ }
88
108
  // Wait for first chunk of data or early completion instead of fixed delay
109
+ // Excel search runs in background and results are merged via readSearchResults
89
110
  const firstChunk = new Promise(resolve => {
90
111
  const onData = () => {
91
112
  session.process.stdout?.off('data', onData);
@@ -94,6 +115,7 @@ import { getRipgrepPath } from './utils/ripgrep-resolver.js';
94
115
  session.process.stdout?.once('data', onData);
95
116
  setTimeout(resolve, 40); // cap at 40ms instead of 50-100ms
96
117
  });
118
+ // Only wait for ripgrep first chunk - Excel results merge asynchronously
97
119
  await firstChunk;
98
120
  return {
99
121
  sessionId,
@@ -178,6 +200,170 @@ import { getRipgrepPath } from './utils/ripgrep-resolver.js';
178
200
  totalResults: session.totalMatches + session.totalContextLines
179
201
  }));
180
202
  }
203
+ /**
204
+ * Search Excel files for content matches
205
+ * Called during content search to include Excel files alongside text files
206
+ * Searches ALL sheets in each Excel file (row-wise for cross-column matching)
207
+ *
208
+ * TODO: Refactor - Extract Excel search logic to separate module (src/utils/search/excel-search.ts)
209
+ * and inject into SearchManager, similar to how file handlers are structured in src/utils/files/
210
+ * This would allow adding other file type searches (PDF, etc.) without bloating search-manager.ts
211
+ */
212
+ async searchExcelFiles(rootPath, pattern, ignoreCase, maxResults, filePattern) {
213
+ const results = [];
214
+ // Build regex for matching content
215
+ const flags = ignoreCase ? 'i' : '';
216
+ let regex;
217
+ try {
218
+ regex = new RegExp(pattern, flags);
219
+ }
220
+ catch {
221
+ // If pattern is not valid regex, escape it for literal matching
222
+ const escaped = pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
223
+ regex = new RegExp(escaped, flags);
224
+ }
225
+ // Find Excel files recursively
226
+ let excelFiles = await this.findExcelFiles(rootPath);
227
+ // Filter by filePattern if provided
228
+ if (filePattern) {
229
+ const patterns = filePattern.split('|').map(p => p.trim()).filter(Boolean);
230
+ excelFiles = excelFiles.filter(filePath => {
231
+ const fileName = path.basename(filePath);
232
+ return patterns.some(pat => {
233
+ // Support glob-like patterns
234
+ if (pat.includes('*')) {
235
+ const regexPat = pat.replace(/\./g, '\\.').replace(/\*/g, '.*');
236
+ return new RegExp(`^${regexPat}$`, 'i').test(fileName);
237
+ }
238
+ // Exact match (case-insensitive)
239
+ return fileName.toLowerCase() === pat.toLowerCase();
240
+ });
241
+ });
242
+ }
243
+ // Dynamically import ExcelJS to search all sheets
244
+ const ExcelJS = await import('exceljs');
245
+ for (const filePath of excelFiles) {
246
+ if (maxResults && results.length >= maxResults)
247
+ break;
248
+ try {
249
+ const workbook = new ExcelJS.default.Workbook();
250
+ await workbook.xlsx.readFile(filePath);
251
+ // Search ALL sheets in the workbook (row-wise for speed and cross-column matching)
252
+ for (const worksheet of workbook.worksheets) {
253
+ if (maxResults && results.length >= maxResults)
254
+ break;
255
+ const sheetName = worksheet.name;
256
+ // Iterate through rows (faster than cell-by-cell)
257
+ worksheet.eachRow({ includeEmpty: false }, (row, rowNumber) => {
258
+ if (maxResults && results.length >= maxResults)
259
+ return;
260
+ // Build a concatenated string of all cell values in the row
261
+ const rowValues = [];
262
+ row.eachCell({ includeEmpty: false }, (cell) => {
263
+ if (cell.value === null || cell.value === undefined)
264
+ return;
265
+ let cellStr;
266
+ if (typeof cell.value === 'object') {
267
+ if ('result' in cell.value) {
268
+ cellStr = String(cell.value.result ?? '');
269
+ }
270
+ else if ('richText' in cell.value) {
271
+ cellStr = cell.value.richText.map((rt) => rt.text).join('');
272
+ }
273
+ else if ('text' in cell.value) {
274
+ cellStr = String(cell.value.text);
275
+ }
276
+ else {
277
+ cellStr = String(cell.value);
278
+ }
279
+ }
280
+ else {
281
+ cellStr = String(cell.value);
282
+ }
283
+ if (cellStr.trim()) {
284
+ rowValues.push(cellStr);
285
+ }
286
+ });
287
+ // Join all cell values with space for cross-column matching
288
+ const rowText = rowValues.join(' ');
289
+ if (regex.test(rowText)) {
290
+ // Extract the matching portion for display
291
+ const match = rowText.match(regex);
292
+ const matchContext = match
293
+ ? this.getMatchContext(rowText, match.index || 0, match[0].length)
294
+ : rowText.substring(0, 150);
295
+ results.push({
296
+ file: `${filePath}:${sheetName}!Row${rowNumber}`,
297
+ line: rowNumber,
298
+ match: matchContext,
299
+ type: 'content'
300
+ });
301
+ }
302
+ });
303
+ }
304
+ }
305
+ catch (error) {
306
+ // Skip files that can't be read (permission issues, corrupted, etc.)
307
+ continue;
308
+ }
309
+ }
310
+ return results;
311
+ }
312
+ /**
313
+ * Find all Excel files in a directory recursively
314
+ */
315
+ async findExcelFiles(rootPath) {
316
+ const excelFiles = [];
317
+ async function walk(dir) {
318
+ try {
319
+ const entries = await fs.readdir(dir, { withFileTypes: true });
320
+ for (const entry of entries) {
321
+ const fullPath = path.join(dir, entry.name);
322
+ if (entry.isDirectory()) {
323
+ // Skip node_modules, .git, etc.
324
+ if (!entry.name.startsWith('.') && entry.name !== 'node_modules') {
325
+ await walk(fullPath);
326
+ }
327
+ }
328
+ else if (entry.isFile() && isExcelFile(entry.name)) {
329
+ excelFiles.push(fullPath);
330
+ }
331
+ }
332
+ }
333
+ catch {
334
+ // Skip directories we can't read
335
+ }
336
+ }
337
+ // Check if rootPath is a file or directory
338
+ try {
339
+ const stats = await fs.stat(rootPath);
340
+ if (stats.isFile() && isExcelFile(rootPath)) {
341
+ return [rootPath];
342
+ }
343
+ else if (stats.isDirectory()) {
344
+ await walk(rootPath);
345
+ }
346
+ }
347
+ catch {
348
+ // Path doesn't exist or can't be accessed
349
+ }
350
+ return excelFiles;
351
+ }
352
+ /**
353
+ * Extract context around a match for display (show surrounding text)
354
+ */
355
+ getMatchContext(text, matchStart, matchLength) {
356
+ const contextChars = 50; // chars before and after match
357
+ const start = Math.max(0, matchStart - contextChars);
358
+ const end = Math.min(text.length, matchStart + matchLength + contextChars);
359
+ let context = text.substring(start, end);
360
+ // Add ellipsis if truncated
361
+ if (start > 0)
362
+ context = '...' + context;
363
+ if (end < text.length)
364
+ context = context + '...';
365
+ return context;
366
+ }
181
367
  /**
182
368
  * Clean up completed sessions older than specified time
183
369
  * Called automatically by cleanup interval
@@ -215,6 +401,32 @@ import { getRipgrepPath } from './utils/ripgrep-resolver.js';
215
401
  pattern.includes(']') ||
216
402
  pattern.includes('}');
217
403
  }
404
+ /**
405
+ * Determine if Excel search should be included based on context
406
+ * Only searches Excel files when:
407
+ * - filePattern explicitly targets Excel files (*.xlsx, *.xls, *.xlsm, *.xlsb)
408
+ * - or the rootPath itself is an Excel file
409
+ */
410
+ shouldIncludeExcelSearch(filePattern, rootPath) {
411
+ const excelExtensions = ['.xlsx', '.xls', '.xlsm', '.xlsb'];
412
+ // Check if rootPath is an Excel file
413
+ if (rootPath) {
414
+ const lowerPath = rootPath.toLowerCase();
415
+ if (excelExtensions.some(ext => lowerPath.endsWith(ext))) {
416
+ return true;
417
+ }
418
+ }
419
+ // Check if filePattern targets Excel files
420
+ if (filePattern) {
421
+ const lowerPattern = filePattern.toLowerCase();
422
+ // Check for patterns like *.xlsx, *.xls, or explicit Excel extensions
423
+ if (excelExtensions.some(ext => lowerPattern.includes(`*${ext}`) ||
424
+ lowerPattern.endsWith(ext))) {
425
+ return true;
426
+ }
427
+ }
428
+ return false;
429
+ }
218
430
  buildRipgrepArgs(options) {
219
431
  const args = [];
220
432
  if (options.searchType === 'content') {
package/dist/server.js CHANGED
@@ -8,7 +8,7 @@ const OS_GUIDANCE = getOSSpecificGuidance(SYSTEM_INFO);
8
8
  const DEV_TOOL_GUIDANCE = getDevelopmentToolGuidance(SYSTEM_INFO);
9
9
  const PATH_GUIDANCE = `IMPORTANT: ${getPathGuidance(SYSTEM_INFO)} Relative paths may fail as they depend on the current working directory. Tilde paths (~/...) might not work in all contexts. Unless the user explicitly asks for relative paths, use absolute paths.`;
10
10
  const CMD_PREFIX_DESCRIPTION = `This command can be referenced as "DC: ..." or "use Desktop Commander to ..." in your instructions.`;
11
- import { StartProcessArgsSchema, ReadProcessOutputArgsSchema, InteractWithProcessArgsSchema, ForceTerminateArgsSchema, ListSessionsArgsSchema, KillProcessArgsSchema, ReadFileArgsSchema, ReadMultipleFilesArgsSchema, WriteFileArgsSchema, CreateDirectoryArgsSchema, ListDirectoryArgsSchema, MoveFileArgsSchema, GetFileInfoArgsSchema, GetConfigArgsSchema, SetConfigValueArgsSchema, ListProcessesArgsSchema, EditBlockArgsSchema, GetUsageStatsArgsSchema, GiveFeedbackArgsSchema, StartSearchArgsSchema, GetMoreSearchResultsArgsSchema, StopSearchArgsSchema, ListSearchesArgsSchema, GetPromptsArgsSchema, GetRecentToolCallsArgsSchema, } from './tools/schemas.js';
11
+ import { StartProcessArgsSchema, ReadProcessOutputArgsSchema, InteractWithProcessArgsSchema, ForceTerminateArgsSchema, ListSessionsArgsSchema, KillProcessArgsSchema, ReadFileArgsSchema, ReadMultipleFilesArgsSchema, WriteFileArgsSchema, CreateDirectoryArgsSchema, ListDirectoryArgsSchema, MoveFileArgsSchema, GetFileInfoArgsSchema, GetConfigArgsSchema, SetConfigValueArgsSchema, ListProcessesArgsSchema, EditBlockArgsSchema, GetUsageStatsArgsSchema, GiveFeedbackArgsSchema, StartSearchArgsSchema, GetMoreSearchResultsArgsSchema, StopSearchArgsSchema, ListSearchesArgsSchema, GetPromptsArgsSchema, GetRecentToolCallsArgsSchema, WritePdfArgsSchema, } from './tools/schemas.js';
12
12
  import { getConfig, setConfigValue } from './tools/config.js';
13
13
  import { getUsageStats } from './tools/usage.js';
14
14
  import { giveFeedbackToDesktopCommander } from './tools/feedback.js';
@@ -173,7 +173,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
173
173
  {
174
174
  name: "read_file",
175
175
  description: `
176
- Read the contents of a file from the file system or a URL with optional offset and length parameters.
176
+ Read contents from files and URLs.
177
+ Read PDF files and extract content as markdown and images.
177
178
 
178
179
  Prefer this over 'execute_command' with cat/type for viewing files.
179
180
 
@@ -200,9 +201,17 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
200
201
  Can fetch content from URLs when isUrl parameter is set to true
201
202
  (URLs are always read in full regardless of offset/length).
202
203
 
203
- Handles text files normally and image files are returned as viewable images.
204
- Recognized image types: PNG, JPEG, GIF, WebP.
205
-
204
+ FORMAT HANDLING (by extension):
205
+ - Text: Uses offset/length for line-based pagination
206
+ - Excel (.xlsx, .xls, .xlsm): Returns JSON 2D array
207
+ * sheet: "Sheet1" (name) or "0" (index as string, 0-based)
208
+ * range: ALWAYS use FROM:TO format (e.g., "A1:D100", "C1:C1", "B2:B50")
209
+ * offset/length work as row pagination (optional fallback)
210
+ - Images (PNG, JPEG, GIF, WebP): Base64 encoded viewable content
211
+ - PDF: Extracts text content as markdown with page structure
212
+ * offset/length work as page pagination (0-based)
213
+ * Includes embedded images when available
214
+
206
215
  ${PATH_GUIDANCE}
207
216
  ${CMD_PREFIX_DESCRIPTION}`,
208
217
  inputSchema: zodToJsonSchema(ReadFileArgsSchema),
@@ -235,7 +244,9 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
235
244
  {
236
245
  name: "write_file",
237
246
  description: `
238
- Write or append to file contents.
247
+ Write or append to file contents.
248
+
249
+ IMPORTANT: DO NOT use this tool to create PDF files. Use 'write_pdf' for all PDF creation tasks.
239
250
 
240
251
  CHUNKING IS STANDARD PRACTICE: Always write files in chunks of 25-30 lines maximum.
241
252
  This is the normal, recommended way to write files - not an emergency measure.
@@ -251,16 +262,21 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
251
262
  1. Any file expected to be longer than 25-30 lines
252
263
  2. When writing multiple files in sequence
253
264
  3. When creating documentation, code files, or configuration files
254
-
265
+
255
266
  HANDLING CONTINUATION ("Continue" prompts):
256
267
  If user asks to "Continue" after an incomplete operation:
257
268
  1. Read the file to see what was successfully written
258
269
  2. Continue writing ONLY the remaining content using {mode: 'append'}
259
270
  3. Keep chunks to 25-30 lines each
260
-
271
+
272
+ FORMAT HANDLING (by extension):
273
+ - Text files: String content
274
+ - Excel (.xlsx, .xls, .xlsm): JSON 2D array or {"SheetName": [[...]]}
275
+ Example: '[["Name","Age"],["Alice",30]]'
276
+
261
277
  Files over 50 lines will generate performance notes but are still written successfully.
262
278
  Only works within allowed directories.
263
-
279
+
264
280
  ${PATH_GUIDANCE}
265
281
  ${CMD_PREFIX_DESCRIPTION}`,
266
282
  inputSchema: zodToJsonSchema(WriteFileArgsSchema),
@@ -271,6 +287,68 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
271
287
  openWorldHint: false,
272
288
  },
273
289
  },
290
+ {
291
+ name: "write_pdf",
292
+ description: `
293
+ Create a new PDF file or modify an existing one.
294
+
295
+ THIS IS THE ONLY TOOL FOR CREATING AND MODIFYING PDF FILES.
296
+
297
+ RULES ABOUT FILENAMES:
298
+ - When creating a new PDF, 'outputPath' MUST be provided and MUST use a new unique filename (e.g., "result_01.pdf", "analysis_2025_01.pdf", etc.).
299
+
300
+ MODES:
301
+ 1. CREATE NEW PDF:
302
+ - Pass a markdown string as 'content'.
303
+ write_pdf(path="doc.pdf", content="# Title\\n\\nBody text...")
304
+
305
+ 2. MODIFY EXISTING PDF:
306
+ - Pass array of operations as 'content'.
307
+ - NEVER overwrite the original file.
308
+ - ALWAYS provide a new filename in 'outputPath'.
309
+ - After modifying, show original file path and new file path to user.
310
+
311
+ write_pdf(path="doc.pdf", content=[
312
+ { type: "delete", pageIndexes: [0, 2] },
313
+ { type: "insert", pageIndex: 1, markdown: "# New Page" }
314
+ ])
315
+
316
+ OPERATIONS:
317
+ - delete: Remove pages by 0-based index.
318
+ { type: "delete", pageIndexes: [0, 1, 5] }
319
+
320
+ - insert: Add pages at a specific 0-based index.
321
+ { type: "insert", pageIndex: 0, markdown: "..." }
322
+ { type: "insert", pageIndex: 5, sourcePdfPath: "/path/to/source.pdf" }
323
+
324
+ PAGE BREAKS:
325
+ To force a page break, use this HTML element:
326
+ <div style="page-break-before: always;"></div>
327
+
328
+ Example:
329
+ "# Page 1\\n\\n<div style=\\"page-break-before: always;\\"></div>\\n\\n# Page 2"
330
+
331
+ ADVANCED STYLING:
332
+ HTML/CSS and inline SVG are supported for:
333
+ - Text styling: colors, sizes, alignment, highlights
334
+ - Boxes: borders, backgrounds, padding, rounded corners
335
+ - SVG graphics: charts, diagrams, icons, shapes
336
+ - Images: <img src="/absolute/path/image.jpg" width="300" /> or ![alt](/path/image.jpg)
337
+
338
+ Supports standard markdown features including headers, lists, code blocks, tables, and basic formatting.
339
+
340
+ Only works within allowed directories.
341
+
342
+ ${PATH_GUIDANCE}
343
+ ${CMD_PREFIX_DESCRIPTION}`,
344
+ inputSchema: zodToJsonSchema(WritePdfArgsSchema),
345
+ annotations: {
346
+ title: "Write/Modify PDF",
347
+ readOnlyHint: false,
348
+ destructiveHint: true,
349
+ openWorldHint: false,
350
+ },
351
+ },
274
352
  {
275
353
  name: "create_directory",
276
354
  description: `
@@ -489,13 +567,14 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
489
567
  Retrieve detailed metadata about a file or directory including:
490
568
  - size
491
569
  - creation time
492
- - last modified time
570
+ - last modified time
493
571
  - permissions
494
572
  - type
495
573
  - lineCount (for text files)
496
574
  - lastLine (zero-indexed number of last line, for text files)
497
575
  - appendPosition (line number for appending, for text files)
498
-
576
+ - sheets (for Excel files - array of {name, rowCount, colCount})
577
+
499
578
  Only works within allowed directories.
500
579
 
501
580
  ${PATH_GUIDANCE}
@@ -507,45 +586,54 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
507
586
  },
508
587
  },
509
588
  // Note: list_allowed_directories removed - use get_config to check allowedDirectories
510
- // Text editing tools
589
+ // Editing tools
511
590
  {
512
591
  name: "edit_block",
513
592
  description: `
514
- Apply surgical text replacements to files.
515
-
593
+ Apply surgical edits to files.
594
+
516
595
  BEST PRACTICE: Make multiple small, focused edits rather than one large edit.
517
- Each edit_block call should change only what needs to be changed - include just enough
596
+ Each edit_block call should change only what needs to be changed - include just enough
518
597
  context to uniquely identify the text being modified.
519
-
598
+
599
+ FORMAT HANDLING (by extension):
600
+
601
+ EXCEL FILES (.xlsx, .xls, .xlsm) - Range Update mode:
602
+ Takes:
603
+ - file_path: Path to the Excel file
604
+ - range: ALWAYS use FROM:TO format - "SheetName!A1:C10" or "SheetName!C1:C1"
605
+ - content: 2D array, e.g., [["H1","H2"],["R1","R2"]]
606
+
607
+ TEXT FILES - Find/Replace mode:
520
608
  Takes:
521
609
  - file_path: Path to the file to edit
522
610
  - old_string: Text to replace
523
611
  - new_string: Replacement text
524
- - expected_replacements: Optional parameter for number of replacements
525
-
612
+ - expected_replacements: Optional number of replacements (default: 1)
613
+
526
614
  By default, replaces only ONE occurrence of the search text.
527
- To replace multiple occurrences, provide the expected_replacements parameter with
615
+ To replace multiple occurrences, provide expected_replacements with
528
616
  the exact number of matches expected.
529
-
617
+
530
618
  UNIQUENESS REQUIREMENT: When expected_replacements=1 (default), include the minimal
531
619
  amount of context necessary (typically 1-3 lines) before and after the change point,
532
620
  with exact whitespace and indentation.
533
-
621
+
534
622
  When editing multiple sections, make separate edit_block calls for each distinct change
535
623
  rather than one large replacement.
536
-
624
+
537
625
  When a close but non-exact match is found, a character-level diff is shown in the format:
538
626
  common_prefix{-removed-}{+added+}common_suffix to help you identify what's different.
539
-
627
+
540
628
  Similar to write_file, there is a configurable line limit (fileWriteLineLimit) that warns
541
629
  if the edited file exceeds this limit. If this happens, consider breaking your edits into
542
630
  smaller, more focused changes.
543
-
631
+
544
632
  ${PATH_GUIDANCE}
545
633
  ${CMD_PREFIX_DESCRIPTION}`,
546
634
  inputSchema: zodToJsonSchema(EditBlockArgsSchema),
547
635
  annotations: {
548
- title: "Edit Text Block",
636
+ title: "Edit Block",
549
637
  readOnlyHint: false,
550
638
  destructiveHint: true,
551
639
  openWorldHint: false,
@@ -574,7 +662,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
574
662
 
575
663
  COMMON FILE ANALYSIS PATTERNS:
576
664
  • start_process("python3 -i") → Python REPL for data analysis (RECOMMENDED)
577
- • start_process("node -i") → Node.js for JSON processing
665
+ • start_process("node -i") → Node.js REPL for JSON processing
666
+ • start_process("node:local") → Node.js on MCP server (stateless, ES imports, all code in one call)
578
667
  • start_process("cut -d',' -f1 file.csv | sort | uniq -c") → Quick CSV analysis
579
668
  • start_process("wc -l /path/file.csv") → Line counting
580
669
  • start_process("head -10 /path/file.csv") → File preview
@@ -583,12 +672,15 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
583
672
  For PDF, Excel, Word, archives, databases, and other binary formats, use process tools with appropriate libraries or command-line utilities.
584
673
 
585
674
  INTERACTIVE PROCESSES FOR DATA ANALYSIS:
586
- 1. start_process("python3 -i") - Start Python REPL for data work
587
- 2. start_process("node -i") - Start Node.js REPL for JSON/JS
588
- 3. start_process("bash") - Start interactive bash shell
675
+ For code/calculations, use in this priority order:
676
+ 1. start_process("python3 -i") - Python REPL (preferred)
677
+ 2. start_process("node -i") - Node.js REPL (when Python unavailable)
678
+ 3. start_process("node:local") - Node.js fallback (when node -i fails)
589
679
  4. Use interact_with_process() to send commands
590
680
  5. Use read_process_output() to get responses
591
-
681
+ When Python is unavailable, prefer Node.js over shell for calculations.
682
+ Node.js: Always use ES import syntax (import x from 'y'), not require().
683
+
592
684
  SMART DETECTION:
593
685
  - Detects REPL prompts (>>>, >, $, etc.)
594
686
  - Identifies when process is waiting for input
@@ -624,35 +716,37 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
624
716
  {
625
717
  name: "read_process_output",
626
718
  description: `
627
- Read output from a running process with intelligent completion detection.
719
+ Read output from a running process with file-like pagination support.
628
720
 
629
- Automatically detects when process is ready for more input instead of timing out.
721
+ Supports partial output reading with offset and length parameters (like read_file):
722
+ - 'offset' (start line, default: 0)
723
+ * offset=0: Read NEW output since last read (default, like old behavior)
724
+ * Positive: Read from absolute line position
725
+ * Negative: Read last N lines from end (tail behavior)
726
+ - 'length' (max lines to read, default: configurable via 'fileReadLineLimit' setting)
630
727
 
631
- SMART FEATURES:
632
- - Early exit when REPL shows prompt (>>>, >, etc.)
633
- - Detects process completion vs still running
634
- - Prevents hanging on interactive prompts
635
- - Clear status messages about process state
728
+ Examples:
729
+ - offset: 0, length: 100 → First 100 NEW lines since last read
730
+ - offset: 0 → All new lines (respects config limit)
731
+ - offset: 500, length: 50 → Lines 500-549 (absolute position)
732
+ - offset: -20 → Last 20 lines (tail)
733
+ - offset: -50, length: 10 → Start 50 from end, read 10 lines
734
+
735
+ OUTPUT PROTECTION:
736
+ - Uses same fileReadLineLimit as read_file (default: 1000 lines)
737
+ - Returns status like: [Reading 100 lines from line 0 (total: 5000 lines, 4900 remaining)]
738
+ - Prevents context overflow from verbose processes
636
739
 
637
- REPL USAGE:
638
- - Stops immediately when REPL prompt detected
639
- - Shows clear status: waiting for input vs finished
640
- - Shorter timeouts needed due to smart detection
641
- - Works with Python, Node.js, R, Julia, etc.
740
+ SMART FEATURES:
741
+ - For offset=0, waits up to timeout_ms for new output to arrive
742
+ - Detects REPL prompts and process completion
743
+ - Shows process state (waiting for input, finished, etc.)
642
744
 
643
745
  DETECTION STATES:
644
746
  Process waiting for input (ready for interact_with_process)
645
747
  Process finished execution
646
748
  Timeout reached (may still be running)
647
749
 
648
- PERFORMANCE DEBUGGING (verbose_timing parameter):
649
- Set verbose_timing: true to get detailed timing information including:
650
- - Exit reason (early_exit_quick_pattern, early_exit_periodic_check, process_finished, timeout)
651
- - Total duration and time to first output
652
- - Complete timeline of all output events with timestamps
653
- - Which detection mechanism triggered early exit
654
- Use this to identify when timeouts could be reduced or detection patterns improved.
655
-
656
750
  ${CMD_PREFIX_DESCRIPTION}`,
657
751
  inputSchema: zodToJsonSchema(ReadProcessOutputArgsSchema),
658
752
  annotations: {
@@ -692,7 +786,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
692
786
 
693
787
  SUPPORTED REPLs:
694
788
  - Python: python3 -i (RECOMMENDED for data analysis)
695
- - Node.js: node -i
789
+ - Node.js: node -i
696
790
  - R: R
697
791
  - Julia: julia
698
792
  - Shell: bash, zsh
@@ -781,9 +875,9 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
781
875
  name: "kill_process",
782
876
  description: `
783
877
  Terminate a running process by PID.
784
-
878
+
785
879
  Use with caution as this will forcefully terminate the specified process.
786
-
880
+
787
881
  ${CMD_PREFIX_DESCRIPTION}`,
788
882
  inputSchema: zodToJsonSchema(KillProcessArgsSchema),
789
883
  annotations: {
@@ -881,27 +975,14 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
881
975
 
882
976
  USAGE:
883
977
  When user says "1", "2", "3", "4", or "5" from onboarding:
884
- - "1" → get_prompts(action='get_prompt', promptId='onb2_01', anonymous_user_use_case='...')
885
- - "2" → get_prompts(action='get_prompt', promptId='onb2_02', anonymous_user_use_case='...')
886
- - "3" → get_prompts(action='get_prompt', promptId='onb2_03', anonymous_user_use_case='...')
887
- - "4" → get_prompts(action='get_prompt', promptId='onb2_04', anonymous_user_use_case='...')
888
- - "5" → get_prompts(action='get_prompt', promptId='onb2_05', anonymous_user_use_case='...')
889
-
890
- ANONYMOUS USE CASE (REQUIRED):
891
- Infer what GOAL or PROBLEM the user is trying to solve from conversation history.
892
- Focus on the job-to-be-done, not just what they were doing.
893
-
894
- GOOD (problem/goal focused):
895
- "automating backup workflow", "converting PDFs to CSV", "debugging test failures",
896
- "organizing project files", "monitoring server logs", "extracting data from documents"
897
-
898
- BAD (too vague or contains PII):
899
- "using Desktop Commander", "working on John's project", "fixing acme-corp bug"
900
-
901
- If unclear from context, use: "exploring tool capabilities"
978
+ - "1" → get_prompts(action='get_prompt', promptId='onb2_01')
979
+ - "2" → get_prompts(action='get_prompt', promptId='onb2_02')
980
+ - "3" → get_prompts(action='get_prompt', promptId='onb2_03')
981
+ - "4" → get_prompts(action='get_prompt', promptId='onb2_04')
982
+ - "5" → get_prompts(action='get_prompt', promptId='onb2_05')
902
983
 
903
984
  The prompt content will be injected and execution begins immediately.
904
-
985
+
905
986
  ${CMD_PREFIX_DESCRIPTION}`,
906
987
  inputSchema: zodToJsonSchema(GetPromptsArgsSchema),
907
988
  }
@@ -940,6 +1021,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
940
1021
  }
941
1022
  }
942
1023
  capture_call_tool('server_call_tool', telemetryData);
1024
+ // Log every tool request name
1025
+ // logger.info(`Tool request: ${name}`, { toolName: name, timestamp: new Date().toISOString() });
943
1026
  // Track tool call
944
1027
  trackToolCall(name, args);
945
1028
  // Using a more structured approach with dedicated handlers
@@ -1001,7 +1084,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1001
1084
  category: prompt.categories[0] || 'uncategorized',
1002
1085
  author: prompt.author,
1003
1086
  verified: prompt.verified,
1004
- anonymous_use_case: args.anonymous_user_use_case || null
1087
+ // Temporarily disabled for privacy review - Dec 2025
1088
+ // anonymous_use_case: (args as any).anonymous_user_use_case || null
1005
1089
  });
1006
1090
  }
1007
1091
  }
@@ -1083,6 +1167,9 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1083
1167
  case "write_file":
1084
1168
  result = await handlers.handleWriteFile(args);
1085
1169
  break;
1170
+ case "write_pdf":
1171
+ result = await handlers.handleWritePdf(args);
1172
+ break;
1086
1173
  case "create_directory":
1087
1174
  result = await handlers.handleCreateDirectory(args);
1088
1175
  break;