Startup takes 25-90+s (causing MCP client connection timeouts) — eager-loads exceljs/pdf-lib/puppeteer on every launch regardless of use
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:
src/utils/files/factory.tsstatically importsExcelFileHandler(pulls inexceljs, ~9.2s to import alone),PdfFileHandler, andDocxFileHandlerunconditionally, even in sessions that never touch those file types.src/utils/files/index.tsseparately re-exportsExcelFileHandleras a value, which forces the same eager load independent of #1.src/tools/filesystem.tshas its own separate static import ofparsePdfToMarkdown/editPdf/parseMarkdownToPdffrom./pdf/index.js, bypassing the factory entirely.src/index.tsstatically importsensureChromeAvailablefromtools/pdf/markdown.js(pulls in@puppeteer/browsers' Chrome-detection pipeline, ~6.8s), even though it's only ever called once, later, insideserver.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