@bestimmaa/posprint-mcp 0.1.1 → 0.2.0
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 +11 -19
- package/dist/src/errors.js +1 -1
- package/dist/src/printing/posprintClient.js +1 -15
- package/dist/src/tools/printReceipt.js +3 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,42 +9,34 @@ The tool is intentionally named `print` so clients can map natural user phrasing
|
|
|
9
9
|
- Node.js 20+
|
|
10
10
|
- A printer reachable via a CUPS URI supported by `@bestimmaa/posprint`
|
|
11
11
|
|
|
12
|
-
## Run With npx
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
npx --package=@bestimmaa/posprint-mcp posprint-mcp
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Install
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
npm install -g @bestimmaa/posprint-mcp
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
After global installation, the package exposes a `posprint-mcp` binary on your PATH.
|
|
25
|
-
|
|
26
12
|
## MCP Client Configuration
|
|
27
13
|
|
|
28
|
-
|
|
14
|
+
Add this to your MCP client config. No separate installation step is required — `npx` fetches the package on first run.
|
|
29
15
|
|
|
30
16
|
```json
|
|
31
17
|
{
|
|
32
18
|
"mcpServers": {
|
|
33
19
|
"posprint": {
|
|
34
|
-
"command": "
|
|
20
|
+
"command": "npx",
|
|
21
|
+
"args": ["-y", "@bestimmaa/posprint-mcp"]
|
|
35
22
|
}
|
|
36
23
|
}
|
|
37
24
|
}
|
|
38
25
|
```
|
|
39
26
|
|
|
40
|
-
|
|
27
|
+
## Global Install (optional)
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install -g @bestimmaa/posprint-mcp
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
After global installation, you can use the shorter form in your MCP client config:
|
|
41
34
|
|
|
42
35
|
```json
|
|
43
36
|
{
|
|
44
37
|
"mcpServers": {
|
|
45
38
|
"posprint": {
|
|
46
|
-
"command": "
|
|
47
|
-
"args": ["--yes", "--package=@bestimmaa/posprint-mcp", "posprint-mcp"]
|
|
39
|
+
"command": "posprint-mcp"
|
|
48
40
|
}
|
|
49
41
|
}
|
|
50
42
|
}
|
package/dist/src/errors.js
CHANGED
|
@@ -12,7 +12,7 @@ export function mapUnknownError(error) {
|
|
|
12
12
|
if (error instanceof AppError) {
|
|
13
13
|
return error;
|
|
14
14
|
}
|
|
15
|
-
if (error instanceof Error && /
|
|
15
|
+
if (error instanceof Error && /time(?:out|d\s+out)/i.test(error.message)) {
|
|
16
16
|
return new AppError("TIMEOUT", "Printing timed out", { cause: error.message });
|
|
17
17
|
}
|
|
18
18
|
return new AppError("UNKNOWN_ERROR", "Unexpected printing failure", {
|
|
@@ -1,25 +1,11 @@
|
|
|
1
1
|
import posprint from "@bestimmaa/posprint";
|
|
2
2
|
const { markdownToEscpos, printRawToPrinterUri } = posprint;
|
|
3
|
-
function withTimeout(promise, timeoutMs) {
|
|
4
|
-
return new Promise((resolve, reject) => {
|
|
5
|
-
const timer = setTimeout(() => reject(new Error(`print timeout after ${timeoutMs}ms`)), timeoutMs);
|
|
6
|
-
promise
|
|
7
|
-
.then((value) => {
|
|
8
|
-
clearTimeout(timer);
|
|
9
|
-
resolve(value);
|
|
10
|
-
})
|
|
11
|
-
.catch((error) => {
|
|
12
|
-
clearTimeout(timer);
|
|
13
|
-
reject(error);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
3
|
export async function printMarkdown(params) {
|
|
18
4
|
const { printerUri, markdown, copies = 1, timeoutMs = 15_000, charsPerLine = 42 } = params;
|
|
19
5
|
const escpos = markdownToEscpos(markdown, { charsPerLine });
|
|
20
6
|
const payload = Buffer.from(escpos);
|
|
21
7
|
for (let i = 0; i < copies; i += 1) {
|
|
22
|
-
await
|
|
8
|
+
await printRawToPrinterUri(printerUri, payload, { timeoutMs });
|
|
23
9
|
}
|
|
24
10
|
return {};
|
|
25
11
|
}
|
|
@@ -13,8 +13,10 @@ function buildSnippet(markdown, lineCount = PREVIEW_LINE_COUNT) {
|
|
|
13
13
|
}
|
|
14
14
|
export async function handlePrintReceipt(input) {
|
|
15
15
|
const start = Date.now();
|
|
16
|
+
let printerUri;
|
|
16
17
|
try {
|
|
17
18
|
const parsed = parsePrintReceiptInput(input);
|
|
19
|
+
printerUri = parsed.printerUri;
|
|
18
20
|
if (parsed.mode === "preview") {
|
|
19
21
|
const lineCount = getLineCount(parsed.markdown);
|
|
20
22
|
const confirmationToken = createConfirmationToken({
|
|
@@ -71,7 +73,7 @@ export async function handlePrintReceipt(input) {
|
|
|
71
73
|
"UNSUPPORTED_SCHEME" === error.code ||
|
|
72
74
|
"UNSUPPORTED_PATH" === error.code)) {
|
|
73
75
|
throw new AppError("VALIDATION_ERROR", error.message, {
|
|
74
|
-
printerUri
|
|
76
|
+
printerUri
|
|
75
77
|
});
|
|
76
78
|
}
|
|
77
79
|
const mapped = mapUnknownError(error);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bestimmaa/posprint-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "MCP server for printing markdown receipts on POS printers.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
32
|
-
"
|
|
32
|
+
"prepare": "npm run build",
|
|
33
33
|
"start": "node dist/src/cli.js",
|
|
34
34
|
"dev": "tsx src/cli.ts",
|
|
35
35
|
"test": "vitest run --passWithNoTests",
|