Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/mcp-server/src/utils/load-file-uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ export default async function loadFileUploads(
} catch (error) {
// "cannot find it" and "it ran and failed" send the operator to different places, and only the
// first is about the path they configured.
// The quoted name, not the whole message: a module whose own dependency is missing reports
// MODULE_NOT_FOUND too, with the resolved path in the require stack rather than as the subject.
const absent =
(error as NodeJS.ErrnoException)?.code === 'MODULE_NOT_FOUND' &&
String((error as Error)?.message).includes(resolved);
String((error as Error)?.message).includes(`'${resolved}'`);

throw withCause(
absent
Expand Down
10 changes: 10 additions & 0 deletions packages/mcp-server/test/utils/load-file-uploads.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ describe('loadFileUploads', () => {
});
});

it('blames the dependency, not the path, when the module requires something missing', async () => {
const file = writeModule(`require('@this/does-not-exist');`);

const error = (await loadFileUploads(file).catch((e: Error) => e)) as Error;

expect(error.message).toContain('failed while loading');
expect(error.message).toContain("Cannot find module '@this/does-not-exist'");
expect(error.message).not.toContain('was not found');
});

it('names the module and the resolved path when it cannot be found', async () => {
await expect(loadFileUploads('./does-not-exist.js')).rejects.toThrow(
/"\.\/does-not-exist\.js" was not found \(resolved to .+\)/,
Expand Down
Loading