bucketlens 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.
Files changed (31) hide show
  1. bucketlens-0.1.0/.github/workflows/ci.yml +17 -0
  2. bucketlens-0.1.0/.github/workflows/release.yml +45 -0
  3. bucketlens-0.1.0/.gitignore +11 -0
  4. bucketlens-0.1.0/LICENSE +202 -0
  5. bucketlens-0.1.0/PKG-INFO +195 -0
  6. bucketlens-0.1.0/README.md +169 -0
  7. bucketlens-0.1.0/benchmarks/README.md +25 -0
  8. bucketlens-0.1.0/benchmarks/RESULTS.md +183 -0
  9. bucketlens-0.1.0/benchmarks/agent_test.py +162 -0
  10. bucketlens-0.1.0/benchmarks/fetch_real.py +100 -0
  11. bucketlens-0.1.0/benchmarks/gen/make_big_workbook.py +71 -0
  12. bucketlens-0.1.0/benchmarks/gen/make_contracts.py +142 -0
  13. bucketlens-0.1.0/benchmarks/gen/make_workbook.py +71 -0
  14. bucketlens-0.1.0/benchmarks/questions/real.json +85 -0
  15. bucketlens-0.1.0/benchmarks/questions/synthetic.json +146 -0
  16. bucketlens-0.1.0/benchmarks/results/real-2026-11-14-v0.1-package.json +142 -0
  17. bucketlens-0.1.0/benchmarks/results/real-2026-11-14.json +512 -0
  18. bucketlens-0.1.0/benchmarks/results/synthetic-2026-11-14.json +818 -0
  19. bucketlens-0.1.0/pyproject.toml +49 -0
  20. bucketlens-0.1.0/server.json +61 -0
  21. bucketlens-0.1.0/src/bucketlens/__init__.py +3 -0
  22. bucketlens-0.1.0/src/bucketlens/__main__.py +5 -0
  23. bucketlens-0.1.0/src/bucketlens/cli.py +140 -0
  24. bucketlens-0.1.0/src/bucketlens/config.py +111 -0
  25. bucketlens-0.1.0/src/bucketlens/index.py +260 -0
  26. bucketlens-0.1.0/src/bucketlens/parse.py +146 -0
  27. bucketlens-0.1.0/src/bucketlens/server.py +161 -0
  28. bucketlens-0.1.0/src/bucketlens/store.py +114 -0
  29. bucketlens-0.1.0/src/bucketlens/watch.py +206 -0
  30. bucketlens-0.1.0/tests/conftest.py +103 -0
  31. bucketlens-0.1.0/tests/test_bucketlens.py +153 -0
@@ -0,0 +1,17 @@
1
+ name: ci
2
+ on:
3
+ push:
4
+ branches: [main]
5
+ pull_request:
6
+ jobs:
7
+ test:
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ matrix:
11
+ python: ["3.10", "3.11", "3.12"]
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - uses: astral-sh/setup-uv@v5
15
+ - run: uv venv --python ${{ matrix.python }} && uv pip install -e ".[dev]"
16
+ - run: .venv/bin/ruff check .
17
+ - run: .venv/bin/python -m pytest -q -p no:logging
@@ -0,0 +1,45 @@
1
+ name: release
2
+ # Push a tag like v0.1.0. This builds the package, publishes it to PyPI (trusted publishing, no
3
+ # token stored here), then lists the new version in the official MCP Registry (GitHub OIDC login).
4
+ on:
5
+ push:
6
+ tags: ["v*"]
7
+ jobs:
8
+ pypi:
9
+ runs-on: ubuntu-latest
10
+ environment: pypi
11
+ permissions:
12
+ id-token: write
13
+ contents: read
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: astral-sh/setup-uv@v5
17
+ - name: Versions match the tag
18
+ run: |
19
+ tag="${GITHUB_REF_NAME#v}"
20
+ py=$(grep -m1 '^version = ' pyproject.toml | cut -d'"' -f2)
21
+ sj=$(python3 -c "import json;d=json.load(open('server.json'));print(d['version'], d['packages'][0]['version'])")
22
+ echo "tag=$tag pyproject=$py server.json=$sj"
23
+ [ "$py" = "$tag" ] && [ "$sj" = "$tag $tag" ]
24
+ - run: uv build
25
+ - uses: pypa/gh-action-pypi-publish@release/v1
26
+ mcp-registry:
27
+ needs: pypi
28
+ runs-on: ubuntu-latest
29
+ permissions:
30
+ id-token: write
31
+ contents: read
32
+ steps:
33
+ - uses: actions/checkout@v4
34
+ - name: Install mcp-publisher
35
+ run: |
36
+ curl -fsSL "https://github.com/modelcontextprotocol/registry/releases/latest/download/mcp-publisher_linux_amd64.tar.gz" | tar xz mcp-publisher
37
+ - name: Wait for PyPI to serve the new version
38
+ run: |
39
+ for i in $(seq 1 30); do
40
+ curl -fsS "https://pypi.org/pypi/bucketlens/${GITHUB_REF_NAME#v}/json" >/dev/null && exit 0
41
+ sleep 10
42
+ done
43
+ exit 1
44
+ - run: ./mcp-publisher login github-oidc
45
+ - run: ./mcp-publisher publish
@@ -0,0 +1,11 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+ dist/
7
+ build/
8
+ *.egg-info/
9
+ benchmarks/results/runs/
10
+ *.env
11
+ .DS_Store
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,195 @@
1
+ Metadata-Version: 2.5
2
+ Name: bucketlens
3
+ Version: 0.1.0
4
+ Summary: Let any AI agent read the documents and spreadsheets in your own S3 or R2 bucket: outlines, pages, rows, SQL and search, without downloading the files.
5
+ Project-URL: Homepage, https://github.com/Pritom14/bucketlens
6
+ Author: Pritom Mazumdar
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ Keywords: agents,documents,excel,llm,mcp,pdf,r2,s3
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
13
+ Requires-Python: >=3.10
14
+ Requires-Dist: boto3>=1.34
15
+ Requires-Dist: duckdb>=1.2
16
+ Requires-Dist: mcp>=2.0
17
+ Requires-Dist: openpyxl>=3.1
18
+ Requires-Dist: pypdfium2>=4.30
19
+ Provides-Extra: dev
20
+ Requires-Dist: fpdf2>=2.7; extra == 'dev'
21
+ Requires-Dist: moto[server]>=5; extra == 'dev'
22
+ Requires-Dist: pytest>=8; extra == 'dev'
23
+ Requires-Dist: ruff>=0.6; extra == 'dev'
24
+ Requires-Dist: xlsxwriter>=3.1; extra == 'dev'
25
+ Description-Content-Type: text/markdown
26
+
27
+ # bucketlens
28
+
29
+ <!-- mcp-name: io.github.Pritom14/bucketlens -->
30
+
31
+ [![ci](https://github.com/Pritom14/bucketlens/actions/workflows/ci.yml/badge.svg)](https://github.com/Pritom14/bucketlens/actions/workflows/ci.yml)
32
+ [![python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-3776ab)](pyproject.toml)
33
+ [![license](https://img.shields.io/badge/license-Apache--2.0-4f46e5)](LICENSE)
34
+ [![MCP](https://img.shields.io/badge/MCP-server-111827)](https://modelcontextprotocol.io)
35
+
36
+ Let any AI agent read the documents and spreadsheets in your own S3 or R2 bucket, without
37
+ downloading them.
38
+
39
+ Agents work best the way a developer does: look at what's there, search, open just the part
40
+ that matters. That works on code, because code is plain text on a local disk. A company's
41
+ knowledge is PDFs, spreadsheets and contracts in a bucket. An agent with a shell downloads and
42
+ parses them on every run. An agent without one (a chat app, Claude Desktop, a support bot, an
43
+ MCP-only client) often can't use them at all.
44
+
45
+ bucketlens is an MCP server. It parses each file once, keeps the result next to the file in your
46
+ bucket, and lets the agent ask for exactly what it needs: an outline, pages 36 to 38, a search
47
+ across 100 contracts, or a SQL query over a 400,000-row sheet.
48
+
49
+ ## Results on real files
50
+
51
+ Claude Code (Sonnet) answered 10 questions about real public files: Berkshire Hathaway's 2025
52
+ annual report and 2026 quarterly reports, the World Bank's 82 MB World Development Indicators
53
+ workbook, and 100 commercial contracts from the CUAD dataset. Each question ran three ways.
54
+
55
+ | Setup | Right answers | Tokens | Cost | Time |
56
+ |---|---|---|---|---|
57
+ | Downloads the files, has a shell and Python | 10/10 | 226,231 | $0.21 | 405 s |
58
+ | Downloads the files, no shell (like a chat app) | 6/10 | 433,144 | $0.59 | 370 s |
59
+ | bucketlens (no files, no shell) | **10/10** | **159,280** | $0.23 | **141 s** |
60
+ | bucketlens, re-run with the released v0.1 package | **10/10** | 182,630 | $0.30 | 165 s |
61
+
62
+ By dataset:
63
+
64
+ | Dataset | Shell | No shell | bucketlens |
65
+ |---|---|---|---|
66
+ | Berkshire reports (154-page annual report, 3 quarterlies) | 5/5, 67 s | 5/5, 2.9x the tokens | 5/5, 48 s |
67
+ | World Bank workbook (82 MB, 398,468 rows) | 3/3, 240 s | **0/3**, can't open .xlsx | 3/3, 52 s |
68
+ | 100 contracts (1,481 pages) | 2/2, 98 s | **1/2** | 2/2, 41 s |
69
+
70
+ What this says, honestly:
71
+
72
+ - **Agents without a shell are where bucketlens changes the outcome.** They can't open a
73
+ spreadsheet at all, and across many files they give up or spend many turns reading.
74
+ - **Agents with a shell get the same answers either way.** bucketlens is about 2.5x faster for them
75
+ (no downloads; the 82 MB workbook alone took 20 to 65 s to download) and uses fewer tokens. It is
76
+ not cheaper: $0.23 and $0.30 across two runs, against $0.21, because tool results are fresh input
77
+ while a shell agent's long prompt is mostly cached.
78
+
79
+ The answers were checked automatically against values taken from the files. The 2026 quarterly
80
+ figures are newer than the model's training data, so they had to be read, not remembered.
81
+ Details and earlier runs on synthetic data: [benchmarks/RESULTS.md](benchmarks/RESULTS.md).
82
+
83
+ ## Quick start
84
+
85
+ bucketlens is an MCP server. Install it, point it at a bucket, and add it to any MCP client.
86
+
87
+ ```bash
88
+ pip install bucketlens # or: uv tool install bucketlens
89
+ bucketlens setup # bucket + keys, typed hidden, saved to ~/.config/bucketlens/config.env
90
+ bucketlens index # parse every PDF, XLSX and CSV once (optional; files are also indexed on first use)
91
+ ```
92
+
93
+ **Claude Code**
94
+
95
+ ```bash
96
+ claude mcp add bucketlens -- bucketlens serve
97
+ ```
98
+
99
+ **Claude Desktop, Cursor, or any client that takes a JSON config** (no install needed with `uvx`):
100
+
101
+ ```json
102
+ {
103
+ "mcpServers": {
104
+ "bucketlens": {
105
+ "command": "uvx",
106
+ "args": ["bucketlens", "serve"],
107
+ "env": {
108
+ "BUCKETLENS_R2_ACCOUNT_ID": "your Cloudflare account ID (or set BUCKETLENS_ENDPOINT for S3)",
109
+ "BUCKETLENS_BUCKET": "your-bucket",
110
+ "BUCKETLENS_ACCESS_KEY_ID": "...",
111
+ "BUCKETLENS_SECRET_ACCESS_KEY": "..."
112
+ }
113
+ }
114
+ }
115
+ }
116
+ ```
117
+
118
+ If you ran `bucketlens setup`, leave out `env`: the server reads the saved config.
119
+
120
+ Works with Cloudflare R2, AWS S3, MinIO and other S3-compatible storage. Give it a key that can
121
+ read the bucket and write under `.bucketlens/` (where the index lives). It is listed in the
122
+ official MCP Registry as `io.github.Pritom14/bucketlens`.
123
+
124
+ ## Tools the agent gets
125
+
126
+ | Tool | What it returns |
127
+ |---|---|
128
+ | `list_files(prefix)` | names, sizes, dates; nothing is downloaded |
129
+ | `outline(path, depth)` | PDF: pages, table of contents with page numbers, token cost of reading it whole. Spreadsheet: sheets, rows, columns and types |
130
+ | `search(path, text)` | pages of one PDF that contain the text, with snippets |
131
+ | `search_all(text, folder, files_only)` | every PDF in a folder at once, as compact hits or just file names and counts |
132
+ | `read_pages(path, pages)` | text of specific pages, e.g. `"36-38"` |
133
+ | `query(path, sql)` | read-only SQL over a spreadsheet or CSV; each sheet is a table |
134
+ | `read_rows(path, sheet, first, last)` | rows by the spreadsheet's own row numbers |
135
+
136
+ ## How it works
137
+
138
+ The first time a file is touched (or when it's saved, with `watch`), bucketlens reads it once:
139
+
140
+ - **PDF**: each page's text goes into one `pages.txt` with byte offsets, plus the outline. Reading
141
+ pages 600 to 602 of a 733-page PDF is then one range request (about 150 KB).
142
+ - **XLSX / CSV**: each sheet becomes a Parquet file with a `_row` column. DuckDB reads only the
143
+ columns and row groups a query needs (rows 150,000 to 150,049 of a 20 MB workbook: about 190 KB).
144
+
145
+ Everything is stored under `.bucketlens/index/<file>/<etag>/`. When a file changes its ETag
146
+ changes, so an agent is never answered from an old version.
147
+
148
+ Why not just read parts of the original file? We measured it: opening a PDF or the first rows of
149
+ a workbook fetches 5 to 7% of the file, but deep pages and deep rows fetch 50 to 75%, because of
150
+ how PDF and XLSX are laid out inside. Parsing once and serving slices is what makes every read
151
+ small.
152
+
153
+ ## Keeping the index fresh
154
+
155
+ ```bash
156
+ bucketlens watch # Cloudflare R2: event notifications -> Queue, pulled over HTTP
157
+ bucketlens watch --poll 300 # any S3: list the bucket every 5 minutes
158
+ ```
159
+
160
+ With R2 event notifications, a new 492-page PDF was indexed 8.8 s after its upload started, an
161
+ edited workbook 4.4 s after it was saved, and a deleted file's index removed 3 s later. To set it
162
+ up: create a Queue, add an event notification on the bucket (object creation and deletion) that
163
+ sends to it, and add a Cloudflare API token with **Account > Queues > Edit** to the config as
164
+ `BUCKETLENS_CF_API_TOKEN`, with `BUCKETLENS_CF_QUEUE` set to the queue's name.
165
+
166
+ ## Costs
167
+
168
+ bucketlens itself is free. On Cloudflare R2, the free tier (10 GB of storage, 1 million writes and
169
+ 10 million reads a month, free downloads) covered everything in the benchmarks. The index adds
170
+ about 25% to stored bytes for these files. The watcher polls once a minute when idle, about
171
+ 1,440 Queue calls a day against a free allowance of 10,000. R2 has no hard spending cap, so set a
172
+ billing alert.
173
+
174
+ ## Security
175
+
176
+ - Keys stay on your machine, in a file only you can read. bucketlens never prints them.
177
+ - SQL from agents is read-only: one statement, and DuckDB is locked so it can't read or write local
178
+ files or change its own settings.
179
+ - The agent can read anything in the bucket the key can read. Use a key scoped to one bucket.
180
+
181
+ ## Limits
182
+
183
+ - Reads PDF, XLSX/XLSM and CSV. Word and PowerPoint are next.
184
+ - Scanned PDFs without a text layer aren't searchable yet (no OCR).
185
+ - The first touch of a file reads it whole; use `watch` or `index` so agents never wait on it.
186
+ - Benchmarks used one agent (Claude Code) and one model (Sonnet).
187
+
188
+ ## Reproduce the benchmarks
189
+
190
+ See [benchmarks/README.md](benchmarks/README.md). The public files are fetched by a script, not
191
+ stored in this repo.
192
+
193
+ ## License
194
+
195
+ Apache-2.0
@@ -0,0 +1,169 @@
1
+ # bucketlens
2
+
3
+ <!-- mcp-name: io.github.Pritom14/bucketlens -->
4
+
5
+ [![ci](https://github.com/Pritom14/bucketlens/actions/workflows/ci.yml/badge.svg)](https://github.com/Pritom14/bucketlens/actions/workflows/ci.yml)
6
+ [![python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-3776ab)](pyproject.toml)
7
+ [![license](https://img.shields.io/badge/license-Apache--2.0-4f46e5)](LICENSE)
8
+ [![MCP](https://img.shields.io/badge/MCP-server-111827)](https://modelcontextprotocol.io)
9
+
10
+ Let any AI agent read the documents and spreadsheets in your own S3 or R2 bucket, without
11
+ downloading them.
12
+
13
+ Agents work best the way a developer does: look at what's there, search, open just the part
14
+ that matters. That works on code, because code is plain text on a local disk. A company's
15
+ knowledge is PDFs, spreadsheets and contracts in a bucket. An agent with a shell downloads and
16
+ parses them on every run. An agent without one (a chat app, Claude Desktop, a support bot, an
17
+ MCP-only client) often can't use them at all.
18
+
19
+ bucketlens is an MCP server. It parses each file once, keeps the result next to the file in your
20
+ bucket, and lets the agent ask for exactly what it needs: an outline, pages 36 to 38, a search
21
+ across 100 contracts, or a SQL query over a 400,000-row sheet.
22
+
23
+ ## Results on real files
24
+
25
+ Claude Code (Sonnet) answered 10 questions about real public files: Berkshire Hathaway's 2025
26
+ annual report and 2026 quarterly reports, the World Bank's 82 MB World Development Indicators
27
+ workbook, and 100 commercial contracts from the CUAD dataset. Each question ran three ways.
28
+
29
+ | Setup | Right answers | Tokens | Cost | Time |
30
+ |---|---|---|---|---|
31
+ | Downloads the files, has a shell and Python | 10/10 | 226,231 | $0.21 | 405 s |
32
+ | Downloads the files, no shell (like a chat app) | 6/10 | 433,144 | $0.59 | 370 s |
33
+ | bucketlens (no files, no shell) | **10/10** | **159,280** | $0.23 | **141 s** |
34
+ | bucketlens, re-run with the released v0.1 package | **10/10** | 182,630 | $0.30 | 165 s |
35
+
36
+ By dataset:
37
+
38
+ | Dataset | Shell | No shell | bucketlens |
39
+ |---|---|---|---|
40
+ | Berkshire reports (154-page annual report, 3 quarterlies) | 5/5, 67 s | 5/5, 2.9x the tokens | 5/5, 48 s |
41
+ | World Bank workbook (82 MB, 398,468 rows) | 3/3, 240 s | **0/3**, can't open .xlsx | 3/3, 52 s |
42
+ | 100 contracts (1,481 pages) | 2/2, 98 s | **1/2** | 2/2, 41 s |
43
+
44
+ What this says, honestly:
45
+
46
+ - **Agents without a shell are where bucketlens changes the outcome.** They can't open a
47
+ spreadsheet at all, and across many files they give up or spend many turns reading.
48
+ - **Agents with a shell get the same answers either way.** bucketlens is about 2.5x faster for them
49
+ (no downloads; the 82 MB workbook alone took 20 to 65 s to download) and uses fewer tokens. It is
50
+ not cheaper: $0.23 and $0.30 across two runs, against $0.21, because tool results are fresh input
51
+ while a shell agent's long prompt is mostly cached.
52
+
53
+ The answers were checked automatically against values taken from the files. The 2026 quarterly
54
+ figures are newer than the model's training data, so they had to be read, not remembered.
55
+ Details and earlier runs on synthetic data: [benchmarks/RESULTS.md](benchmarks/RESULTS.md).
56
+
57
+ ## Quick start
58
+
59
+ bucketlens is an MCP server. Install it, point it at a bucket, and add it to any MCP client.
60
+
61
+ ```bash
62
+ pip install bucketlens # or: uv tool install bucketlens
63
+ bucketlens setup # bucket + keys, typed hidden, saved to ~/.config/bucketlens/config.env
64
+ bucketlens index # parse every PDF, XLSX and CSV once (optional; files are also indexed on first use)
65
+ ```
66
+
67
+ **Claude Code**
68
+
69
+ ```bash
70
+ claude mcp add bucketlens -- bucketlens serve
71
+ ```
72
+
73
+ **Claude Desktop, Cursor, or any client that takes a JSON config** (no install needed with `uvx`):
74
+
75
+ ```json
76
+ {
77
+ "mcpServers": {
78
+ "bucketlens": {
79
+ "command": "uvx",
80
+ "args": ["bucketlens", "serve"],
81
+ "env": {
82
+ "BUCKETLENS_R2_ACCOUNT_ID": "your Cloudflare account ID (or set BUCKETLENS_ENDPOINT for S3)",
83
+ "BUCKETLENS_BUCKET": "your-bucket",
84
+ "BUCKETLENS_ACCESS_KEY_ID": "...",
85
+ "BUCKETLENS_SECRET_ACCESS_KEY": "..."
86
+ }
87
+ }
88
+ }
89
+ }
90
+ ```
91
+
92
+ If you ran `bucketlens setup`, leave out `env`: the server reads the saved config.
93
+
94
+ Works with Cloudflare R2, AWS S3, MinIO and other S3-compatible storage. Give it a key that can
95
+ read the bucket and write under `.bucketlens/` (where the index lives). It is listed in the
96
+ official MCP Registry as `io.github.Pritom14/bucketlens`.
97
+
98
+ ## Tools the agent gets
99
+
100
+ | Tool | What it returns |
101
+ |---|---|
102
+ | `list_files(prefix)` | names, sizes, dates; nothing is downloaded |
103
+ | `outline(path, depth)` | PDF: pages, table of contents with page numbers, token cost of reading it whole. Spreadsheet: sheets, rows, columns and types |
104
+ | `search(path, text)` | pages of one PDF that contain the text, with snippets |
105
+ | `search_all(text, folder, files_only)` | every PDF in a folder at once, as compact hits or just file names and counts |
106
+ | `read_pages(path, pages)` | text of specific pages, e.g. `"36-38"` |
107
+ | `query(path, sql)` | read-only SQL over a spreadsheet or CSV; each sheet is a table |
108
+ | `read_rows(path, sheet, first, last)` | rows by the spreadsheet's own row numbers |
109
+
110
+ ## How it works
111
+
112
+ The first time a file is touched (or when it's saved, with `watch`), bucketlens reads it once:
113
+
114
+ - **PDF**: each page's text goes into one `pages.txt` with byte offsets, plus the outline. Reading
115
+ pages 600 to 602 of a 733-page PDF is then one range request (about 150 KB).
116
+ - **XLSX / CSV**: each sheet becomes a Parquet file with a `_row` column. DuckDB reads only the
117
+ columns and row groups a query needs (rows 150,000 to 150,049 of a 20 MB workbook: about 190 KB).
118
+
119
+ Everything is stored under `.bucketlens/index/<file>/<etag>/`. When a file changes its ETag
120
+ changes, so an agent is never answered from an old version.
121
+
122
+ Why not just read parts of the original file? We measured it: opening a PDF or the first rows of
123
+ a workbook fetches 5 to 7% of the file, but deep pages and deep rows fetch 50 to 75%, because of
124
+ how PDF and XLSX are laid out inside. Parsing once and serving slices is what makes every read
125
+ small.
126
+
127
+ ## Keeping the index fresh
128
+
129
+ ```bash
130
+ bucketlens watch # Cloudflare R2: event notifications -> Queue, pulled over HTTP
131
+ bucketlens watch --poll 300 # any S3: list the bucket every 5 minutes
132
+ ```
133
+
134
+ With R2 event notifications, a new 492-page PDF was indexed 8.8 s after its upload started, an
135
+ edited workbook 4.4 s after it was saved, and a deleted file's index removed 3 s later. To set it
136
+ up: create a Queue, add an event notification on the bucket (object creation and deletion) that
137
+ sends to it, and add a Cloudflare API token with **Account > Queues > Edit** to the config as
138
+ `BUCKETLENS_CF_API_TOKEN`, with `BUCKETLENS_CF_QUEUE` set to the queue's name.
139
+
140
+ ## Costs
141
+
142
+ bucketlens itself is free. On Cloudflare R2, the free tier (10 GB of storage, 1 million writes and
143
+ 10 million reads a month, free downloads) covered everything in the benchmarks. The index adds
144
+ about 25% to stored bytes for these files. The watcher polls once a minute when idle, about
145
+ 1,440 Queue calls a day against a free allowance of 10,000. R2 has no hard spending cap, so set a
146
+ billing alert.
147
+
148
+ ## Security
149
+
150
+ - Keys stay on your machine, in a file only you can read. bucketlens never prints them.
151
+ - SQL from agents is read-only: one statement, and DuckDB is locked so it can't read or write local
152
+ files or change its own settings.
153
+ - The agent can read anything in the bucket the key can read. Use a key scoped to one bucket.
154
+
155
+ ## Limits
156
+
157
+ - Reads PDF, XLSX/XLSM and CSV. Word and PowerPoint are next.
158
+ - Scanned PDFs without a text layer aren't searchable yet (no OCR).
159
+ - The first touch of a file reads it whole; use `watch` or `index` so agents never wait on it.
160
+ - Benchmarks used one agent (Claude Code) and one model (Sonnet).
161
+
162
+ ## Reproduce the benchmarks
163
+
164
+ See [benchmarks/README.md](benchmarks/README.md). The public files are fetched by a script, not
165
+ stored in this repo.
166
+
167
+ ## License
168
+
169
+ Apache-2.0
@@ -0,0 +1,25 @@
1
+ # Benchmarks
2
+
3
+ `agent_test.py` asks Claude Code the same questions three ways (shell + downloads, no shell +
4
+ downloads, bucketlens only) and checks each answer against a value taken from the files.
5
+
6
+ ```bash
7
+ pip install -e ".[dev]"
8
+ bucketlens setup # point it at a test bucket
9
+ python benchmarks/fetch_real.py # downloads the public files and uploads them under real/
10
+ bucketlens index --prefix real/
11
+ python benchmarks/agent_test.py --questions benchmarks/questions/real.json --parallel 4
12
+ ```
13
+
14
+ Each run is capped at `AGENT_TEST_BUDGET` dollars (default 0.40). The full real-file comparison
15
+ (30 runs) cost about $1.
16
+
17
+ - `questions/real.json`: 10 questions on Berkshire Hathaway reports, the World Bank WDI workbook and
18
+ 100 CUAD contracts.
19
+ - `questions/synthetic.json`: 17 questions on NIST SP 800-53 PDFs and generated spreadsheets and
20
+ contracts (`gen/`).
21
+ - `results/`: every run, with answers, tokens, cost and time. `RESULTS.md` is the full log.
22
+
23
+ Data sources: Berkshire Hathaway reports (berkshirehathaway.com), World Bank World Development
24
+ Indicators (CC BY 4.0), CUAD v1 by The Atticus Project (CC BY 4.0). They are downloaded by the
25
+ script, not stored here.