Commit 9db22f0
authored
feat(mcp): add Python MCP server for paperjam (#46)
* fix(publish): use manylinux_2_28 for aarch64 to fix aws-lc-sys C11 compile failure
manylinux2014 (auto) uses GCC 4.8 from CentOS 7 which lacks stdatomic.h,
causing aws-lc-sys bcm.c cross-compilation to fail on aarch64.
manylinux_2_28 uses AlmaLinux 8 with GCC 8.5 which has full C11 support.
* feat(mcp): add Python MCP server for paperjam document processing
FastMCP-based server exposing 48+ tools for AI agents to open, extract,
manipulate, convert, and analyze documents (PDF, DOCX, XLSX, PPTX, HTML,
EPUB) via the Model Context Protocol.
Flat src/ layout with tools organized by domain:
- document: session lifecycle (open, close, save, list, info)
- extraction: text, tables, structure, markdown, search, links, images
- page: page-level operations and layout analysis
- manipulation: split, merge, reorder, delete, insert, rotate, optimize
- annotation: watermark, annotations, stamp
- metadata: document metadata, bookmarks, TOC generation
- comparison: text diff and visual diff
- conversion: format conversion and detection
- render: page rendering to PNG/JPEG/BMP
- forms: AcroForm field operations
- security: sanitize, redact, encrypt
- signatures: digital signature operations
- validation: PDF/A and PDF/UA compliance
- pipeline: YAML/JSON workflow execution
Includes session management with TTL, MCP resources for document
browsing, prompt templates for common workflows, structured error
handling with logging, and setuptools package-dir mapping for clean
src/ → paperjam_mcp installation.
* docs(mcp): add README with installation, config, and tools reference
Installation via uvx/pip, MCP client configuration examples for
tools reference table covering all 48+ tools across 14 categories.
* ci(mcp): add PyPI publish workflow with trusted publishing
Triggers on mcp-* tags (e.g. mcp-0.1.0). Builds pure Python wheel
with uv and publishes via OIDC trusted publishing — no API tokens.
* fix(mcp): use SPDX license string to fix setuptools deprecation warning
* docs: update README — remove redundant title, center badges, update MCP section
* fix(mcp): resolve PR review comments — unused imports and mixed import style
- server.py: move side-effect imports out, use importlib in __main__
- security.py: replace mixed import styles with single from-import
* fix(mcp): harden for production — path sandboxing, resource leaks, memory limits
Security:
- resolve_path: reject paths that escape the working directory
- pipeline tools: disabled — they bypass server-side path sandboxing
Resource management:
- update_document: close old document before replacing (prevents native resource leak)
- _cleanup_expired: wrap close() in try/except so one failure doesn't orphan remaining sessions
- close_all: new method for clean shutdown, registered via atexit
- TTL now based on last access time, not creation time
Memory safety:
- render_page/render_pages: cap DPI at 600, limit to 50 pages per call
- visual_diff: cap DPI at 300
Error handling:
- Add @handle_errors to all 7 resource handlers (previously raw exceptions)
* docs(mcp): update docs site MCP guide for Python server
Replace Rust MCP server references with the new Python package
(paperjam-mcp via uvx/pip). Add Cursor config example, complete
tools reference across all 14 categories, document security
sandboxing and session TTL behavior.
* ci(mcp): add CI workflow for MCP server — lint, typecheck, build
Runs on mcp-server/** changes. Lint job: ruff check, ruff format,
mypy. Build job: wheel build + CLI smoke test on Python 3.12 and 3.13.
* fix(ci): let uv sync build paperjam from source, drop maturin develop step
maturin develop requires a pre-existing virtualenv. uv sync handles
building the paperjam path dependency (which uses maturin) automatically.
* fix(mcp): add str() casts to fix mypy no-any-return errors
paperjam's stubs type extract_text() and to_markdown() as returning
Any, which triggers no-any-return when returned from -> str functions.1 parent 5491a3f commit 9db22f0
29 files changed
Lines changed: 2340 additions & 35 deletions
File tree
- .github/workflows
- docs-site/docs/guides
- mcp-server
- src
- tools
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
97 | 101 | | |
98 | 102 | | |
99 | 103 | | |
100 | 104 | | |
101 | 105 | | |
102 | | - | |
103 | | - | |
| 106 | + | |
| 107 | + | |
104 | 108 | | |
105 | 109 | | |
106 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
| 17 | + | |
| 18 | + | |
19 | 19 | | |
20 | | - | |
21 | | - | |
| 20 | + | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | | - | |
| 40 | + | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
57 | 72 | | |
58 | 73 | | |
59 | 74 | | |
60 | 75 | | |
61 | 76 | | |
62 | 77 | | |
63 | 78 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
69 | 87 | | |
70 | 88 | | |
71 | 89 | | |
72 | 90 | | |
73 | 91 | | |
74 | | - | |
| 92 | + | |
75 | 93 | | |
76 | 94 | | |
77 | 95 | | |
78 | | - | |
| 96 | + | |
79 | 97 | | |
80 | 98 | | |
81 | 99 | | |
| 100 | + | |
82 | 101 | | |
83 | | - | |
| 102 | + | |
84 | 103 | | |
85 | 104 | | |
86 | 105 | | |
87 | | - | |
| 106 | + | |
88 | 107 | | |
89 | 108 | | |
90 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
91 | 148 | | |
92 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
93 | 163 | | |
94 | 164 | | |
95 | 165 | | |
96 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
97 | 186 | | |
98 | | - | |
| 187 | + | |
99 | 188 | | |
100 | 189 | | |
101 | 190 | | |
| 191 | + | |
102 | 192 | | |
103 | | - | |
| 193 | + | |
104 | 194 | | |
105 | | - | |
106 | 195 | | |
107 | | - | |
| 196 | + | |
108 | 197 | | |
109 | 198 | | |
110 | 199 | | |
111 | | - | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
112 | 211 | | |
113 | 212 | | |
114 | 213 | | |
| |||
131 | 230 | | |
132 | 231 | | |
133 | 232 | | |
134 | | - | |
| 233 | + | |
135 | 234 | | |
136 | 235 | | |
137 | 236 | | |
| |||
141 | 240 | | |
142 | 241 | | |
143 | 242 | | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
144 | 253 | | |
145 | 254 | | |
146 | | - | |
| 255 | + | |
147 | 256 | | |
148 | 257 | | |
| 258 | + | |
149 | 259 | | |
150 | 260 | | |
151 | 261 | | |
| |||
0 commit comments