Skip to content

Conversation

@ochafik
Copy link
Collaborator

@ochafik ochafik commented Jan 15, 2026

Summary

  • Fixes ENOENT: no such file or directory errors when running servers from npm packages
  • Fixes pdfjs-dist worker file not found error in pdf-server

Changes

1. DIST_DIR path resolution

When servers are compiled to dist/server.js and run via npx, import.meta.dirname already points to dist/, causing path.join(import.meta.dirname, "dist") to resolve to dist/dist/ which doesn't exist.

Updated all 20 example servers to detect whether running from TypeScript source or compiled JavaScript:

// Works both from source (server.ts) and compiled (dist/server.js)
const DIST_DIR = import.meta.filename.endsWith(".ts")
  ? path.join(import.meta.dirname, "dist")
  : import.meta.dirname;

2. pdf-server pdfjs-dist bundling fix

The pdf.worker.mjs file wasn't found when running from npm because bun bundled pdfjs-dist but didn't include the worker file.

By marking pdfjs-dist as external in the build, it uses the installed package from node_modules at runtime where the worker is available:

bun build server.ts --outdir dist --target node --external pdfjs-dist

Test plan

  • Build passes (npm run build:all)
  • E2E tests pass
  • Tested in a host + checked importing from another server works

🤖 Generated with Claude Code

When servers are compiled to dist/server.js and published to npm,
`import.meta.dirname` already points to dist/, so joining with "dist"
results in dist/dist/ which doesn't exist.

This fix detects whether we're running from TypeScript source or
compiled JavaScript and adjusts the path accordingly:
- From source (server.ts): use dist/ subdirectory
- From compiled (dist/server.js): use current directory

Fixes ENOENT errors like:
"ENOENT: no such file or directory, open '.../dist/dist/mcp-app.html'"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 15, 2026

Open in StackBlitz

@modelcontextprotocol/ext-apps

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/ext-apps@277

@modelcontextprotocol/server-basic-react

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-basic-react@277

@modelcontextprotocol/server-basic-vanillajs

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-basic-vanillajs@277

@modelcontextprotocol/server-budget-allocator

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-budget-allocator@277

@modelcontextprotocol/server-cohort-heatmap

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-cohort-heatmap@277

@modelcontextprotocol/server-customer-segmentation

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-customer-segmentation@277

@modelcontextprotocol/server-map

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-map@277

@modelcontextprotocol/server-pdf

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-pdf@277

@modelcontextprotocol/server-scenario-modeler

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-scenario-modeler@277

@modelcontextprotocol/server-shadertoy

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-shadertoy@277

@modelcontextprotocol/server-sheet-music

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-sheet-music@277

@modelcontextprotocol/server-system-monitor

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-system-monitor@277

@modelcontextprotocol/server-threejs

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-threejs@277

@modelcontextprotocol/server-transcript

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-transcript@277

@modelcontextprotocol/server-video-resource

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-video-resource@277

@modelcontextprotocol/server-wiki-explorer

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-wiki-explorer@277

commit: f5fb4d8

@ochafik ochafik marked this pull request as ready for review January 15, 2026 02:36
@ochafik ochafik requested review from jerome3o-anthropic and jonathanhefner and removed request for jonathanhefner January 15, 2026 02:36
The pdf.worker.mjs file wasn't being found when running from npm
because bun bundled pdfjs-dist but didn't include the worker file.

By marking pdfjs-dist as external, it uses the installed package
from node_modules at runtime where the worker is available.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ochafik
Copy link
Collaborator Author

ochafik commented Jan 15, 2026

config.json:

{
  "mcpServers": {
    "basic-react": {
      "command": "npx",
      "args": ["-y", "https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-basic-react@277", "--stdio"]
    },
    "basic-vanillajs": {
      "command": "npx",
      "args": ["-y", "https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-basic-vanillajs@277", "--stdio"]
    },
    "budget-allocator": {
      "command": "npx",
      "args": ["-y", "https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-budget-allocator@277", "--stdio"]
    },
    "cohort-heatmap": {
      "command": "npx",
      "args": ["-y", "https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-cohort-heatmap@277", "--stdio"]
    },
    "customer-segmentation": {
      "command": "npx",
      "args": ["-y", "https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-customer-segmentation@277", "--stdio"]
    },
    "map": {
      "command": "npx",
      "args": ["-y", "https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-map@277", "--stdio"]
    },
    "pdf": {
      "command": "npx",
      "args": ["-y", "https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-pdf@277", "--stdio"]
    },
    "scenario-modeler": {
      "command": "npx",
      "args": ["-y", "https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-scenario-modeler@277", "--stdio"]
    },
    "shadertoy": {
      "command": "npx",
      "args": ["-y", "https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-shadertoy@277", "--stdio"]
    },
    "sheet-music": {
      "command": "npx",
      "args": ["-y", "https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-sheet-music@277", "--stdio"]
    },
    "system-monitor": {
      "command": "npx",
      "args": ["-y", "https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-system-monitor@277", "--stdio"]
    },
    "threejs": {
      "command": "npx",
      "args": ["-y", "https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-threejs@277", "--stdio"]
    },
    "transcript": {
      "command": "npx",
      "args": ["-y", "https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-transcript@277", "--stdio"]
    },
    "video-resource": {
      "command": "npx",
      "args": ["-y", "https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-video-resource@277", "--stdio"]
    },
    "wiki-explorer": {
      "command": "npx",
      "args": ["-y", "https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-wiki-explorer@277", "--stdio"]
    }
  }
}

@ochafik ochafik merged commit 89a6845 into main Jan 15, 2026
17 of 19 checks passed
@ochafik ochafik deleted the fix/dist-dir-path-resolution branch January 15, 2026 13:01
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.

3 participants