mcp-web-print-pdf 0.2.0 → 0.2.1
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 +4 -3
- package/README_EN.md +5 -3
- package/package.json +3 -2
- package/src/options.js +3 -3
- package/src/server.js +9 -9
package/README.md
CHANGED
|
@@ -214,8 +214,8 @@ Roo Code / Kilo Code 是 Cline 的分叉,配置结构相同,只是文件路
|
|
|
214
214
|
|
|
215
215
|
### 打印
|
|
216
216
|
|
|
217
|
-
所有打印工具默认 `dry_run:
|
|
218
|
-
(或 `extra_options.action: "
|
|
217
|
+
所有打印工具默认 `dry_run: false`:直接出纸;要只渲染预览请显式传 `dry_run: true`
|
|
218
|
+
(或 `extra_options.action: "preview"`)。默认会真的用纸,请先确认打印机和纸张。
|
|
219
219
|
|
|
220
220
|
> 不传 `paper_format` 时,PDF 渲染默认用 A4,但打印阶段会沿用客户端默认打印机的纸张。
|
|
221
221
|
> 要固定纸张(比如热敏 80mm、面单 100×150),请显式传 `paper_format` / `pdf_options`。
|
|
@@ -262,7 +262,7 @@ Roo Code / Kilo Code 是 Cline 的分叉,配置结构相同,只是文件路
|
|
|
262
262
|
| `pdf_options` | `pdfOptions` | 排版成 PDF:纸张、边距、页眉页脚、背景、水印、页码… |
|
|
263
263
|
| `print_options` | `printOptions` | 投递打印机:打印机名、份数、单双面、缩放、纸盒、热敏锐化… |
|
|
264
264
|
| `extra_options` | `extraOptions` | `action`、`requestTimeout`、`cookies`、`httpHeaders`、`localStorages`… |
|
|
265
|
-
| `dry_run` | — |
|
|
265
|
+
| `dry_run` | — | 默认出纸;`true` 只预览;显式 `action` 优先 |
|
|
266
266
|
| `paper_format` | — | 便捷参数,等价于 `print_options.paperFormat` |
|
|
267
267
|
| `printer_name` | — | 便捷参数,等价于 `print_options.printerName` |
|
|
268
268
|
| `copies` | — | 便捷参数,等价于 `print_options.copies` |
|
|
@@ -302,6 +302,7 @@ Roo Code / Kilo Code 是 Cline 的分叉,配置结构相同,只是文件路
|
|
|
302
302
|
"tool": "printHtml",
|
|
303
303
|
"arguments": {
|
|
304
304
|
"html": "<h1>发票 #12345</h1><p>合计 ¥99.99</p>",
|
|
305
|
+
"dry_run": true,
|
|
305
306
|
"paper_format": "A4",
|
|
306
307
|
"pdf_options": { "printBackground": true, "margin": { "top": "10mm", "bottom": "10mm" } }
|
|
307
308
|
}
|
package/README_EN.md
CHANGED
|
@@ -221,8 +221,9 @@ file by path" method.
|
|
|
221
221
|
|
|
222
222
|
### Printing
|
|
223
223
|
|
|
224
|
-
Every printing tool defaults to `dry_run:
|
|
225
|
-
|
|
224
|
+
Every printing tool defaults to `dry_run: false`: it actually prints. To render a preview only, pass
|
|
225
|
+
`dry_run: true` explicitly (or `extra_options.action: "preview"`). The default really uses paper —
|
|
226
|
+
check the printer and paper first.
|
|
226
227
|
|
|
227
228
|
> When `paper_format` is omitted, the PDF is rendered at A4 but the print stage uses the client's
|
|
228
229
|
> default printer paper. To pin the paper (80mm thermal, 100×150 labels, etc.), pass `paper_format` /
|
|
@@ -271,7 +272,7 @@ All printing tools share one parameter set, mirroring the upstream four argument
|
|
|
271
272
|
| `pdf_options` | `pdfOptions` | PDF layout: paper, margins, header/footer, background, watermark, page numbers… |
|
|
272
273
|
| `print_options` | `printOptions` | Printer delivery: printer name, copies, duplex, scaling, tray, thermal sharpening… |
|
|
273
274
|
| `extra_options` | `extraOptions` | `action`, `requestTimeout`, `cookies`, `httpHeaders`, `localStorages`… |
|
|
274
|
-
| `dry_run` | — |
|
|
275
|
+
| `dry_run` | — | Prints by default; `true` previews only; an explicit `action` wins |
|
|
275
276
|
| `paper_format` | — | Convenience for `print_options.paperFormat` |
|
|
276
277
|
| `printer_name` | — | Convenience for `print_options.printerName` |
|
|
277
278
|
| `copies` | — | Convenience for `print_options.copies` |
|
|
@@ -315,6 +316,7 @@ Preview an A4 invoice (no paper):
|
|
|
315
316
|
"tool": "printHtml",
|
|
316
317
|
"arguments": {
|
|
317
318
|
"html": "<h1>Invoice #12345</h1><p>Total ¥99.99</p>",
|
|
319
|
+
"dry_run": true,
|
|
318
320
|
"paper_format": "A4",
|
|
319
321
|
"pdf_options": { "printBackground": true, "margin": { "top": "10mm", "bottom": "10mm" } }
|
|
320
322
|
}
|
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.1",
|
|
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"
|
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,
|