diff --git a/packages/mcp-server/src/utils/load-file-uploads.ts b/packages/mcp-server/src/utils/load-file-uploads.ts index 97507f0db6..a902696438 100644 --- a/packages/mcp-server/src/utils/load-file-uploads.ts +++ b/packages/mcp-server/src/utils/load-file-uploads.ts @@ -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 diff --git a/packages/mcp-server/test/utils/load-file-uploads.test.ts b/packages/mcp-server/test/utils/load-file-uploads.test.ts index 59930c0503..8eec8107c2 100644 --- a/packages/mcp-server/test/utils/load-file-uploads.test.ts +++ b/packages/mcp-server/test/utils/load-file-uploads.test.ts @@ -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 .+\)/,