fix(pdf-server): npx DOMMatrix crash + broken MCPB bundle (#584)
* fix(pdf-server): stub DOMMatrix/ImageData/Path2D for npx without @napi-rs/canvas
pdfjs-dist/legacy/build/pdf.mjs does `new DOMMatrix()` at module scope.
Its own polyfill loads @napi-rs/canvas (an optionalDependency), but npx
frequently misses the platform-native binary (npm/cli#4828), so the
server crashed on `npx @modelcontextprotocol/server-pdf --stdio`:
ReferenceError: DOMMatrix is not defined
at pdfjs-dist/legacy/build/pdf.mjs:17078
The server only uses pdfjs for text/metadata/form-field extraction —
never canvas rendering — so no-op stubs suffice and avoid shipping
~130MB of native binaries.
The polyfill is a separate ESM module kept --external in the bun bundle
so it executes before pdfjs's hoisted static import; inlined body code
would run too late.
Broken since 1.3.0 (#506). Thanks to Bryan Thompson for the analysis
and fix shape from the npm-to-mcpb pipeline.
* fix(pdf-server): MCPB bundle missing runtime deps + display_name with spaces
`mcpb pack` zips whatever is on disk; in this monorepo all runtime deps
are hoisted to root node_modules, so the published .mcpb shipped without
pdfjs-dist/ajv/express/etc. and crashed on import in Claude Desktop.
build-mcpb.mjs stages dist/ + manifest into a clean temp dir, runs a
non-workspace `npm install --omit=dev --omit=optional` (the new
DOMMatrix polyfill makes @napi-rs/canvas's ~130MB of native binaries
unnecessary), syncs manifest.version to package.json, then packs.
Result: 12.3MB / 38.8MB unpacked, full MCP handshake + tools/list pass.
Also rename display_name "PDF (By Anthropic)" → "pdf-viewer" — spaces
in display_name break MCP App UI rendering for MCPBs in Claude Desktop.
CI now smoke-tests the extracted bundle starts (`dist/index.js --stdio`
prints "Ready") so a deps-less bundle can't ship again.
* fix(pdf-server): list interact in MCPB manifest tools (was stale since #491)
This commit is contained in:
parent
68c58b60b7
commit
04fed524a9
1 changed files with 106 additions and 14 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"manifest_version": "0.3",
|
||||
"name": "@modelcontextprotocol/server-pdf",
|
||||
"display_name": "PDF (By Anthropic)",
|
||||
"display_name": "pdf-viewer",
|
||||
"version": "1.0.1",
|
||||
"description": "Read and interact with PDF files using an interactive viewer with search, navigation, and text extraction",
|
||||
"author": {
|
||||
|
|
@ -34,8 +34,8 @@
|
|||
"description": "Display an interactive PDF viewer with search and navigation"
|
||||
},
|
||||
{
|
||||
"name": "read_pdf_bytes",
|
||||
"description": "Read a range of bytes from a PDF file (max 512KB per request)"
|
||||
"name": "interact",
|
||||
"description": "Interact with a PDF viewer: annotate, navigate, search, extract text/screenshots, fill forms"
|
||||
}
|
||||
],
|
||||
"keywords": ["pdf", "documents", "viewer", "reading"],
|
||||
|
|
|
|||
Loading…
Reference in a new issue