Startup takes 25-90+s (causing MCP client connection timeouts) — eager-loads exceljs/pdf-lib/puppeteer on every launch regardless of use

Author: rgogosCreated Sep 17, 2026Updated Sep 17, 2026

Symptom

Desktop Commander's MCP initialize handshake intermittently takes long enough that connecting clients (30s/60s timeout windows) hit Request timed out / CONNECT_TIMEOUT and have to retry. On our Windows 11 machine (Node 24.14.0, DC v0.2.50, built from a local clone), time-to-response ranged ~25-90+ seconds across repeated runs.

Root cause

Measured directly (CPU sampling showed sustained ~80% single-core usage for ~25s straight, ruling out disk/AV/network waits — this is genuine synchronous computation, not I/O). Bisecting the import graph turned up four places where heavy, rarely-needed dependencies are loaded eagerly at process startup instead of on first actual use:

  1. src/utils/files/factory.ts statically imports ExcelFileHandler (pulls in exceljs, ~9.2s to import alone), PdfFileHandler, and DocxFileHandler unconditionally, even in sessions that never touch those file types.
  2. src/utils/files/index.ts separately re-exports ExcelFileHandler as a value, which forces the same eager load independent of #1.
  3. src/tools/filesystem.ts has its own separate static import of parsePdfToMarkdown/editPdf/parseMarkdownToPdf from ./pdf/index.js, bypassing the factory entirely.
  4. src/index.ts statically imports ensureChromeAvailable from tools/pdf/markdown.js (pulls in @puppeteer/browsers' Chrome-detection pipeline, ~6.8s), even though it's only ever called once, later, inside server.oninitialized.

Fix

Converted all four to dynamic import() calls, deferred until the corresponding file type or feature is actually used, with plain extension-check helpers so file-type routing doesn't need to load the handler module just to test a filename. No behavior change — verified getFileHandler() still routes .xlsx/.pdf/.docx/everything-else to the correct handler.

Result

Time-to-initialize-response dropped from ~25-90+s to a consistent ~8-10s on the same machine, same load.

Happy to open a PR with the actual diff if that's useful — the patch is small and isolated to the four files above.

Source: wonderwhy-er/DesktopCommanderMCP