toolbloat 0.2.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 (33) hide show
  1. toolbloat-0.2.0/.gitignore +15 -0
  2. toolbloat-0.2.0/CHANGELOG.md +48 -0
  3. toolbloat-0.2.0/LICENSE +21 -0
  4. toolbloat-0.2.0/NOTICE +232 -0
  5. toolbloat-0.2.0/PKG-INFO +296 -0
  6. toolbloat-0.2.0/README.md +264 -0
  7. toolbloat-0.2.0/pyproject.toml +68 -0
  8. toolbloat-0.2.0/src/toolbloat/__init__.py +3 -0
  9. toolbloat-0.2.0/src/toolbloat/__main__.py +3 -0
  10. toolbloat-0.2.0/src/toolbloat/cli.py +439 -0
  11. toolbloat-0.2.0/src/toolbloat/config.py +175 -0
  12. toolbloat-0.2.0/src/toolbloat/data/demo/results.json +3677 -0
  13. toolbloat-0.2.0/src/toolbloat/discover.py +100 -0
  14. toolbloat-0.2.0/src/toolbloat/errors.py +25 -0
  15. toolbloat-0.2.0/src/toolbloat/evaluate.py +245 -0
  16. toolbloat-0.2.0/src/toolbloat/intents.py +167 -0
  17. toolbloat-0.2.0/src/toolbloat/llm.py +261 -0
  18. toolbloat-0.2.0/src/toolbloat/metrics.py +197 -0
  19. toolbloat-0.2.0/src/toolbloat/py.typed +0 -0
  20. toolbloat-0.2.0/src/toolbloat/report.py +67 -0
  21. toolbloat-0.2.0/src/toolbloat/templates/report.html.j2 +376 -0
  22. toolbloat-0.2.0/src/toolbloat/terminal.py +132 -0
  23. toolbloat-0.2.0/src/toolbloat/tokens.py +55 -0
  24. toolbloat-0.2.0/tests/conftest.py +60 -0
  25. toolbloat-0.2.0/tests/fixtures/tiny_server.py +23 -0
  26. toolbloat-0.2.0/tests/test_cli.py +116 -0
  27. toolbloat-0.2.0/tests/test_config.py +84 -0
  28. toolbloat-0.2.0/tests/test_discover.py +14 -0
  29. toolbloat-0.2.0/tests/test_evaluate.py +72 -0
  30. toolbloat-0.2.0/tests/test_intents.py +31 -0
  31. toolbloat-0.2.0/tests/test_llm.py +108 -0
  32. toolbloat-0.2.0/tests/test_metrics_report.py +78 -0
  33. toolbloat-0.2.0/tests/test_tokens.py +16 -0
@@ -0,0 +1,15 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ .pytest_cache/
8
+ .ruff_cache/
9
+ .env
10
+ .env.*
11
+ !.env.example
12
+ .toolbloat/
13
+ toolbloat-report/
14
+ .DS_Store
15
+ toolbloat-demo/
@@ -0,0 +1,48 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
5
+ [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [0.2.0] - 2026-11-04
8
+
9
+ ### Added
10
+ - GitHub Action (`uses: diegoperezg7/toolbloat@v0.2.0`): counts the tokens of the MCP tool
11
+ definitions in a config, writes the table to the job summary and fails over `max-tokens`.
12
+ No model calls, no keys.
13
+ - `toolbloat tokens --max-tokens N`: exit code 2 when the total is over the budget, 1 when a server
14
+ could not be measured.
15
+ - `toolbloat tokens --markdown FILE`: append a Markdown summary (for `$GITHUB_STEP_SUMMARY`).
16
+
17
+ ## [0.1.1] - 2026-11-03
18
+
19
+ ### Changed
20
+ - The privacy prompt before sending anything to a cloud provider now lists every server that will be
21
+ sent, the config file it came from (or `--server`), its command and the provider, and refuses
22
+ without `--yes` when there is no interactive terminal. `toolbloat intents` asks too.
23
+ - The HTML report formats numbers, percentages and amounts for the active language
24
+ (English `6,064` / `$2.73`, Spanish `6.064` / `2,73 US$`).
25
+
26
+ ## [0.1.0] - 2026-11-03
27
+
28
+ ### Added
29
+ - `toolbloat tokens`: start MCP servers over stdio (official MCP Python SDK), list their tools and
30
+ count definition tokens per tool, per server and in total (tiktoken o200k, approximate).
31
+ - `toolbloat intents`: write one or more realistic requests per tool with a model, cached in an
32
+ editable YAML file.
33
+ - `toolbloat run`: ask each model which tool it would call, with only the tool's own server and with
34
+ the whole stack. Reports selection accuracy, argument validity against the JSON Schema, a
35
+ cross-server confusion matrix, tools no model chose, tokens saved by removing them and a monthly
36
+ token and cost projection. Tools are never executed.
37
+ - `toolbloat report`: rebuild the HTML report from `results.json`.
38
+ - `toolbloat demo`: a recorded real run on six MCP reference servers, no keys needed.
39
+ - Before sending tool definitions to a cloud provider, lists the servers and the provider and asks
40
+ for confirmation (`--yes` to skip, required without a terminal).
41
+ - Reads `.mcp.json`, Cursor and Claude Desktop configs (command and args only, `env` is never shown).
42
+ - Providers: Ollama, Mistral, OpenRouter, OpenAI through one OpenAI-compatible client, with
43
+ `--max-cost`, backoff on rate limits and a resumable call cache.
44
+ - Static HTML report in English and Spanish, light and dark, mobile friendly.
45
+
46
+ [0.2.0]: https://github.com/diegoperezg7/toolbloat/releases/tag/v0.2.0
47
+ [0.1.1]: https://github.com/diegoperezg7/toolbloat/releases/tag/v0.1.1
48
+ [0.1.0]: https://github.com/diegoperezg7/toolbloat/releases/tag/v0.1.0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Diego Pérez
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.
toolbloat-0.2.0/NOTICE ADDED
@@ -0,0 +1,232 @@
1
+ toolbloat
2
+ Copyright (c) 2026 Diego Pérez. Licensed under the MIT License (see LICENSE).
3
+
4
+ This repository and the toolbloat wheel include third-party material:
5
+
6
+ - src/toolbloat/data/demo/results.json, docs/index.html and the screenshots/GIF in docs/assets
7
+ contain tool names, descriptions and JSON Schemas returned by the MCP reference servers
8
+ (@modelcontextprotocol/server-filesystem 2.1.0, server-memory 2.0.1, server-everything 2.1.0,
9
+ server-sequential-thinking 2.0.0, mcp-server-time 2026.10.28, mcp-server-fetch 2026.10.28),
10
+ from https://github.com/modelcontextprotocol/servers
11
+ - examples/reference-stack.mcp.json names those packages.
12
+
13
+ No code from those servers is included. Their license, reproduced verbatim from
14
+ https://github.com/modelcontextprotocol/servers/blob/main/LICENSE (retrieved 2026-11-03):
15
+
16
+ --------------------------------------------------------------------------------
17
+ The MCP project is undergoing a licensing transition from the MIT License to the Apache License, Version 2.0 ("Apache-2.0"). All new code and specification contributions to the project are licensed under Apache-2.0. Documentation contributions (excluding specifications) are licensed under CC-BY-4.0.
18
+
19
+ Contributions for which relicensing consent has been obtained are licensed under Apache-2.0. Contributions made by authors who originally licensed their work under the MIT License and who have not yet granted explicit permission to relicense remain licensed under the MIT License.
20
+
21
+ No rights beyond those granted by the applicable original license are conveyed for such contributions.
22
+
23
+ ---
24
+
25
+ Apache License
26
+ Version 2.0, January 2004
27
+ http://www.apache.org/licenses/
28
+
29
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
30
+
31
+ 1. Definitions.
32
+
33
+ "License" shall mean the terms and conditions for use, reproduction,
34
+ and distribution as defined by Sections 1 through 9 of this document.
35
+
36
+ "Licensor" shall mean the copyright owner or entity authorized by
37
+ the copyright owner that is granting the License.
38
+
39
+ "Legal Entity" shall mean the union of the acting entity and all
40
+ other entities that control, are controlled by, or are under common
41
+ control with that entity. For the purposes of this definition,
42
+ "control" means (i) the power, direct or indirect, to cause the
43
+ direction or management of such entity, whether by contract or
44
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
45
+ outstanding shares, or (iii) beneficial ownership of such entity.
46
+
47
+ "You" (or "Your") shall mean an individual or Legal Entity
48
+ exercising permissions granted by this License.
49
+
50
+ "Source" form shall mean the preferred form for making modifications,
51
+ including but not limited to software source code, documentation
52
+ source, and configuration files.
53
+
54
+ "Object" form shall mean any form resulting from mechanical
55
+ transformation or translation of a Source form, including but
56
+ not limited to compiled object code, generated documentation,
57
+ and conversions to other media types.
58
+
59
+ "Work" shall mean the work of authorship, whether in Source or
60
+ Object form, made available under the License, as indicated by a
61
+ copyright notice that is included in or attached to the work
62
+ (an example is provided in the Appendix below).
63
+
64
+ "Derivative Works" shall mean any work, whether in Source or Object
65
+ form, that is based on (or derived from) the Work and for which the
66
+ editorial revisions, annotations, elaborations, or other modifications
67
+ represent, as a whole, an original work of authorship. For the purposes
68
+ of this License, Derivative Works shall not include works that remain
69
+ separable from, or merely link (or bind by name) to the interfaces of,
70
+ the Work and Derivative Works thereof.
71
+
72
+ "Contribution" shall mean any work of authorship, including
73
+ the original version of the Work and any modifications or additions
74
+ to that Work or Derivative Works thereof, that is intentionally
75
+ submitted to the Licensor for inclusion in the Work by the copyright
76
+ owner or by an individual or Legal Entity authorized to submit on behalf
77
+ of the copyright owner. For the purposes of this definition, "submitted"
78
+ means any form of electronic, verbal, or written communication sent
79
+ to the Licensor or its representatives, including but not limited to
80
+ communication on electronic mailing lists, source code control systems,
81
+ and issue tracking systems that are managed by, or on behalf of, the
82
+ Licensor for the purpose of discussing and improving the Work, but
83
+ excluding communication that is conspicuously marked or otherwise
84
+ designated in writing by the copyright owner as "Not a Contribution."
85
+
86
+ "Contributor" shall mean Licensor and any individual or Legal Entity
87
+ on behalf of whom a Contribution has been received by Licensor and
88
+ subsequently incorporated within the Work.
89
+
90
+ 2. Grant of Copyright License. Subject to the terms and conditions of
91
+ this License, each Contributor hereby grants to You a perpetual,
92
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
93
+ copyright license to reproduce, prepare Derivative Works of,
94
+ publicly display, publicly perform, sublicense, and distribute the
95
+ Work and such Derivative Works in Source or Object form.
96
+
97
+ 3. Grant of Patent License. Subject to the terms and conditions of
98
+ this License, each Contributor hereby grants to You a perpetual,
99
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
100
+ (except as stated in this section) patent license to make, have made,
101
+ use, offer to sell, sell, import, and otherwise transfer the Work,
102
+ where such license applies only to those patent claims licensable
103
+ by such Contributor that are necessarily infringed by their
104
+ Contribution(s) alone or by combination of their Contribution(s)
105
+ with the Work to which such Contribution(s) was submitted. If You
106
+ institute patent litigation against any entity (including a
107
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
108
+ or a Contribution incorporated within the Work constitutes direct
109
+ or contributory patent infringement, then any patent licenses
110
+ granted to You under this License for that Work shall terminate
111
+ as of the date such litigation is filed.
112
+
113
+ 4. Redistribution. You may reproduce and distribute copies of the
114
+ Work or Derivative Works thereof in any medium, with or without
115
+ modifications, and in Source or Object form, provided that You
116
+ meet the following conditions:
117
+
118
+ (a) You must give any other recipients of the Work or
119
+ Derivative Works a copy of this License; and
120
+
121
+ (b) You must cause any modified files to carry prominent notices
122
+ stating that You changed the files; and
123
+
124
+ (c) You must retain, in the Source form of any Derivative Works
125
+ that You distribute, all copyright, patent, trademark, and
126
+ attribution notices from the Source form of the Work,
127
+ excluding those notices that do not pertain to any part of
128
+ the Derivative Works; and
129
+
130
+ (d) If the Work includes a "NOTICE" text file as part of its
131
+ distribution, then any Derivative Works that You distribute must
132
+ include a readable copy of the attribution notices contained
133
+ within such NOTICE file, excluding those notices that do not
134
+ pertain to any part of the Derivative Works, in at least one
135
+ of the following places: within a NOTICE text file distributed
136
+ as part of the Derivative Works; within the Source form or
137
+ documentation, if provided along with the Derivative Works; or,
138
+ within a display generated by the Derivative Works, if and
139
+ wherever such third-party notices normally appear. The contents
140
+ of the NOTICE file are for informational purposes only and
141
+ do not modify the License. You may add Your own attribution
142
+ notices within Derivative Works that You distribute, alongside
143
+ or as an addendum to the NOTICE text from the Work, provided
144
+ that such additional attribution notices cannot be construed
145
+ as modifying the License.
146
+
147
+ You may add Your own copyright statement to Your modifications and
148
+ may provide additional or different license terms and conditions
149
+ for use, reproduction, or distribution of Your modifications, or
150
+ for any such Derivative Works as a whole, provided Your use,
151
+ reproduction, and distribution of the Work otherwise complies with
152
+ the conditions stated in this License.
153
+
154
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
155
+ any Contribution intentionally submitted for inclusion in the Work
156
+ by You to the Licensor shall be under the terms and conditions of
157
+ this License, without any additional terms or conditions.
158
+ Notwithstanding the above, nothing herein shall supersede or modify
159
+ the terms of any separate license agreement you may have executed
160
+ with Licensor regarding such Contributions.
161
+
162
+ 6. Trademarks. This License does not grant permission to use the trade
163
+ names, trademarks, service marks, or product names of the Licensor,
164
+ except as required for reasonable and customary use in describing the
165
+ origin of the Work and reproducing the content of the NOTICE file.
166
+
167
+ 7. Disclaimer of Warranty. Unless required by applicable law or
168
+ agreed to in writing, Licensor provides the Work (and each
169
+ Contributor provides its Contributions) on an "AS IS" BASIS,
170
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
171
+ implied, including, without limitation, any warranties or conditions
172
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
173
+ PARTICULAR PURPOSE. You are solely responsible for determining the
174
+ appropriateness of using or redistributing the Work and assume any
175
+ risks associated with Your exercise of permissions under this License.
176
+
177
+ 8. Limitation of Liability. In no event and under no legal theory,
178
+ whether in tort (including negligence), contract, or otherwise,
179
+ unless required by applicable law (such as deliberate and grossly
180
+ negligent acts) or agreed to in writing, shall any Contributor be
181
+ liable to You for damages, including any direct, indirect, special,
182
+ incidental, or consequential damages of any character arising as a
183
+ result of this License or out of the use or inability to use the
184
+ Work (including but not limited to damages for loss of goodwill,
185
+ work stoppage, computer failure or malfunction, or any and all
186
+ other commercial damages or losses), even if such Contributor
187
+ has been advised of the possibility of such damages.
188
+
189
+ 9. Accepting Warranty or Additional Liability. While redistributing
190
+ the Work or Derivative Works thereof, You may choose to offer,
191
+ and charge a fee for, acceptance of support, warranty, indemnity,
192
+ or other liability obligations and/or rights consistent with this
193
+ License. However, in accepting such obligations, You may act only
194
+ on Your own behalf and on Your sole responsibility, not on behalf
195
+ of any other Contributor, and only if You agree to indemnify,
196
+ defend, and hold each Contributor harmless for any liability
197
+ incurred by, or claims asserted against, such Contributor by reason
198
+ of your accepting any such warranty or additional liability.
199
+
200
+ END OF TERMS AND CONDITIONS
201
+
202
+ ---
203
+
204
+ MIT License
205
+
206
+ Copyright (c) 2024-2025 Model Context Protocol a Series of LF Projects, LLC.
207
+
208
+ Permission is hereby granted, free of charge, to any person obtaining a copy
209
+ of this software and associated documentation files (the "Software"), to deal
210
+ in the Software without restriction, including without limitation the rights
211
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
212
+ copies of the Software, and to permit persons to whom the Software is
213
+ furnished to do so, subject to the following conditions:
214
+
215
+ The above copyright notice and this permission notice shall be included in all
216
+ copies or substantial portions of the Software.
217
+
218
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
219
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
220
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
221
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
222
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
223
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
224
+ SOFTWARE.
225
+
226
+ ---
227
+
228
+ Creative Commons Attribution 4.0 International (CC-BY-4.0)
229
+
230
+ Documentation in this project (excluding specifications) is licensed under
231
+ CC-BY-4.0. See https://creativecommons.org/licenses/by/4.0/legalcode for
232
+ the full license text.
@@ -0,0 +1,296 @@
1
+ Metadata-Version: 2.5
2
+ Name: toolbloat
3
+ Version: 0.2.0
4
+ Summary: See what your MCP servers cost in tokens on every turn, and whether stacking them makes your model pick the wrong tool.
5
+ Project-URL: Homepage, https://github.com/diegoperezg7/toolbloat
6
+ Project-URL: Report, https://diegoperezg7.github.io/toolbloat/
7
+ Project-URL: Issues, https://github.com/diegoperezg7/toolbloat/issues
8
+ Author: Diego Pérez
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ License-File: NOTICE
12
+ Keywords: agents,evaluation,llm,mcp,model-context-protocol,tokens,tool-calling
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Testing
22
+ Requires-Python: >=3.11
23
+ Requires-Dist: jinja2==3.1.6
24
+ Requires-Dist: jsonschema==4.26.0
25
+ Requires-Dist: mcp==2.3.0
26
+ Requires-Dist: openai==3.42.1
27
+ Requires-Dist: pyyaml==6.0.3
28
+ Requires-Dist: rich==15.0.0
29
+ Requires-Dist: tiktoken==0.14.0
30
+ Requires-Dist: typer==0.27.3
31
+ Description-Content-Type: text/markdown
32
+
33
+ <p align="center">
34
+ <picture>
35
+ <source media="(prefers-color-scheme: dark)" srcset="docs/assets/banner-dark.svg">
36
+ <img alt="toolbloat" src="docs/assets/banner-light.svg" width="640">
37
+ </picture>
38
+ </p>
39
+
40
+ <p align="center">
41
+ <a href="https://github.com/diegoperezg7/toolbloat/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/diegoperezg7/toolbloat/actions/workflows/ci.yml/badge.svg"></a>
42
+ <a href="LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-8f3bb3.svg"></a>
43
+ <a href="https://github.com/diegoperezg7/toolbloat/releases"><img alt="Release" src="https://img.shields.io/github/v/release/diegoperezg7/toolbloat?color=8f3bb3"></a>
44
+ <a href="https://github.com/diegoperezg7/toolbloat/stargazers"><img alt="Stars" src="https://img.shields.io/github/stars/diegoperezg7/toolbloat?style=flat&color=8f3bb3"></a>
45
+ </p>
46
+
47
+ <p align="center"><b>See what your MCP servers cost in tokens on every turn, and whether stacking them makes your model pick the wrong tool.</b></p>
48
+
49
+ <p align="center"><a href="README.es.md">Leer en español</a> · <a href="https://diegoperezg7.github.io/toolbloat/">Example report</a></p>
50
+
51
+ <p align="center"><img alt="toolbloat demo in a terminal" src="docs/assets/demo.gif" width="760"></p>
52
+
53
+ ## Why
54
+
55
+ Every MCP server you connect sends its tool definitions to the model on every turn. Tools exist to
56
+ see that cost: Claude Code shows MCP tool tokens in [`/context`](https://code.claude.com/docs/en/slash-commands),
57
+ [mcp-bloat](https://github.com/pranayasharma/mcp-bloat) audits them per server, and
58
+ [mcp-compressor](https://github.com/atlassian-labs/mcp-compressor) or
59
+ [squeez](https://github.com/claudioemmanuel/squeez) shrink them. Tools also exist to check one
60
+ server's tool descriptions: [toolfit](https://github.com/sreshtalluri/toolfit) and
61
+ [toolscore](https://github.com/Aryan-MP/toolscore) find which tools of *a* server confuse a model,
62
+ and [LiveMCPBench](https://github.com/icip-cas/LiveMCPBench) is a fixed benchmark over a large toolset.
63
+
64
+ None of them answers the question you have once you run five servers at once: **does stacking
65
+ them make my model pick the wrong tool, how much does that depend on the model, and what am I
66
+ paying per turn for it?** toolbloat measures exactly that, on your own stack:
67
+
68
+ - tokens per tool, per server and in total, plus the prompt tokens each provider actually bills;
69
+ - selection accuracy per model with **only the tool's own server** loaded vs. **the whole stack**;
70
+ - which requests stacking breaks, and a **cross-server confusion matrix**;
71
+ - whether the arguments the model proposes validate against the tool's JSON Schema;
72
+ - tools no model chose, the tokens you would save by removing them, and a monthly projection.
73
+
74
+ Tools are **never executed**: toolbloat only reads the tool call the model proposes.
75
+
76
+ ## Quickstart
77
+
78
+ See a recorded real run, no keys and no setup (needs [uv](https://docs.astral.sh/uv/)):
79
+
80
+ ```bash
81
+ uvx --from git+https://github.com/diegoperezg7/toolbloat@v0.2.0 toolbloat demo --open
82
+ ```
83
+
84
+ or from a clone:
85
+
86
+ ```bash
87
+ git clone https://github.com/diegoperezg7/toolbloat && cd toolbloat && uv run toolbloat demo --open
88
+ ```
89
+
90
+ `uvx toolbloat` is coming to PyPI.
91
+
92
+ Then measure your own stack:
93
+
94
+ ```bash
95
+ # tokens only, no model calls: reads ./.mcp.json, Cursor and Claude Desktop configs
96
+ toolbloat tokens
97
+
98
+ # full run with a local model (nothing leaves your machine)
99
+ toolbloat run -m ollama:qwen3:4b-16k
100
+
101
+ # or compare several models (keys from env vars), capped at 1 USD
102
+ toolbloat run -m ollama:qwen3:4b-16k -m mistral:ministral-8b-latest -m mistral:mistral-small-latest --max-cost 1
103
+ ```
104
+
105
+ ## Example output
106
+
107
+ <!-- demo:start -->
108
+ ```text
109
+ $ toolbloat demo
110
+ Recorded run from 2026-11-03 · toolbloat 0.1.0 · Apple M4, 16 GB RAM, macOS 27.2
111
+ This replays a real `toolbloat run`; nothing is executed now. Measure your own stack with `toolbloat
112
+ run`.
113
+ Tokens per server (o200k, approx.)
114
+ ┏━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━┳━━━━━━━┓
115
+ ┃ server ┃ tools ┃ tokens ┃ share ┃
116
+ ┡━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━╇━━━━━━━┩
117
+ │ everything │ 16 │ 1,825 │ 30% │
118
+ │ filesystem │ 14 │ 1,806 │ 30% │
119
+ │ memory │ 9 │ 1,045 │ 17% │
120
+ │ thinking │ 1 │ 873 │ 14% │
121
+ │ time │ 2 │ 281 │ 5% │
122
+ │ fetch │ 1 │ 234 │ 4% │
123
+ ├────────────┼───────┼────────┼───────┤
124
+ │ total │ 43 │ 6,064 │ 100% │
125
+ └────────────┴───────┴────────┴───────┘
126
+ Every turn re-sends ~6,064 tokens of tool definitions: ~18.2M tokens/month at 100 turns/day (before
127
+ prompt caching).
128
+ Tool selection accuracy (alone vs. whole stack)
129
+ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┓
130
+ ┃ model ┃ alone ┃ stacked ┃ change ┃ broken ┃ args ok ┃ $/month ┃
131
+ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━┩
132
+ │ mistral:ministral-8b-latest │ 86% │ 72% │ -14 pts │ 6 │ 100% │ $2.73 │
133
+ │ mistral:ministral-14b-latest │ 91% │ 86% │ -5 pts │ 2 │ 100% │ $3.64 │
134
+ └──────────────────────────────┴───────┴─────────┴─────────┴────────┴─────────┴─────────┘
135
+ broken = right alone, wrong with the whole stack · args ok = correct calls whose arguments match the
136
+ JSON Schema
137
+ Most common wrong picks with the whole stack
138
+ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┓
139
+ ┃ expected ┃ model chose ┃ times ┃
140
+ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━┩
141
+ │ memory/create_relations │ memory/create_entities │ 2 │
142
+ │ filesystem/write_file │ filesystem/create_directory │ 2 │
143
+ │ memory/delete_observations │ memory/search_nodes │ 2 │
144
+ │ filesystem/edit_file │ filesystem/read_text_file │ 2 │
145
+ │ filesystem/list_directory_with_sizes │ filesystem/list_allowed_directories │ 2 │
146
+ │ filesystem/read_file │ filesystem/list_allowed_directories │ 1 │
147
+ │ filesystem/read_text_file │ filesystem/list_allowed_directories │ 1 │
148
+ │ filesystem/read_media_file │ filesystem/search_files │ 1 │
149
+ └──────────────────────────────────────┴─────────────────────────────────────┴───────┘
150
+ 5 tool(s) were never chosen with the whole stack: filesystem/edit_file, memory/create_relations,
151
+ filesystem/list_directory_with_sizes, memory/delete_observations, filesystem/write_file. Removing
152
+ them saves ~690 tokens per turn (~2.1M/month).
153
+ API cost of the calls in this report: $0.1447
154
+ ```
155
+ <!-- demo:end -->
156
+
157
+ The full report for this run is at **<https://diegoperezg7.github.io/toolbloat/>**.
158
+
159
+ <p align="center">
160
+ <img alt="toolbloat HTML report, light" src="docs/assets/report-light.png" width="49%">
161
+ <img alt="toolbloat HTML report, dark" src="docs/assets/report-dark.png" width="49%">
162
+ </p>
163
+
164
+ ## Use it in CI
165
+
166
+ A GitHub Action keeps the token cost of your MCP stack, or of the MCP server you maintain, from
167
+ growing unnoticed. It starts the stdio servers in your config, counts their tool definitions, writes
168
+ the table to the job summary and fails the job when the total goes over `max-tokens`. It never calls
169
+ a model and needs no keys.
170
+
171
+ ```yaml
172
+ # .github/workflows/mcp-tokens.yml
173
+ on: [pull_request]
174
+ jobs:
175
+ tokens:
176
+ runs-on: ubuntu-latest
177
+ steps:
178
+ - uses: actions/checkout@v7
179
+ - uses: diegoperezg7/toolbloat@v0.2.0
180
+ with:
181
+ config: .mcp.json # space-separated list of config files
182
+ max-tokens: "8000" # leave empty to only report
183
+ ```
184
+
185
+ On the six reference servers of the demo the summary reads 6,064 tokens, so a budget of 5,000
186
+ fails by 1,064. The same check runs locally:
187
+
188
+ ```bash
189
+ toolbloat tokens --config .mcp.json --max-tokens 8000 # exit 2 if over, 1 if a server cannot be measured
190
+ ```
191
+
192
+ The action runs the server commands from the config in the repository it checks out. On pull
193
+ requests from forks GitHub gives the job no secrets, but those commands still run: review config
194
+ changes as you would review code.
195
+
196
+ ## How it works
197
+
198
+ ```mermaid
199
+ flowchart LR
200
+ A[".mcp.json / Cursor /<br>Claude Desktop / --server"] --> B["start each server<br>over stdio"]
201
+ B --> C["tools/list<br>(never tools/call)"]
202
+ C --> D["count tokens<br>per tool and server"]
203
+ C --> E["intents.yaml<br>1+ request per tool<br>(LLM-written, editable)"]
204
+ E --> F{"each model, each request"}
205
+ F -->|"only the tool's server"| G["alone"]
206
+ F -->|"every server"| H["stacked"]
207
+ G --> I["accuracy, broken by stacking,<br>confusion matrix, valid args,<br>never-chosen tools, $/month"]
208
+ H --> I
209
+ D --> I
210
+ I --> J["terminal summary +<br>static HTML report + results.json"]
211
+ ```
212
+
213
+ 1. **Discover.** Each server is started with the official MCP Python SDK (`mcp==2.3.0`) and asked
214
+ for `tools/list`. Only `command` and `args` are read from your configs for display; `env` is
215
+ passed to the server but never printed or saved.
216
+ 2. **Count.** Each tool is serialised as an OpenAI-style function (name, description, JSON Schema)
217
+ and counted with tiktoken `o200k_base`. Providers wrap tools in their own templates and
218
+ tokenizers, so this is **approximate**; the report also shows the prompt tokens each provider billed.
219
+ 3. **Write intents.** A model writes realistic requests for each tool (`.toolbloat/intents.yaml`).
220
+ They are cached; edit them, add `also_ok` for tools that are equally right, or `skip: true`.
221
+ 4. **Ask.** For every request, each model gets the same system prompt ("call exactly one tool") at
222
+ temperature 0, once with only the right server's tools and once with every tool. Answers are
223
+ cached in `toolbloat-report/calls.jsonl`, so interrupted runs resume for free.
224
+ 5. **Report.** `results.json`, a Rich summary in the terminal and a single-file HTML report.
225
+
226
+ ## Configuration
227
+
228
+ | Option | Default | What it does |
229
+ | --- | --- | --- |
230
+ | `-m, --model provider:model` | `ollama:qwen3:4b` | Repeatable. Providers: `ollama`, `mistral`, `openrouter`, `openai`. |
231
+ | `-c, --config PATH` | auto | `.mcp.json`, `.cursor/mcp.json`, `~/.cursor/mcp.json`, Claude Desktop config. Repeatable. |
232
+ | `-s, --server "name=cmd args"` | – | Add a server by hand. Repeatable. |
233
+ | `--intents PATH` | `.toolbloat/intents.yaml` | Cached, editable requests. |
234
+ | `--intent-model` | first `--model` | Model that writes missing intents. |
235
+ | `--intents-per-tool N` | `1` | More requests per tool = steadier numbers, more calls. |
236
+ | `--max-cost USD` | `1.0` | Checked before every call; the run stops with partial results. Local models cost 0. |
237
+ | `--price provider:model=IN,OUT` | – | USD per million tokens for a model without a built-in price. |
238
+ | `--turns-per-day N` | `100` | For the monthly projection. |
239
+ | `--out DIR` | `toolbloat-report` | `results.json`, `report.html`, `calls.jsonl`. |
240
+
241
+ Keys come only from environment variables: `MISTRAL_API_KEY`, `OPENROUTER_API_KEY`,
242
+ `OPENAI_API_KEY`. `OLLAMA_HOST` points to another Ollama. See [.env.example](.env.example).
243
+
244
+ **Ollama context window.** Ollama loads models with a small context window by default (4,096 tokens
245
+ for `qwen3:4b` here). A stack of a few servers is larger than that and gets cut silently;
246
+ toolbloat warns when a model bills fewer prompt tokens than the definitions. Create a variant with a
247
+ bigger window once (`num_ctx` 16384) and use it:
248
+
249
+ ```bash
250
+ printf 'FROM qwen3:4b\nPARAMETER num_ctx 16384\n' > Modelfile && ollama create qwen3:4b-16k -f Modelfile
251
+ ```
252
+
253
+ Tested with a partial run of `ollama:qwen3:4b-16k` (32 real calls on the reference stack; the largest prompt was 5,193
254
+ tokens, well under the 16,384 window). It is not in the recorded demo: a local 4B model with thinking took several
255
+ minutes per call on a shared 16 GB laptop.
256
+
257
+ **Privacy.** With a cloud provider, your tool definitions and the test requests are sent to it.
258
+ Before anything is sent, toolbloat lists the servers whose definitions will go out and the provider
259
+ they go to, and asks for confirmation; without a terminal (CI) it refuses unless you pass `--yes`.
260
+ With Ollama nothing leaves your machine. There is no telemetry. Running toolbloat starts the MCP
261
+ servers in your config, which is third-party code you already run with your agent: see
262
+ [SECURITY.md](SECURITY.md).
263
+
264
+ ## The demo data
265
+
266
+ `toolbloat demo` replays a real `toolbloat run` from 2026-11-03 on six servers from the
267
+ [MCP reference servers](https://github.com/modelcontextprotocol/servers), which start without
268
+ credentials: `server-filesystem`, `server-memory`, `server-everything`, `server-sequential-thinking`
269
+ (npm) and `mcp-server-time`, `mcp-server-fetch` (PyPI). They are published under MIT, with the
270
+ project moving new contributions to Apache-2.0 ([LICENSE](https://github.com/modelcontextprotocol/servers/blob/main/LICENSE)).
271
+ toolbloat does not bundle their code, only the tool definitions they returned.
272
+
273
+ Models in the recording: `mistral:ministral-8b-latest` and `mistral:ministral-14b-latest`, each on all 43 requests in both conditions (172 calls, 0.14 USD in total at list price). Requests were written by `ministral-8b-latest` and reviewed by hand. Third-party notices for the bundled tool definitions are in [NOTICE](NOTICE). The config is in
274
+ [`examples/reference-stack.mcp.json`](examples/reference-stack.mcp.json) and the reviewed intents in
275
+ [`examples/reference-stack.intents.yaml`](examples/reference-stack.intents.yaml).
276
+
277
+ ## Roadmap
278
+
279
+ - Execute tools in a sandbox to check results, not just the choice.
280
+ - Suggest description rewrites for the tools that get confused.
281
+ - HTTP and SSE transports.
282
+ - Compare a stack with and without a compressor such as mcp-compressor.
283
+
284
+ ## Part of a series
285
+
286
+ Open source tools that evaluate agents and LLMs on your own data:
287
+
288
+ - [memarena](https://github.com/diegoperezg7/memarena): Benchmark memory layers on your own conversations.
289
+ - [parsearena](https://github.com/diegoperezg7/parsearena): Compare PDF parsers side by side and their effect on retrieval.
290
+ - [commitarena](https://github.com/diegoperezg7/commitarena): Replay real bug fixes from your git history against any model.
291
+ - [rulelab](https://github.com/diegoperezg7/rulelab): Find which AGENTS.md rules earn their tokens.
292
+ - [doesitfire](https://github.com/diegoperezg7/doesitfire): Test whether your SKILL.md activates in Claude Code, Codex and OpenCode.
293
+
294
+ ## License
295
+
296
+ [MIT](LICENSE) © 2026 Diego Pérez