Skip to content

fix(mcp-server): blame the missing dependency, not the configured path - #1834

Open
Scra3 wants to merge 1 commit into
mainfrom
fix/mcp-storage-module-dependency
Open

fix(mcp-server): blame the missing dependency, not the configured path#1834
Scra3 wants to merge 1 commit into
mainfrom
fix/mcp-storage-module-dependency

Conversation

@Scra3

@Scra3 Scra3 commented Aug 18, 2026

Copy link
Copy Markdown
Member

Found while writing the S3 storage example for a customer about to configure FOREST_MCP_UPLOAD_STORAGE_MODULE: the module was on disk and correct, and the server said it was not there.

FOREST_MCP_UPLOAD_STORAGE_MODULE "/app/forest-upload-storage.js" was not found (resolved to /app/forest-upload-storage.js).

The real cause was @aws-sdk/client-s3 not being installed. Node raises MODULE_NOT_FOUND for that too, naming the dependency as the subject and carrying the module's own path in the require stack — so the old test, message.includes(resolved), matched on the stack line and reported the wrong diagnosis.

Matching the quoted name separates the two cases:

Situation Node's message Reported now
entry point missing Cannot find module '<resolved>' was not found (resolved to …)
its dependency missing Cannot find module '<dependency>' failed while loading: Cannot find module '<dependency>'

Verified in plain node against the built dist, both directions — the Jest resolver rewrites this message, so a test alone would not have proven it. Pinned by blames the dependency, not the path, when the module requires something missing, alongside the existing test for a genuinely absent path.

npm i @aws-sdk/client-s3 forgotten is the first thing anyone setting this variable will hit, and it was the one mistake the error actively mislabelled.

🤖 Generated with Claude Code

Note

Fix loadFileUploads to distinguish missing module from missing dependency in MODULE_NOT_FOUND errors

When require() throws a MODULE_NOT_FOUND error, it can mean either the target module itself is absent or a dependency of that module is missing. Previously, the function treated both cases as 'module not found'. It now checks whether the error message contains the resolved path wrapped in single quotes; only that case is classified as 'not found', while missing-dependency errors are classified as 'failed while loading'.

Macroscope summarized 701d045.

A storage module whose own dependency is not installed reported
FOREST_MCP_UPLOAD_STORAGE_MODULE "…" was not found, sending the operator to
check a path that was correct. Node raises MODULE_NOT_FOUND for that case too,
naming the dependency as the subject and carrying the module's own path in the
require stack, so matching the resolved path anywhere in the message caught it.

Matching the quoted name separates them: the entry point failing reads
Cannot find module '<resolved>', a missing dependency reads Cannot find
module '<dependency>'.

Found writing the S3 example for a customer: `npm i @aws-sdk/client-s3`
forgotten is the first thing anyone configuring this variable will hit.
@qltysh

qltysh Bot commented Aug 18, 2026

Copy link
Copy Markdown

Qlty


Coverage Impact

This PR will not change total coverage.

🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant