benspdf-mcp 0.1.0__tar.gz
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.
- benspdf_mcp-0.1.0/LICENSE +201 -0
- benspdf_mcp-0.1.0/MANIFEST.in +11 -0
- benspdf_mcp-0.1.0/PKG-INFO +201 -0
- benspdf_mcp-0.1.0/README.md +168 -0
- benspdf_mcp-0.1.0/pyproject.toml +75 -0
- benspdf_mcp-0.1.0/setup.cfg +4 -0
- benspdf_mcp-0.1.0/src/benscore/__init__.py +63 -0
- benspdf_mcp-0.1.0/src/benscore/errors.py +19 -0
- benspdf_mcp-0.1.0/src/benscore/results.py +34 -0
- benspdf_mcp-0.1.0/src/benscore/store.py +308 -0
- benspdf_mcp-0.1.0/src/benscore/tools.py +147 -0
- benspdf_mcp-0.1.0/src/benspdf/__init__.py +30 -0
- benspdf_mcp-0.1.0/src/benspdf/cli.py +229 -0
- benspdf_mcp-0.1.0/src/benspdf/mcp_client.py +175 -0
- benspdf_mcp-0.1.0/src/benspdf/mcp_server.py +363 -0
- benspdf_mcp-0.1.0/src/benspdf/models.py +51 -0
- benspdf_mcp-0.1.0/src/benspdf/tools/__init__.py +16 -0
- benspdf_mcp-0.1.0/src/benspdf/tools/check_access.py +324 -0
- benspdf_mcp-0.1.0/src/benspdf/tools/check_text.py +562 -0
- benspdf_mcp-0.1.0/src/benspdf/tools/create_test_pdf.py +71 -0
- benspdf_mcp-0.1.0/src/benspdf/tools/metadata.py +359 -0
- benspdf_mcp-0.1.0/src/benspdf/tools/page_count.py +95 -0
- benspdf_mcp-0.1.0/src/benspdf/tools/page_layout.py +441 -0
- benspdf_mcp-0.1.0/src/benspdf/tools/page_spec.py +94 -0
- benspdf_mcp-0.1.0/src/benspdf/tools/render_pages.py +298 -0
- benspdf_mcp-0.1.0/src/benspdf_mcp.egg-info/PKG-INFO +201 -0
- benspdf_mcp-0.1.0/src/benspdf_mcp.egg-info/SOURCES.txt +39 -0
- benspdf_mcp-0.1.0/src/benspdf_mcp.egg-info/dependency_links.txt +1 -0
- benspdf_mcp-0.1.0/src/benspdf_mcp.egg-info/entry_points.txt +3 -0
- benspdf_mcp-0.1.0/src/benspdf_mcp.egg-info/requires.txt +13 -0
- benspdf_mcp-0.1.0/src/benspdf_mcp.egg-info/top_level.txt +2 -0
- benspdf_mcp-0.1.0/tests/conftest.py +38 -0
- benspdf_mcp-0.1.0/tests/test_check_access.py +354 -0
- benspdf_mcp-0.1.0/tests/test_check_text.py +668 -0
- benspdf_mcp-0.1.0/tests/test_cli.py +73 -0
- benspdf_mcp-0.1.0/tests/test_core_store.py +313 -0
- benspdf_mcp-0.1.0/tests/test_mcp_server.py +601 -0
- benspdf_mcp-0.1.0/tests/test_metadata.py +356 -0
- benspdf_mcp-0.1.0/tests/test_page_layout.py +537 -0
- benspdf_mcp-0.1.0/tests/test_pdf_page_counter.py +124 -0
- benspdf_mcp-0.1.0/tests/test_render_pages.py +325 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# setuptools already picks up tests/test_*.py by itself, but not conftest.py,
|
|
2
|
+
# which every test needs: the autouse isolated_workspace fixture lives there and
|
|
3
|
+
# points the artifact workspace at a temp directory. Without it the tests in the
|
|
4
|
+
# sdist collect and then write to the real ~/.benstools/work. Graft the whole
|
|
5
|
+
# directory so the sdist is either coherent or obviously not.
|
|
6
|
+
graft tests
|
|
7
|
+
|
|
8
|
+
# Build noise that has no business in a release artifact.
|
|
9
|
+
global-exclude *.py[cod]
|
|
10
|
+
global-exclude .DS_Store
|
|
11
|
+
prune **/__pycache__
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: benspdf-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Local PDF tools for AI agents, exposed over the Model Context Protocol
|
|
5
|
+
Author-email: Benjamin Bergner <bergner.benjamin@gmail.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/benbergner/BensPDF
|
|
8
|
+
Project-URL: Repository, https://github.com/benbergner/BensPDF
|
|
9
|
+
Project-URL: Issues, https://github.com/benbergner/BensPDF/issues
|
|
10
|
+
Keywords: mcp,pdf,llm,agents,model-context-protocol
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Topic :: Text Processing
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: pypdf>=4.0.0
|
|
22
|
+
Requires-Dist: pypdfium2>=4.30.0
|
|
23
|
+
Requires-Dist: Pillow>=10.0.0
|
|
24
|
+
Requires-Dist: mcp>=2.0.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
28
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
29
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
30
|
+
Provides-Extra: ollama
|
|
31
|
+
Requires-Dist: ollama>=0.1.0; extra == "ollama"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# BensPDF
|
|
35
|
+
|
|
36
|
+
Ben's PDF tools for AI agents, exposed over the [Model Context Protocol](https://modelcontextprotocol.io) (MCP).
|
|
37
|
+
|
|
38
|
+
Your PDFs are read on your own machine and never uploaded. Works with Claude
|
|
39
|
+
Desktop, VS Code, Kiro, Cursor, the ChatGPT desktop app, and any other MCP
|
|
40
|
+
client, or fully offline with a local Ollama model.
|
|
41
|
+
|
|
42
|
+
## Tools
|
|
43
|
+
|
|
44
|
+
| Tool | What it does |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| `pdf_page_count` | Counts the pages in a PDF |
|
|
47
|
+
| `pdf_metadata` | Reads document properties: title, author, dates, producer |
|
|
48
|
+
| `pdf_check_text` | Says whether a PDF is readable text or a scan that needs OCR |
|
|
49
|
+
| `pdf_page_layout` | Page sizes, orientation, rotation and page boxes |
|
|
50
|
+
| `pdf_check_access` | Encryption, and what the file permits: printing, copying, editing |
|
|
51
|
+
| `pdf_render_pages` | Renders pages to images, so a page can be looked at |
|
|
52
|
+
| `create_test_pdf_file` | Generates a throwaway PDF, handy for trying things out |
|
|
53
|
+
| `export` | Saves results to a real location on disk |
|
|
54
|
+
| `list_artifacts` | Lists recent temporary results |
|
|
55
|
+
| `discard` | Deletes temporary results now |
|
|
56
|
+
|
|
57
|
+
## Where results go
|
|
58
|
+
|
|
59
|
+
When a tool makes a new PDF, it goes into a scratch folder instead of your own
|
|
60
|
+
folders, and you get back a short id like `art_a1b2c3d4.pdf`. Tools accept those
|
|
61
|
+
ids anywhere they accept a file path, so several steps can be chained together.
|
|
62
|
+
|
|
63
|
+
Results carry the artifact's `path` as well as its id, so you can open a rendered
|
|
64
|
+
page or an intermediate file straight away without exporting it first.
|
|
65
|
+
|
|
66
|
+
`export` is the only tool that writes into your folders, so nothing shows up
|
|
67
|
+
until you ask for it. Each time the server starts it clears out scratch files
|
|
68
|
+
older than 7 days. Set `BENSTOOLS_WORKSPACE` to put the scratch folder somewhere
|
|
69
|
+
other than `~/.benstools/work`.
|
|
70
|
+
|
|
71
|
+
## Setup
|
|
72
|
+
|
|
73
|
+
Install [uv](https://docs.astral.sh/uv/getting-started/installation/)
|
|
74
|
+
once, then point your client at `uvx benspdf-mcp` and uv fetches the package,
|
|
75
|
+
plus a suitable Python, on first run.
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# macOS and Linux
|
|
79
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
80
|
+
|
|
81
|
+
# Windows
|
|
82
|
+
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
On macOS, `brew install uv` works too.
|
|
86
|
+
|
|
87
|
+
Add the server to your client with one of the configs below, then restart the
|
|
88
|
+
server from your client's UI. Once connected, just ask in plain language:
|
|
89
|
+
|
|
90
|
+
> How many pages are in ~/Downloads/report.pdf?
|
|
91
|
+
|
|
92
|
+
### Claude Desktop
|
|
93
|
+
|
|
94
|
+
Edit `claude_desktop_config.json`, which lives at
|
|
95
|
+
`~/Library/Application Support/Claude/` on macOS and `%APPDATA%\Claude\` on
|
|
96
|
+
Windows. You can also open it from **Settings → Developer → Edit Config**.
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
{
|
|
100
|
+
"mcpServers": {
|
|
101
|
+
"benspdf": {
|
|
102
|
+
"command": "uvx",
|
|
103
|
+
"args": ["benspdf-mcp"]
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### VS Code
|
|
110
|
+
|
|
111
|
+
`.vscode/mcp.json` in your workspace, or the same file in your user profile.
|
|
112
|
+
Note VS Code uses `servers` rather than `mcpServers`, and wants an explicit
|
|
113
|
+
`type`.
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
{
|
|
117
|
+
"servers": {
|
|
118
|
+
"benspdf": {
|
|
119
|
+
"type": "stdio",
|
|
120
|
+
"command": "uvx",
|
|
121
|
+
"args": ["benspdf-mcp"]
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Kiro
|
|
128
|
+
|
|
129
|
+
`.kiro/settings/mcp.json` in your workspace, or `~/.kiro/settings/mcp.json` to
|
|
130
|
+
enable it everywhere. `autoApprove` skips the confirmation prompt for tools you
|
|
131
|
+
trust.
|
|
132
|
+
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"mcpServers": {
|
|
136
|
+
"benspdf": {
|
|
137
|
+
"command": "uvx",
|
|
138
|
+
"args": ["benspdf-mcp"],
|
|
139
|
+
"autoApprove": ["pdf_page_count"]
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Cursor, Continue.dev, and most other clients
|
|
146
|
+
|
|
147
|
+
Same shape as the Claude Desktop config above, in whatever file the client uses.
|
|
148
|
+
|
|
149
|
+
### ChatGPT desktop app, Codex CLI, Codex IDE extension
|
|
150
|
+
|
|
151
|
+
All three are Codex clients and share one config file, `~/.codex/config.toml`,
|
|
152
|
+
so adding the server once covers all of them.
|
|
153
|
+
|
|
154
|
+
```toml
|
|
155
|
+
[mcp_servers.benspdf]
|
|
156
|
+
command = "uvx"
|
|
157
|
+
args = ["benspdf-mcp"]
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Fully offline with Ollama
|
|
161
|
+
|
|
162
|
+
The clients above keep your PDFs local, but they answer using a hosted model.
|
|
163
|
+
Pair the tools with a local model instead and nothing leaves your machine.
|
|
164
|
+
|
|
165
|
+
You'll need [Ollama](https://ollama.com) with a model pulled, plus this package:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
pip install benspdf-mcp ollama
|
|
169
|
+
ollama pull llama3.1
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Then run the bundled CLI:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
benspdf-cli # uses the first model you have
|
|
176
|
+
benspdf-cli --model llama3.1 # or pick one
|
|
177
|
+
BENSPDF_MODEL=llama3.1 benspdf-cli # or set it once
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
`python -m benspdf.cli` does the same thing, handy from a source checkout.
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
You: how many pages in ~/Downloads/report.pdf?
|
|
184
|
+
[Using tool: pdf_page_count]
|
|
185
|
+
[Result: 12 pages in report.pdf]
|
|
186
|
+
Assistant: The PDF has 12 pages.
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Reference
|
|
190
|
+
|
|
191
|
+
Each tool's own description tells your client what it does and when to use it, so
|
|
192
|
+
in normal use there is nothing to look up. If you want the detail — every field a
|
|
193
|
+
tool returns, and the reasoning behind the answers it gives — see the
|
|
194
|
+
[tool reference](https://github.com/benbergner/BensPDF/blob/main/docs/tools.md).
|
|
195
|
+
|
|
196
|
+
To work on the code, see
|
|
197
|
+
[CONTRIBUTING.md](https://github.com/benbergner/BensPDF/blob/main/CONTRIBUTING.md).
|
|
198
|
+
|
|
199
|
+
## License
|
|
200
|
+
|
|
201
|
+
Apache 2.0
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# BensPDF
|
|
2
|
+
|
|
3
|
+
Ben's PDF tools for AI agents, exposed over the [Model Context Protocol](https://modelcontextprotocol.io) (MCP).
|
|
4
|
+
|
|
5
|
+
Your PDFs are read on your own machine and never uploaded. Works with Claude
|
|
6
|
+
Desktop, VS Code, Kiro, Cursor, the ChatGPT desktop app, and any other MCP
|
|
7
|
+
client, or fully offline with a local Ollama model.
|
|
8
|
+
|
|
9
|
+
## Tools
|
|
10
|
+
|
|
11
|
+
| Tool | What it does |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| `pdf_page_count` | Counts the pages in a PDF |
|
|
14
|
+
| `pdf_metadata` | Reads document properties: title, author, dates, producer |
|
|
15
|
+
| `pdf_check_text` | Says whether a PDF is readable text or a scan that needs OCR |
|
|
16
|
+
| `pdf_page_layout` | Page sizes, orientation, rotation and page boxes |
|
|
17
|
+
| `pdf_check_access` | Encryption, and what the file permits: printing, copying, editing |
|
|
18
|
+
| `pdf_render_pages` | Renders pages to images, so a page can be looked at |
|
|
19
|
+
| `create_test_pdf_file` | Generates a throwaway PDF, handy for trying things out |
|
|
20
|
+
| `export` | Saves results to a real location on disk |
|
|
21
|
+
| `list_artifacts` | Lists recent temporary results |
|
|
22
|
+
| `discard` | Deletes temporary results now |
|
|
23
|
+
|
|
24
|
+
## Where results go
|
|
25
|
+
|
|
26
|
+
When a tool makes a new PDF, it goes into a scratch folder instead of your own
|
|
27
|
+
folders, and you get back a short id like `art_a1b2c3d4.pdf`. Tools accept those
|
|
28
|
+
ids anywhere they accept a file path, so several steps can be chained together.
|
|
29
|
+
|
|
30
|
+
Results carry the artifact's `path` as well as its id, so you can open a rendered
|
|
31
|
+
page or an intermediate file straight away without exporting it first.
|
|
32
|
+
|
|
33
|
+
`export` is the only tool that writes into your folders, so nothing shows up
|
|
34
|
+
until you ask for it. Each time the server starts it clears out scratch files
|
|
35
|
+
older than 7 days. Set `BENSTOOLS_WORKSPACE` to put the scratch folder somewhere
|
|
36
|
+
other than `~/.benstools/work`.
|
|
37
|
+
|
|
38
|
+
## Setup
|
|
39
|
+
|
|
40
|
+
Install [uv](https://docs.astral.sh/uv/getting-started/installation/)
|
|
41
|
+
once, then point your client at `uvx benspdf-mcp` and uv fetches the package,
|
|
42
|
+
plus a suitable Python, on first run.
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# macOS and Linux
|
|
46
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
47
|
+
|
|
48
|
+
# Windows
|
|
49
|
+
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
On macOS, `brew install uv` works too.
|
|
53
|
+
|
|
54
|
+
Add the server to your client with one of the configs below, then restart the
|
|
55
|
+
server from your client's UI. Once connected, just ask in plain language:
|
|
56
|
+
|
|
57
|
+
> How many pages are in ~/Downloads/report.pdf?
|
|
58
|
+
|
|
59
|
+
### Claude Desktop
|
|
60
|
+
|
|
61
|
+
Edit `claude_desktop_config.json`, which lives at
|
|
62
|
+
`~/Library/Application Support/Claude/` on macOS and `%APPDATA%\Claude\` on
|
|
63
|
+
Windows. You can also open it from **Settings → Developer → Edit Config**.
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"mcpServers": {
|
|
68
|
+
"benspdf": {
|
|
69
|
+
"command": "uvx",
|
|
70
|
+
"args": ["benspdf-mcp"]
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### VS Code
|
|
77
|
+
|
|
78
|
+
`.vscode/mcp.json` in your workspace, or the same file in your user profile.
|
|
79
|
+
Note VS Code uses `servers` rather than `mcpServers`, and wants an explicit
|
|
80
|
+
`type`.
|
|
81
|
+
|
|
82
|
+
```json
|
|
83
|
+
{
|
|
84
|
+
"servers": {
|
|
85
|
+
"benspdf": {
|
|
86
|
+
"type": "stdio",
|
|
87
|
+
"command": "uvx",
|
|
88
|
+
"args": ["benspdf-mcp"]
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Kiro
|
|
95
|
+
|
|
96
|
+
`.kiro/settings/mcp.json` in your workspace, or `~/.kiro/settings/mcp.json` to
|
|
97
|
+
enable it everywhere. `autoApprove` skips the confirmation prompt for tools you
|
|
98
|
+
trust.
|
|
99
|
+
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"mcpServers": {
|
|
103
|
+
"benspdf": {
|
|
104
|
+
"command": "uvx",
|
|
105
|
+
"args": ["benspdf-mcp"],
|
|
106
|
+
"autoApprove": ["pdf_page_count"]
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Cursor, Continue.dev, and most other clients
|
|
113
|
+
|
|
114
|
+
Same shape as the Claude Desktop config above, in whatever file the client uses.
|
|
115
|
+
|
|
116
|
+
### ChatGPT desktop app, Codex CLI, Codex IDE extension
|
|
117
|
+
|
|
118
|
+
All three are Codex clients and share one config file, `~/.codex/config.toml`,
|
|
119
|
+
so adding the server once covers all of them.
|
|
120
|
+
|
|
121
|
+
```toml
|
|
122
|
+
[mcp_servers.benspdf]
|
|
123
|
+
command = "uvx"
|
|
124
|
+
args = ["benspdf-mcp"]
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Fully offline with Ollama
|
|
128
|
+
|
|
129
|
+
The clients above keep your PDFs local, but they answer using a hosted model.
|
|
130
|
+
Pair the tools with a local model instead and nothing leaves your machine.
|
|
131
|
+
|
|
132
|
+
You'll need [Ollama](https://ollama.com) with a model pulled, plus this package:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
pip install benspdf-mcp ollama
|
|
136
|
+
ollama pull llama3.1
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Then run the bundled CLI:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
benspdf-cli # uses the first model you have
|
|
143
|
+
benspdf-cli --model llama3.1 # or pick one
|
|
144
|
+
BENSPDF_MODEL=llama3.1 benspdf-cli # or set it once
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
`python -m benspdf.cli` does the same thing, handy from a source checkout.
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
You: how many pages in ~/Downloads/report.pdf?
|
|
151
|
+
[Using tool: pdf_page_count]
|
|
152
|
+
[Result: 12 pages in report.pdf]
|
|
153
|
+
Assistant: The PDF has 12 pages.
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Reference
|
|
157
|
+
|
|
158
|
+
Each tool's own description tells your client what it does and when to use it, so
|
|
159
|
+
in normal use there is nothing to look up. If you want the detail — every field a
|
|
160
|
+
tool returns, and the reasoning behind the answers it gives — see the
|
|
161
|
+
[tool reference](https://github.com/benbergner/BensPDF/blob/main/docs/tools.md).
|
|
162
|
+
|
|
163
|
+
To work on the code, see
|
|
164
|
+
[CONTRIBUTING.md](https://github.com/benbergner/BensPDF/blob/main/CONTRIBUTING.md).
|
|
165
|
+
|
|
166
|
+
## License
|
|
167
|
+
|
|
168
|
+
Apache 2.0
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
# 77 is the floor for PEP 639: `license` as an SPDX expression plus
|
|
3
|
+
# `license-files`, which is what PyPI reads now.
|
|
4
|
+
requires = ["setuptools>=77.0"]
|
|
5
|
+
build-backend = "setuptools.build_meta"
|
|
6
|
+
|
|
7
|
+
[project]
|
|
8
|
+
name = "benspdf-mcp"
|
|
9
|
+
version = "0.1.0"
|
|
10
|
+
description = "Local PDF tools for AI agents, exposed over the Model Context Protocol"
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requires-python = ">=3.11"
|
|
13
|
+
license = "Apache-2.0"
|
|
14
|
+
license-files = ["LICENSE"]
|
|
15
|
+
authors = [
|
|
16
|
+
{name = "Benjamin Bergner", email = "bergner.benjamin@gmail.com"}
|
|
17
|
+
]
|
|
18
|
+
keywords = ["mcp", "pdf", "llm", "agents", "model-context-protocol"]
|
|
19
|
+
# These become the sidebar links on the PyPI page, which is where someone who
|
|
20
|
+
# found the package by search goes next.
|
|
21
|
+
urls.Homepage = "https://github.com/benbergner/BensPDF"
|
|
22
|
+
urls.Repository = "https://github.com/benbergner/BensPDF"
|
|
23
|
+
urls.Issues = "https://github.com/benbergner/BensPDF/issues"
|
|
24
|
+
# No license classifier: PEP 639 replaced it with the `license` field above, and
|
|
25
|
+
# setuptools rejects declaring both.
|
|
26
|
+
classifiers = [
|
|
27
|
+
"Development Status :: 3 - Alpha",
|
|
28
|
+
"Intended Audience :: Developers",
|
|
29
|
+
"Programming Language :: Python :: 3.11",
|
|
30
|
+
"Programming Language :: Python :: 3.12",
|
|
31
|
+
"Programming Language :: Python :: 3.13",
|
|
32
|
+
"Topic :: Text Processing",
|
|
33
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
34
|
+
]
|
|
35
|
+
dependencies = [
|
|
36
|
+
"pypdf>=4.0.0",
|
|
37
|
+
"pypdfium2>=4.30.0",
|
|
38
|
+
"Pillow>=10.0.0",
|
|
39
|
+
"mcp>=2.0.0",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[project.scripts]
|
|
43
|
+
benspdf-mcp = "benspdf.mcp_server:main"
|
|
44
|
+
benspdf-cli = "benspdf.cli:main"
|
|
45
|
+
|
|
46
|
+
[project.optional-dependencies]
|
|
47
|
+
dev = [
|
|
48
|
+
"pytest>=7.0.0",
|
|
49
|
+
"pytest-asyncio>=0.21.0",
|
|
50
|
+
"black>=23.0.0",
|
|
51
|
+
"mypy>=1.0.0",
|
|
52
|
+
]
|
|
53
|
+
ollama = ["ollama>=0.1.0"]
|
|
54
|
+
|
|
55
|
+
# Two top-level packages: benspdf (the PDF verbs) and benscore (the shared
|
|
56
|
+
# artifact layer they sit on). benscore carries no domain in its name or its
|
|
57
|
+
# config surface, so a future domain package can share one workspace with these
|
|
58
|
+
# verbs, and so moving it into its own distribution later changes nothing for
|
|
59
|
+
# anything that imports it.
|
|
60
|
+
[tool.setuptools.packages.find]
|
|
61
|
+
where = ["src"]
|
|
62
|
+
|
|
63
|
+
# pypdfium2 is a ctypes binding and ships no py.typed marker, so mypy cannot see
|
|
64
|
+
# into it. Nothing to fix on our side; the calls we make are covered by tests.
|
|
65
|
+
[[tool.mypy.overrides]]
|
|
66
|
+
module = ["pypdfium2.*", "pypdfium2"]
|
|
67
|
+
ignore_missing_imports = true
|
|
68
|
+
|
|
69
|
+
# ollama is an optional extra, so the common case is that it is not installed -
|
|
70
|
+
# which is the case cli.py already handles, by guarding the import and telling
|
|
71
|
+
# the user how to get it. Without this, type checking an install that does not
|
|
72
|
+
# have the extra fails on an import that is meant to be absent.
|
|
73
|
+
[[tool.mypy.overrides]]
|
|
74
|
+
module = ["ollama.*", "ollama"]
|
|
75
|
+
ignore_missing_imports = true
|