mcp-web-print-pdf 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -4
- package/README_EN.md +26 -4
- package/package.json +4 -3
- package/src/options.js +3 -3
- package/src/server.js +9 -9
package/README.md
CHANGED
|
@@ -8,10 +8,21 @@
|
|
|
8
8
|
`ws://127.0.0.1:16794/websocket/standard` 再加一个客户端,并把 `web-print-pdf@2.x` 的公开 API
|
|
9
9
|
一对一映射成 MCP 工具。
|
|
10
10
|
|
|
11
|
+
- 官网:<https://webprintpdf.com/>
|
|
12
|
+
- 底层 npm 包:[web-print-pdf](https://www.npmjs.com/package/web-print-pdf)
|
|
13
|
+
- 文档:<https://webprintpdf.com/docs/>
|
|
14
|
+
|
|
11
15
|
```
|
|
12
16
|
Claude / dsh ──stdio──> mcp-web-print-pdf ──ws──> Web打印专家客户端 ──> 打印机
|
|
13
17
|
```
|
|
14
18
|
|
|
19
|
+
## 前置条件
|
|
20
|
+
|
|
21
|
+
- 本机安装并启动 [Web打印专家客户端](https://webprintpdf.com/downloadApp/)(Windows 10/11、macOS 11+、Linux / 银河麒麟 / 统信 UOS)
|
|
22
|
+
- 客户端默认监听 `ws://127.0.0.1:16794/websocket/standard`
|
|
23
|
+
- 不需要改客户端或前端代码;本 MCP 只是把 [web-print-pdf](https://www.npmjs.com/package/web-print-pdf) 的公开 API 映射成 MCP 工具
|
|
24
|
+
- MCP 接入指南:<https://webprintpdf.com/docs/mcp-print/>
|
|
25
|
+
|
|
15
26
|
## 安装
|
|
16
27
|
|
|
17
28
|
宿主会自动通过 `npx -y mcp-web-print-pdf` 拉取,不需要全局安装。
|
|
@@ -214,8 +225,8 @@ Roo Code / Kilo Code 是 Cline 的分叉,配置结构相同,只是文件路
|
|
|
214
225
|
|
|
215
226
|
### 打印
|
|
216
227
|
|
|
217
|
-
所有打印工具默认 `dry_run:
|
|
218
|
-
(或 `extra_options.action: "
|
|
228
|
+
所有打印工具默认 `dry_run: false`:直接出纸;要只渲染预览请显式传 `dry_run: true`
|
|
229
|
+
(或 `extra_options.action: "preview"`)。默认会真的用纸,请先确认打印机和纸张。
|
|
219
230
|
|
|
220
231
|
> 不传 `paper_format` 时,PDF 渲染默认用 A4,但打印阶段会沿用客户端默认打印机的纸张。
|
|
221
232
|
> 要固定纸张(比如热敏 80mm、面单 100×150),请显式传 `paper_format` / `pdf_options`。
|
|
@@ -262,7 +273,7 @@ Roo Code / Kilo Code 是 Cline 的分叉,配置结构相同,只是文件路
|
|
|
262
273
|
| `pdf_options` | `pdfOptions` | 排版成 PDF:纸张、边距、页眉页脚、背景、水印、页码… |
|
|
263
274
|
| `print_options` | `printOptions` | 投递打印机:打印机名、份数、单双面、缩放、纸盒、热敏锐化… |
|
|
264
275
|
| `extra_options` | `extraOptions` | `action`、`requestTimeout`、`cookies`、`httpHeaders`、`localStorages`… |
|
|
265
|
-
| `dry_run` | — |
|
|
276
|
+
| `dry_run` | — | 默认出纸;`true` 只预览;显式 `action` 优先 |
|
|
266
277
|
| `paper_format` | — | 便捷参数,等价于 `print_options.paperFormat` |
|
|
267
278
|
| `printer_name` | — | 便捷参数,等价于 `print_options.printerName` |
|
|
268
279
|
| `copies` | — | 便捷参数,等价于 `print_options.copies` |
|
|
@@ -302,6 +313,7 @@ Roo Code / Kilo Code 是 Cline 的分叉,配置结构相同,只是文件路
|
|
|
302
313
|
"tool": "printHtml",
|
|
303
314
|
"arguments": {
|
|
304
315
|
"html": "<h1>发票 #12345</h1><p>合计 ¥99.99</p>",
|
|
316
|
+
"dry_run": true,
|
|
305
317
|
"paper_format": "A4",
|
|
306
318
|
"pdf_options": { "printBackground": true, "margin": { "top": "10mm", "bottom": "10mm" } }
|
|
307
319
|
}
|
|
@@ -373,7 +385,7 @@ MCP 的 stdio 通道单条消息默认上限 **10MB**(SDK 的 `ReadBuffer`)
|
|
|
373
385
|
客户端,绕开 MCP 的消息上限。
|
|
374
386
|
- 也可以先把文件挂到 HTTP 地址,用 `printPdfByUrl` / `printImageByUrl` / `printHtmlByUrl`。
|
|
375
387
|
|
|
376
|
-
## 与
|
|
388
|
+
## 与 [web-print-pdf@2.1.9](https://www.npmjs.com/package/web-print-pdf) 的覆盖对照
|
|
377
389
|
|
|
378
390
|
| 上游公开 API | 本 MCP |
|
|
379
391
|
|---|---|
|
|
@@ -436,6 +448,15 @@ npx @modelcontextprotocol/inspector node bin/mcp.js
|
|
|
436
448
|
- 参数与消息结构按 `ElctronPrintWeb`(客户端 1.0.9)源码校准:`batchPrint` 任务用 `data` 字段,
|
|
437
449
|
不是 `web-print-pdf` README 示例里的 `content` / `url` / `base64`。
|
|
438
450
|
|
|
451
|
+
## 相关链接
|
|
452
|
+
|
|
453
|
+
- 官网:<https://webprintpdf.com/>
|
|
454
|
+
- 文档:<https://webprintpdf.com/docs/>
|
|
455
|
+
- MCP 接入指南:<https://webprintpdf.com/docs/mcp-print/>
|
|
456
|
+
- 客户端下载:<https://webprintpdf.com/downloadApp/>
|
|
457
|
+
- web-print-pdf(npm):<https://www.npmjs.com/package/web-print-pdf>
|
|
458
|
+
- 本仓库:<https://github.com/weixiaoyi/mcp-web-print-pdf>
|
|
459
|
+
|
|
439
460
|
## License
|
|
440
461
|
|
|
441
462
|
MIT
|
package/README_EN.md
CHANGED
|
@@ -8,10 +8,21 @@ It does **not** modify the Web Print Expert client or the `web-print-pdf` browse
|
|
|
8
8
|
adds another client to the existing `ws://127.0.0.1:16794/websocket/standard` endpoint and maps the
|
|
9
9
|
public `web-print-pdf@2.x` API one-to-one onto MCP tools.
|
|
10
10
|
|
|
11
|
+
- Website: <https://webprintpdf.com/>
|
|
12
|
+
- Underlying npm package: [web-print-pdf](https://www.npmjs.com/package/web-print-pdf)
|
|
13
|
+
- Docs: <https://webprintpdf.com/docs/>
|
|
14
|
+
|
|
11
15
|
```
|
|
12
16
|
Claude / dsh ──stdio──> mcp-web-print-pdf ──ws──> Web Print Expert client ──> printer
|
|
13
17
|
```
|
|
14
18
|
|
|
19
|
+
## Prerequisites
|
|
20
|
+
|
|
21
|
+
- Install and start the [Web Print Expert client](https://webprintpdf.com/downloadApp/) (Windows 10/11, macOS 11+, Linux / Kylin / UOS)
|
|
22
|
+
- The client listens on `ws://127.0.0.1:16794/websocket/standard` by default
|
|
23
|
+
- No changes to the client or your frontend code; this MCP just maps the public [web-print-pdf](https://www.npmjs.com/package/web-print-pdf) API onto MCP tools
|
|
24
|
+
- MCP guide: <https://webprintpdf.com/docs/mcp-print/>
|
|
25
|
+
|
|
15
26
|
## Installation
|
|
16
27
|
|
|
17
28
|
Hosts fetch it automatically via `npx -y mcp-web-print-pdf`; no global install is required.
|
|
@@ -221,8 +232,9 @@ file by path" method.
|
|
|
221
232
|
|
|
222
233
|
### Printing
|
|
223
234
|
|
|
224
|
-
Every printing tool defaults to `dry_run:
|
|
225
|
-
|
|
235
|
+
Every printing tool defaults to `dry_run: false`: it actually prints. To render a preview only, pass
|
|
236
|
+
`dry_run: true` explicitly (or `extra_options.action: "preview"`). The default really uses paper —
|
|
237
|
+
check the printer and paper first.
|
|
226
238
|
|
|
227
239
|
> When `paper_format` is omitted, the PDF is rendered at A4 but the print stage uses the client's
|
|
228
240
|
> default printer paper. To pin the paper (80mm thermal, 100×150 labels, etc.), pass `paper_format` /
|
|
@@ -271,7 +283,7 @@ All printing tools share one parameter set, mirroring the upstream four argument
|
|
|
271
283
|
| `pdf_options` | `pdfOptions` | PDF layout: paper, margins, header/footer, background, watermark, page numbers… |
|
|
272
284
|
| `print_options` | `printOptions` | Printer delivery: printer name, copies, duplex, scaling, tray, thermal sharpening… |
|
|
273
285
|
| `extra_options` | `extraOptions` | `action`, `requestTimeout`, `cookies`, `httpHeaders`, `localStorages`… |
|
|
274
|
-
| `dry_run` | — |
|
|
286
|
+
| `dry_run` | — | Prints by default; `true` previews only; an explicit `action` wins |
|
|
275
287
|
| `paper_format` | — | Convenience for `print_options.paperFormat` |
|
|
276
288
|
| `printer_name` | — | Convenience for `print_options.printerName` |
|
|
277
289
|
| `copies` | — | Convenience for `print_options.copies` |
|
|
@@ -315,6 +327,7 @@ Preview an A4 invoice (no paper):
|
|
|
315
327
|
"tool": "printHtml",
|
|
316
328
|
"arguments": {
|
|
317
329
|
"html": "<h1>Invoice #12345</h1><p>Total ¥99.99</p>",
|
|
330
|
+
"dry_run": true,
|
|
318
331
|
"paper_format": "A4",
|
|
319
332
|
"pdf_options": { "printBackground": true, "margin": { "top": "10mm", "bottom": "10mm" } }
|
|
320
333
|
}
|
|
@@ -386,7 +399,7 @@ MCP's stdio channel has a default **10MB** per-message limit (the SDK's `ReadBuf
|
|
|
386
399
|
the client over WebSocket, bypassing the MCP message limit.
|
|
387
400
|
- Alternatively host the file over HTTP and use `printPdfByUrl` / `printImageByUrl` / `printHtmlByUrl`.
|
|
388
401
|
|
|
389
|
-
## Coverage vs
|
|
402
|
+
## Coverage vs [web-print-pdf@2.1.9](https://www.npmjs.com/package/web-print-pdf)
|
|
390
403
|
|
|
391
404
|
| Upstream public API | This MCP |
|
|
392
405
|
|---|---|
|
|
@@ -463,6 +476,15 @@ check that a preview appears.
|
|
|
463
476
|
`batchPrint` tasks use a `data` field, not the `content` / `url` / `base64` fields shown in the
|
|
464
477
|
`web-print-pdf` README examples.
|
|
465
478
|
|
|
479
|
+
## Links
|
|
480
|
+
|
|
481
|
+
- Website: <https://webprintpdf.com/>
|
|
482
|
+
- Docs: <https://webprintpdf.com/docs/>
|
|
483
|
+
- MCP guide: <https://webprintpdf.com/docs/mcp-print/>
|
|
484
|
+
- Client download: <https://webprintpdf.com/downloadApp/>
|
|
485
|
+
- web-print-pdf (npm): <https://www.npmjs.com/package/web-print-pdf>
|
|
486
|
+
- This repository: <https://github.com/weixiaoyi/mcp-web-print-pdf>
|
|
487
|
+
|
|
466
488
|
## License
|
|
467
489
|
|
|
468
490
|
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-web-print-pdf",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "MCP server for Web打印专家 / web-print-pdf — full API coverage: HTML, URL, PDF, image, batch printing to local printers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"scripts": {
|
|
16
16
|
"start": "node bin/mcp.js",
|
|
17
17
|
"mock": "node test/mock-server.js",
|
|
18
|
-
"smoke": "node test/smoke.js"
|
|
18
|
+
"smoke": "node test/smoke.js",
|
|
19
|
+
"test": "node --test test/options.test.js"
|
|
19
20
|
},
|
|
20
21
|
"engines": {
|
|
21
22
|
"node": ">=18"
|
|
@@ -37,7 +38,7 @@
|
|
|
37
38
|
"receipt",
|
|
38
39
|
"label"
|
|
39
40
|
],
|
|
40
|
-
"homepage": "https://
|
|
41
|
+
"homepage": "https://webprintpdf.com/",
|
|
41
42
|
"repository": {
|
|
42
43
|
"type": "git",
|
|
43
44
|
"url": "git+https://github.com/weixiaoyi/mcp-web-print-pdf.git"
|
package/src/options.js
CHANGED
|
@@ -153,8 +153,8 @@ export const printArgsShape = {
|
|
|
153
153
|
copies: z.number().int().min(1).max(999).optional().describe("便捷参数:份数"),
|
|
154
154
|
dry_run: z
|
|
155
155
|
.boolean()
|
|
156
|
-
.default(
|
|
157
|
-
.describe("
|
|
156
|
+
.default(false)
|
|
157
|
+
.describe("false(默认)= 真正出纸;true = 只渲染预览。显式 extra_options.action 优先于本项"),
|
|
158
158
|
};
|
|
159
159
|
|
|
160
160
|
/**
|
|
@@ -187,7 +187,7 @@ export function buildOptions(args = {}) {
|
|
|
187
187
|
printOptions.copies = args.copies;
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
const action = extraOptions.action || (args.dry_run ===
|
|
190
|
+
const action = extraOptions.action || (args.dry_run === true ? "preview" : "print");
|
|
191
191
|
extraOptions.action = action;
|
|
192
192
|
|
|
193
193
|
return { pdfOptions, printOptions, extraOptions, action };
|
package/src/server.js
CHANGED
|
@@ -213,7 +213,7 @@ export async function start() {
|
|
|
213
213
|
|
|
214
214
|
registerPrint(
|
|
215
215
|
"printHtml",
|
|
216
|
-
"把 HTML 字符串渲染成 PDF
|
|
216
|
+
"把 HTML 字符串渲染成 PDF 并打印。默认真正出纸;dry_run: true 才只渲染预览",
|
|
217
217
|
{ html: z.string().describe("完整页面或 HTML 片段") },
|
|
218
218
|
"printHtml",
|
|
219
219
|
({ html }) => ({ content: html })
|
|
@@ -221,7 +221,7 @@ export async function start() {
|
|
|
221
221
|
|
|
222
222
|
registerPrint(
|
|
223
223
|
"printHtmlByUrl",
|
|
224
|
-
"抓取一个网页并渲染成 PDF
|
|
224
|
+
"抓取一个网页并渲染成 PDF 打印。默认出纸;dry_run: true 只预览;登录态可用 extra_options.cookies / httpHeaders / localStorages 处理",
|
|
225
225
|
{ url: z.string().url().describe("网页 http(s) 地址") },
|
|
226
226
|
"printHtmlByUrl",
|
|
227
227
|
({ url }) => ({ url })
|
|
@@ -229,7 +229,7 @@ export async function start() {
|
|
|
229
229
|
|
|
230
230
|
registerPrint(
|
|
231
231
|
"printHtmlByBase64",
|
|
232
|
-
"把 Base64 编码的 HTML 渲染成 PDF
|
|
232
|
+
"把 Base64 编码的 HTML 渲染成 PDF 打印。默认出纸;dry_run: true 只预览",
|
|
233
233
|
{ base64: z.string().min(1).describe("HTML 的 base64,可带 data:text/html;base64, 前缀") },
|
|
234
234
|
"printHtmlByBase64",
|
|
235
235
|
({ base64 }) => ({ base64: stripDataUrl(base64) })
|
|
@@ -237,7 +237,7 @@ export async function start() {
|
|
|
237
237
|
|
|
238
238
|
registerPrint(
|
|
239
239
|
"printPdfByUrl",
|
|
240
|
-
"下载一个 PDF
|
|
240
|
+
"下载一个 PDF 链接并打印。默认出纸;dry_run: true 只预览",
|
|
241
241
|
{ url: z.string().url().describe("PDF 的 http(s) 地址") },
|
|
242
242
|
"printPdfByUrl",
|
|
243
243
|
({ url }) => ({ url })
|
|
@@ -245,7 +245,7 @@ export async function start() {
|
|
|
245
245
|
|
|
246
246
|
registerPrint(
|
|
247
247
|
"printPdfByBase64",
|
|
248
|
-
"把 Base64 编码的 PDF
|
|
248
|
+
"把 Base64 编码的 PDF 打印。默认出纸;dry_run: true 只预览",
|
|
249
249
|
{ base64: z.string().min(1).describe("PDF 的 base64,可带 data:application/pdf;base64, 前缀") },
|
|
250
250
|
"printPdfByBase64",
|
|
251
251
|
({ base64 }) => ({ base64: stripDataUrl(base64) })
|
|
@@ -253,7 +253,7 @@ export async function start() {
|
|
|
253
253
|
|
|
254
254
|
registerPrint(
|
|
255
255
|
"printImageByUrl",
|
|
256
|
-
"
|
|
256
|
+
"下载一张图片并打印。默认出纸;dry_run: true 只预览",
|
|
257
257
|
{ url: z.string().url().describe("图片的 http(s) 地址") },
|
|
258
258
|
"printImageByUrl",
|
|
259
259
|
({ url }) => ({ url })
|
|
@@ -261,7 +261,7 @@ export async function start() {
|
|
|
261
261
|
|
|
262
262
|
registerPrint(
|
|
263
263
|
"printImageByBase64",
|
|
264
|
-
"把 Base64
|
|
264
|
+
"把 Base64 编码的图片打印。默认出纸;dry_run: true 只预览;缺 data:image/...;base64, 前缀时会自动补",
|
|
265
265
|
{ base64: z.string().min(1).describe("图片的 base64;带不带 data:image/...;base64, 前缀都可以") },
|
|
266
266
|
"printImageByBase64",
|
|
267
267
|
({ base64 }) => ({ base64: toImageDataUrl(base64) })
|
|
@@ -269,7 +269,7 @@ export async function start() {
|
|
|
269
269
|
|
|
270
270
|
server.tool(
|
|
271
271
|
"printFile",
|
|
272
|
-
"打印本机文件:按扩展名自动选择 PDF / HTML /
|
|
272
|
+
"打印本机文件:按扩展名自动选择 PDF / HTML / 图片通道。默认出纸;dry_run: true 只预览",
|
|
273
273
|
{
|
|
274
274
|
path: z.string().min(1).describe("本机文件路径,绝对路径或相对当前工作目录"),
|
|
275
275
|
...printArgsShape,
|
|
@@ -291,7 +291,7 @@ export async function start() {
|
|
|
291
291
|
|
|
292
292
|
server.tool(
|
|
293
293
|
"batchPrint",
|
|
294
|
-
"一次提交多个打印任务(HTML / 网页 / PDF / 图片,URL 或 Base64
|
|
294
|
+
"一次提交多个打印任务(HTML / 网页 / PDF / 图片,URL 或 Base64 混合)。默认出纸;dry_run: true 只预览",
|
|
295
295
|
{
|
|
296
296
|
tasks: z.array(batchTaskSchema).min(1).describe("任务列表,每项含 type 与对应内容字段"),
|
|
297
297
|
...printArgsShape,
|