pretext-pdf-mcp 1.0.6 → 1.0.7
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/CHANGELOG.md +62 -0
- package/LICENSE +21 -0
- package/dist/index.js +68 -12
- package/package.json +8 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to pretext-pdf-mcp are documented here.
|
|
4
|
+
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## [1.0.7] — 2026-04-13
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **Critical: Version mismatch** — Hardcoded server version (1.0.0) didn't match package.json (1.0.6). Now correctly reports 1.0.7.
|
|
13
|
+
- **Critical: Unsafe type casting in API endpoint** — Added `validatePdfDocumentInput()` to reject null/undefined/non-object inputs before calling `render()`. Previously would pass invalid types and throw cryptic errors.
|
|
14
|
+
- **High: Inconsistent error categorization** — Added `isClientError()` to distinguish client validation errors (HTTP 400) from server errors (HTTP 500). Error responses now include `code` field for debugging.
|
|
15
|
+
- **Medium: MAX_BODY limit too small** — Increased from 100 KB to 500 KB on `/api/generate` to support PDFs with images, rich formatting, and v0.5.1+ features. Now consistent with `/mcp` endpoint.
|
|
16
|
+
- **High: Missing input validation** — `/api/generate` now validates `body.data` is an object before calling `render()`, preventing silent type coercion failures.
|
|
17
|
+
- **Low: Missing limit documentation** — Added detailed comments explaining the 500 KB limit rationale on both endpoints.
|
|
18
|
+
|
|
19
|
+
### Test Coverage
|
|
20
|
+
|
|
21
|
+
- pretext-pdf: 442/442 tests passing
|
|
22
|
+
- pretext-pdf-mcp: 14/14 tests passing
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## [1.0.6] — 2026-04-13
|
|
27
|
+
|
|
28
|
+
### Security
|
|
29
|
+
- Per-chunk size enforcement on both HTTP endpoints (`/api/generate` 100KB, `/mcp` 500KB).
|
|
30
|
+
Previously the full request body was buffered before the size check, allowing memory exhaustion via large payloads.
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
- Bumped `pretext-pdf` dependency to `^0.5.0` to pick up security hardening, CJK/Thai i18n,
|
|
34
|
+
validation improvements, `defaultParagraphStyle`, per-section headers/footers, and tabular numbers.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## [1.0.5] — 2026-04-09
|
|
39
|
+
|
|
40
|
+
### Added
|
|
41
|
+
- Live demo at https://himaan1998y.github.io/pretext-pdf-mcp/
|
|
42
|
+
- StackBlitz playground link in README
|
|
43
|
+
- Smithery registry integration (`https://pretext-pdf.run.tools`)
|
|
44
|
+
- `generate_invoice` tool: GST-aware invoices with INR/USD/EUR/GBP support
|
|
45
|
+
- `generate_report` tool: multi-section reports with optional TOC, tables, and callouts
|
|
46
|
+
- `list_element_types` tool: returns a markdown reference of all 16 element types
|
|
47
|
+
- Docker support via `Dockerfile`
|
|
48
|
+
- Claude Desktop configuration documented in README
|
|
49
|
+
|
|
50
|
+
### Changed
|
|
51
|
+
- HTTP server mode: `PORT` env var enables REST API alongside stdio MCP transport
|
|
52
|
+
- Tool descriptions expanded for better LLM comprehension
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## [1.0.0] — 2026-04-08
|
|
57
|
+
|
|
58
|
+
### Added
|
|
59
|
+
- Initial release
|
|
60
|
+
- `generate_pdf` tool: full `PdfDocument` JSON → Base64 PDF
|
|
61
|
+
- Stdio MCP transport (compatible with Claude Desktop, Cursor, Windsurf)
|
|
62
|
+
- HTTP transport for stateless `/mcp` endpoint
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Himanshu Jain
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.js
CHANGED
|
@@ -2,12 +2,46 @@
|
|
|
2
2
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
3
3
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
4
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
+
import { PretextPdfError } from 'pretext-pdf';
|
|
5
6
|
import { generatePdfTool } from './tools/generate-pdf.js';
|
|
6
7
|
import { generateInvoiceTool } from './tools/generate-invoice.js';
|
|
7
8
|
import { generateReportTool } from './tools/generate-report.js';
|
|
8
9
|
import { listElementsTool } from './tools/list-elements.js';
|
|
10
|
+
// ─── Input Validation ─────────────────────────────────────────────────────────
|
|
11
|
+
/**
|
|
12
|
+
* Validate that body.data is a plain object (minimal type guard).
|
|
13
|
+
* Prevents obvious type errors before calling render().
|
|
14
|
+
*/
|
|
15
|
+
function validatePdfDocumentInput(data) {
|
|
16
|
+
if (data === null || data === undefined) {
|
|
17
|
+
throw new PretextPdfError('VALIDATION_ERROR', 'Request body.data is required and cannot be null or undefined');
|
|
18
|
+
}
|
|
19
|
+
if (typeof data !== 'object' || Array.isArray(data)) {
|
|
20
|
+
throw new PretextPdfError('VALIDATION_ERROR', `Request body.data must be an object, received ${typeof data}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Categorize pretext-pdf errors for HTTP status code determination.
|
|
25
|
+
* Returns true if error is a client error (400), false if server error (500).
|
|
26
|
+
*/
|
|
27
|
+
function isClientError(err) {
|
|
28
|
+
if (!(err instanceof PretextPdfError))
|
|
29
|
+
return true; // Unknown errors → client error by default
|
|
30
|
+
const clientErrors = [
|
|
31
|
+
'VALIDATION_ERROR',
|
|
32
|
+
'IMAGE_LOAD_FAILED',
|
|
33
|
+
'IMAGE_FORMAT_MISMATCH',
|
|
34
|
+
'SVG_LOAD_FAILED',
|
|
35
|
+
'PAGE_TOO_SMALL',
|
|
36
|
+
'FONT_NOT_LOADED',
|
|
37
|
+
'FONT_LOAD_FAILED',
|
|
38
|
+
'MONOSPACE_FONT_REQUIRED',
|
|
39
|
+
'ENCRYPTION_NOT_AVAILABLE',
|
|
40
|
+
];
|
|
41
|
+
return clientErrors.includes(err.code);
|
|
42
|
+
}
|
|
9
43
|
function createServer() {
|
|
10
|
-
const server = new Server({ name: 'pretext-pdf', version: '1.0.
|
|
44
|
+
const server = new Server({ name: 'pretext-pdf', version: '1.0.7' }, { capabilities: { tools: {} } });
|
|
11
45
|
const tools = [generatePdfTool, generateInvoiceTool, generateReportTool, listElementsTool];
|
|
12
46
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
13
47
|
tools: tools.map(t => t.schema),
|
|
@@ -49,15 +83,21 @@ if (port) {
|
|
|
49
83
|
res.end(JSON.stringify({ ok: true, service: 'pretext-pdf-mcp' }));
|
|
50
84
|
return;
|
|
51
85
|
}
|
|
52
|
-
// REST
|
|
86
|
+
// REST API — POST /api/generate → returns PDF bytes
|
|
87
|
+
// Limit: 500 KB — accommodates PDFs with images, rich formatting, and new features (v0.5.1+)
|
|
88
|
+
// Validation: body.data must be a PdfDocument object before calling render()
|
|
53
89
|
if (url.pathname === '/api/generate' && req.method === 'POST') {
|
|
90
|
+
const MAX_BODY = 500_000; // 500 KB — same as MCP endpoint, supports full feature set
|
|
54
91
|
const chunks = [];
|
|
55
|
-
|
|
92
|
+
let totalSize = 0;
|
|
93
|
+
for await (const chunk of req) {
|
|
94
|
+
totalSize += chunk.length;
|
|
95
|
+
if (totalSize > MAX_BODY) {
|
|
96
|
+
res.writeHead(413, { 'Content-Type': 'application/json' });
|
|
97
|
+
res.end(JSON.stringify({ error: 'Request too large (max 500 KB)' }));
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
56
100
|
chunks.push(chunk);
|
|
57
|
-
if (Buffer.concat(chunks).length > 100_000) {
|
|
58
|
-
res.writeHead(413, { 'Content-Type': 'application/json' });
|
|
59
|
-
res.end(JSON.stringify({ error: 'Request too large' }));
|
|
60
|
-
return;
|
|
61
101
|
}
|
|
62
102
|
let body;
|
|
63
103
|
try {
|
|
@@ -65,10 +105,12 @@ if (port) {
|
|
|
65
105
|
}
|
|
66
106
|
catch {
|
|
67
107
|
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
68
|
-
res.end(JSON.stringify({ error: 'Invalid JSON' }));
|
|
108
|
+
res.end(JSON.stringify({ error: 'Invalid JSON body' }));
|
|
69
109
|
return;
|
|
70
110
|
}
|
|
71
111
|
try {
|
|
112
|
+
// Validate input before calling render()
|
|
113
|
+
validatePdfDocumentInput(body.data);
|
|
72
114
|
const pdf = await render(body.data);
|
|
73
115
|
res.writeHead(200, {
|
|
74
116
|
'Content-Type': 'application/pdf',
|
|
@@ -79,16 +121,30 @@ if (port) {
|
|
|
79
121
|
}
|
|
80
122
|
catch (err) {
|
|
81
123
|
const msg = err instanceof Error ? err.message : String(err);
|
|
82
|
-
|
|
83
|
-
|
|
124
|
+
const isClient = isClientError(err);
|
|
125
|
+
const statusCode = isClient ? 400 : 500;
|
|
126
|
+
const errorCode = err instanceof PretextPdfError ? err.code : 'UNKNOWN_ERROR';
|
|
127
|
+
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
128
|
+
res.end(JSON.stringify({ error: msg, code: errorCode }));
|
|
84
129
|
}
|
|
85
130
|
return;
|
|
86
131
|
}
|
|
87
|
-
// MCP endpoint — POST /mcp (stateless)
|
|
132
|
+
// MCP endpoint — POST /mcp (stateless, structured protocol)
|
|
133
|
+
// Limit: 500 KB — same as REST API, accommodates full feature set (images, rich formatting, etc.)
|
|
134
|
+
// Note: MCP protocol adds overhead (jsonrpc wrapper), so same limit across endpoints
|
|
88
135
|
if (url.pathname === '/mcp' && req.method === 'POST') {
|
|
136
|
+
const MAX_MCP_BODY = 500_000; // 500 KB — consistent with /api/generate
|
|
89
137
|
const chunks = [];
|
|
90
|
-
|
|
138
|
+
let mcpSize = 0;
|
|
139
|
+
for await (const chunk of req) {
|
|
140
|
+
mcpSize += chunk.length;
|
|
141
|
+
if (mcpSize > MAX_MCP_BODY) {
|
|
142
|
+
res.writeHead(413, { 'Content-Type': 'application/json' });
|
|
143
|
+
res.end(JSON.stringify({ error: 'Request too large (max 500 KB)' }));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
91
146
|
chunks.push(chunk);
|
|
147
|
+
}
|
|
92
148
|
const body = JSON.parse(Buffer.concat(chunks).toString());
|
|
93
149
|
const transport = new StreamableHTTPServerTransport({
|
|
94
150
|
sessionIdGenerator: undefined,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pretext-pdf-mcp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "MCP server for pretext-pdf — generate professional PDFs from JSON in Claude, Cursor, or any AI agent",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
27
|
-
"pretext-pdf": "^0.
|
|
27
|
+
"pretext-pdf": "^0.5.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^22.0.0",
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"dist/**/*",
|
|
36
36
|
"smithery.yaml",
|
|
37
37
|
"README.md",
|
|
38
|
-
"LICENSE"
|
|
38
|
+
"LICENSE",
|
|
39
|
+
"CHANGELOG.md"
|
|
39
40
|
],
|
|
40
41
|
"engines": {
|
|
41
42
|
"node": ">=18.0.0"
|
|
@@ -46,5 +47,8 @@
|
|
|
46
47
|
"type": "git",
|
|
47
48
|
"url": "https://github.com/Himaan1998Y/pretext-pdf-mcp"
|
|
48
49
|
},
|
|
49
|
-
"
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/Himaan1998Y/pretext-pdf-mcp/issues"
|
|
52
|
+
},
|
|
53
|
+
"homepage": "https://himaan1998y.github.io/pretext-pdf-mcp/"
|
|
50
54
|
}
|