tool-tax 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.
- tool_tax-0.2.0/LICENSE +22 -0
- tool_tax-0.2.0/PKG-INFO +183 -0
- tool_tax-0.2.0/README.md +167 -0
- tool_tax-0.2.0/pyproject.toml +25 -0
- tool_tax-0.2.0/setup.cfg +4 -0
- tool_tax-0.2.0/src/tool_tax/__init__.py +3 -0
- tool_tax-0.2.0/src/tool_tax/cli.py +162 -0
- tool_tax-0.2.0/src/tool_tax/diff.py +149 -0
- tool_tax-0.2.0/src/tool_tax/extract.py +186 -0
- tool_tax-0.2.0/src/tool_tax/github_comment.py +73 -0
- tool_tax-0.2.0/src/tool_tax/model.py +64 -0
- tool_tax-0.2.0/src/tool_tax/report.py +149 -0
- tool_tax-0.2.0/src/tool_tax/tokenize.py +12 -0
- tool_tax-0.2.0/src/tool_tax.egg-info/PKG-INFO +183 -0
- tool_tax-0.2.0/src/tool_tax.egg-info/SOURCES.txt +20 -0
- tool_tax-0.2.0/src/tool_tax.egg-info/dependency_links.txt +1 -0
- tool_tax-0.2.0/src/tool_tax.egg-info/entry_points.txt +2 -0
- tool_tax-0.2.0/src/tool_tax.egg-info/requires.txt +1 -0
- tool_tax-0.2.0/src/tool_tax.egg-info/top_level.txt +1 -0
- tool_tax-0.2.0/tests/test_cli.py +95 -0
- tool_tax-0.2.0/tests/test_extract.py +82 -0
- tool_tax-0.2.0/tests/test_github_comment.py +25 -0
tool_tax-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sihyeon Jeon
|
|
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.
|
|
22
|
+
|
tool_tax-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tool-tax
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Measure the hidden token bill of MCP and agent tool catalogs.
|
|
5
|
+
Author: Sihyeon Jeon
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: mcp,agents,tool-calling,context-engineering,token-budget
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: PyYAML>=6.0
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# tool-tax
|
|
18
|
+
|
|
19
|
+
**See how many tokens your agent tools burn before the user even asks a question.**
|
|
20
|
+
|
|
21
|
+
`tool-tax` scans MCP-style tool catalogs, JSON/YAML tool manifests, and OpenAPI
|
|
22
|
+
files. It shows the full schema cost, ranks the heaviest tools, diffs catalog
|
|
23
|
+
changes in pull requests, and writes a slim tool index for progressive loading.
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pipx install git+https://github.com/SihyeonJeon/tool-tax.git@v0.2.0
|
|
27
|
+
|
|
28
|
+
tool-tax scan examples
|
|
29
|
+
tool-tax diff old-tools.json new-tools.json
|
|
30
|
+
tool-tax pack examples --out .tool-tax
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Example result:
|
|
34
|
+
|
|
35
|
+
```text
|
|
36
|
+
Tools: 7
|
|
37
|
+
Full tool tax: 1,144 est. tokens
|
|
38
|
+
Slim index: 309 est. tokens
|
|
39
|
+
Potential savings: 835 est. tokens (73.0%)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Why
|
|
43
|
+
|
|
44
|
+
Agents keep getting more tools. MCP servers, browser tools, GitHub tools,
|
|
45
|
+
database tools, and internal APIs all ship long schemas. If every schema is
|
|
46
|
+
loaded up front, your agent pays a context tax before it starts working.
|
|
47
|
+
|
|
48
|
+
`tool-tax` gives that tax a number.
|
|
49
|
+
|
|
50
|
+
## What It Does
|
|
51
|
+
|
|
52
|
+
- Finds tool definitions in JSON, YAML, and OpenAPI files.
|
|
53
|
+
- Estimates token cost for each tool schema.
|
|
54
|
+
- Ranks the most expensive tools.
|
|
55
|
+
- Diffs base/head catalogs for PR budget checks.
|
|
56
|
+
- Generates a slim `tool-index.json` plus separate schema files.
|
|
57
|
+
- Fails CI when the tool catalog grows past a budget.
|
|
58
|
+
- Posts or updates a GitHub PR report comment when configured.
|
|
59
|
+
|
|
60
|
+
## Install
|
|
61
|
+
|
|
62
|
+
From GitHub:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pipx install git+https://github.com/SihyeonJeon/tool-tax.git@v0.2.0
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
From a clone:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
git clone https://github.com/SihyeonJeon/tool-tax.git
|
|
72
|
+
cd tool-tax
|
|
73
|
+
python3 -m pip install -e .
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Installs one runtime dependency: `PyYAML`.
|
|
77
|
+
|
|
78
|
+
## Use
|
|
79
|
+
|
|
80
|
+
Scan a repo:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
tool-tax scan .
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Write Markdown and JSON reports:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
tool-tax scan examples --format md --out tool-tax-report.md
|
|
90
|
+
tool-tax scan examples --format json --out tool-tax-report.json
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Create a progressive-loading pack:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
tool-tax pack examples --out .tool-tax
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
That writes:
|
|
100
|
+
|
|
101
|
+
```text
|
|
102
|
+
.tool-tax/
|
|
103
|
+
tool-index.json # small always-load index
|
|
104
|
+
schemas/*.json # full schemas loaded only when needed
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Fail CI on tool bloat:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
tool-tax scan mcp-tools.json --max-tokens 12000 --max-tool-tokens 750
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Compare a pull request:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
tool-tax diff base-tools.json head-tools.json --max-delta-tokens 500
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Use it as a GitHub Action:
|
|
120
|
+
|
|
121
|
+
```yaml
|
|
122
|
+
- uses: SihyeonJeon/tool-tax@v0.2.0
|
|
123
|
+
with:
|
|
124
|
+
path: .
|
|
125
|
+
max-tokens: "12000"
|
|
126
|
+
max-tool-tokens: "750"
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Output
|
|
130
|
+
|
|
131
|
+
```md
|
|
132
|
+
# Tool Tax Report
|
|
133
|
+
|
|
134
|
+
Grade: **lean**
|
|
135
|
+
|
|
136
|
+
| Metric | Value |
|
|
137
|
+
| --- | ---: |
|
|
138
|
+
| Tools | 7 |
|
|
139
|
+
| Full tool tax | 1,144 est. tokens |
|
|
140
|
+
| Slim index | 309 est. tokens |
|
|
141
|
+
| Potential savings | 835 est. tokens (73.0%) |
|
|
142
|
+
| Worst tool | 255 est. tokens |
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Supports
|
|
146
|
+
|
|
147
|
+
- MCP-style JSON/YAML tool arrays
|
|
148
|
+
- Agent tool manifests with `name`, `description`, and `inputSchema`
|
|
149
|
+
- OpenAPI `paths` operations
|
|
150
|
+
- Nested JSON catalogs
|
|
151
|
+
- GitHub Step Summary and PR comment reports
|
|
152
|
+
|
|
153
|
+
## Repo Shape
|
|
154
|
+
|
|
155
|
+
```text
|
|
156
|
+
src/tool_tax/ # library + CLI
|
|
157
|
+
tests/ # unittest smoke coverage
|
|
158
|
+
examples/ # sample MCP/OpenAPI catalogs and reports
|
|
159
|
+
docs/ # trend scan and repo structure notes
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Claim
|
|
163
|
+
|
|
164
|
+
This tool does not compress prompts by itself. It measures the up-front schema
|
|
165
|
+
tax and creates a smaller index so your agent can load full schemas later.
|
|
166
|
+
|
|
167
|
+
It is the measuring tape and CI gate, not a runtime MCP proxy. Use it before or
|
|
168
|
+
alongside proxy/search tools such as MCP compressors, CLI adapters, and
|
|
169
|
+
progressive-disclosure gateways.
|
|
170
|
+
|
|
171
|
+
## More
|
|
172
|
+
|
|
173
|
+
- [Roadmap](ROADMAP.md)
|
|
174
|
+
- [Public scan gallery](docs/scans/README.md)
|
|
175
|
+
- [PyPI publish notes](docs/pypi-publish.md)
|
|
176
|
+
- [Star forecast and comparison set](docs/star-forecast-2026-05-17.md)
|
|
177
|
+
- [Launch kit](docs/launch-kit.md)
|
|
178
|
+
- [Trend scan](docs/trend-scan-2026-05-17.md)
|
|
179
|
+
- [Repo shape scan](docs/repo-shape-scan.md)
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
MIT
|
tool_tax-0.2.0/README.md
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# tool-tax
|
|
2
|
+
|
|
3
|
+
**See how many tokens your agent tools burn before the user even asks a question.**
|
|
4
|
+
|
|
5
|
+
`tool-tax` scans MCP-style tool catalogs, JSON/YAML tool manifests, and OpenAPI
|
|
6
|
+
files. It shows the full schema cost, ranks the heaviest tools, diffs catalog
|
|
7
|
+
changes in pull requests, and writes a slim tool index for progressive loading.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pipx install git+https://github.com/SihyeonJeon/tool-tax.git@v0.2.0
|
|
11
|
+
|
|
12
|
+
tool-tax scan examples
|
|
13
|
+
tool-tax diff old-tools.json new-tools.json
|
|
14
|
+
tool-tax pack examples --out .tool-tax
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Example result:
|
|
18
|
+
|
|
19
|
+
```text
|
|
20
|
+
Tools: 7
|
|
21
|
+
Full tool tax: 1,144 est. tokens
|
|
22
|
+
Slim index: 309 est. tokens
|
|
23
|
+
Potential savings: 835 est. tokens (73.0%)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Why
|
|
27
|
+
|
|
28
|
+
Agents keep getting more tools. MCP servers, browser tools, GitHub tools,
|
|
29
|
+
database tools, and internal APIs all ship long schemas. If every schema is
|
|
30
|
+
loaded up front, your agent pays a context tax before it starts working.
|
|
31
|
+
|
|
32
|
+
`tool-tax` gives that tax a number.
|
|
33
|
+
|
|
34
|
+
## What It Does
|
|
35
|
+
|
|
36
|
+
- Finds tool definitions in JSON, YAML, and OpenAPI files.
|
|
37
|
+
- Estimates token cost for each tool schema.
|
|
38
|
+
- Ranks the most expensive tools.
|
|
39
|
+
- Diffs base/head catalogs for PR budget checks.
|
|
40
|
+
- Generates a slim `tool-index.json` plus separate schema files.
|
|
41
|
+
- Fails CI when the tool catalog grows past a budget.
|
|
42
|
+
- Posts or updates a GitHub PR report comment when configured.
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
|
|
46
|
+
From GitHub:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pipx install git+https://github.com/SihyeonJeon/tool-tax.git@v0.2.0
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
From a clone:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
git clone https://github.com/SihyeonJeon/tool-tax.git
|
|
56
|
+
cd tool-tax
|
|
57
|
+
python3 -m pip install -e .
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Installs one runtime dependency: `PyYAML`.
|
|
61
|
+
|
|
62
|
+
## Use
|
|
63
|
+
|
|
64
|
+
Scan a repo:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
tool-tax scan .
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Write Markdown and JSON reports:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
tool-tax scan examples --format md --out tool-tax-report.md
|
|
74
|
+
tool-tax scan examples --format json --out tool-tax-report.json
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Create a progressive-loading pack:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
tool-tax pack examples --out .tool-tax
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
That writes:
|
|
84
|
+
|
|
85
|
+
```text
|
|
86
|
+
.tool-tax/
|
|
87
|
+
tool-index.json # small always-load index
|
|
88
|
+
schemas/*.json # full schemas loaded only when needed
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Fail CI on tool bloat:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
tool-tax scan mcp-tools.json --max-tokens 12000 --max-tool-tokens 750
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Compare a pull request:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
tool-tax diff base-tools.json head-tools.json --max-delta-tokens 500
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Use it as a GitHub Action:
|
|
104
|
+
|
|
105
|
+
```yaml
|
|
106
|
+
- uses: SihyeonJeon/tool-tax@v0.2.0
|
|
107
|
+
with:
|
|
108
|
+
path: .
|
|
109
|
+
max-tokens: "12000"
|
|
110
|
+
max-tool-tokens: "750"
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Output
|
|
114
|
+
|
|
115
|
+
```md
|
|
116
|
+
# Tool Tax Report
|
|
117
|
+
|
|
118
|
+
Grade: **lean**
|
|
119
|
+
|
|
120
|
+
| Metric | Value |
|
|
121
|
+
| --- | ---: |
|
|
122
|
+
| Tools | 7 |
|
|
123
|
+
| Full tool tax | 1,144 est. tokens |
|
|
124
|
+
| Slim index | 309 est. tokens |
|
|
125
|
+
| Potential savings | 835 est. tokens (73.0%) |
|
|
126
|
+
| Worst tool | 255 est. tokens |
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Supports
|
|
130
|
+
|
|
131
|
+
- MCP-style JSON/YAML tool arrays
|
|
132
|
+
- Agent tool manifests with `name`, `description`, and `inputSchema`
|
|
133
|
+
- OpenAPI `paths` operations
|
|
134
|
+
- Nested JSON catalogs
|
|
135
|
+
- GitHub Step Summary and PR comment reports
|
|
136
|
+
|
|
137
|
+
## Repo Shape
|
|
138
|
+
|
|
139
|
+
```text
|
|
140
|
+
src/tool_tax/ # library + CLI
|
|
141
|
+
tests/ # unittest smoke coverage
|
|
142
|
+
examples/ # sample MCP/OpenAPI catalogs and reports
|
|
143
|
+
docs/ # trend scan and repo structure notes
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Claim
|
|
147
|
+
|
|
148
|
+
This tool does not compress prompts by itself. It measures the up-front schema
|
|
149
|
+
tax and creates a smaller index so your agent can load full schemas later.
|
|
150
|
+
|
|
151
|
+
It is the measuring tape and CI gate, not a runtime MCP proxy. Use it before or
|
|
152
|
+
alongside proxy/search tools such as MCP compressors, CLI adapters, and
|
|
153
|
+
progressive-disclosure gateways.
|
|
154
|
+
|
|
155
|
+
## More
|
|
156
|
+
|
|
157
|
+
- [Roadmap](ROADMAP.md)
|
|
158
|
+
- [Public scan gallery](docs/scans/README.md)
|
|
159
|
+
- [PyPI publish notes](docs/pypi-publish.md)
|
|
160
|
+
- [Star forecast and comparison set](docs/star-forecast-2026-05-17.md)
|
|
161
|
+
- [Launch kit](docs/launch-kit.md)
|
|
162
|
+
- [Trend scan](docs/trend-scan-2026-05-17.md)
|
|
163
|
+
- [Repo shape scan](docs/repo-shape-scan.md)
|
|
164
|
+
|
|
165
|
+
## License
|
|
166
|
+
|
|
167
|
+
MIT
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tool-tax"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Measure the hidden token bill of MCP and agent tool catalogs."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [{name = "Sihyeon Jeon"}]
|
|
13
|
+
keywords = ["mcp", "agents", "tool-calling", "context-engineering", "token-budget"]
|
|
14
|
+
dependencies = ["PyYAML>=6.0"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Environment :: Console",
|
|
18
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.scripts]
|
|
22
|
+
tool-tax = "tool_tax.cli:main"
|
|
23
|
+
|
|
24
|
+
[tool.setuptools.packages.find]
|
|
25
|
+
where = ["src"]
|
tool_tax-0.2.0/setup.cfg
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from . import __version__
|
|
10
|
+
from .diff import dump_diff_json, to_diff_json, to_diff_markdown
|
|
11
|
+
from .extract import extract_tools
|
|
12
|
+
from .github_comment import DEFAULT_MARKER, resolve_pr_number, upsert_pr_comment
|
|
13
|
+
from .report import summarize, to_json, to_markdown, write_pack, write_report
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def parse_paths(values: list[str]) -> list[Path]:
|
|
17
|
+
return [Path(value) for value in values]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def append_step_summary(markdown: str) -> None:
|
|
21
|
+
summary_path = os.environ.get("GITHUB_STEP_SUMMARY")
|
|
22
|
+
if not summary_path:
|
|
23
|
+
print("WARNING: GITHUB_STEP_SUMMARY is not set", file=sys.stderr)
|
|
24
|
+
return
|
|
25
|
+
with Path(summary_path).open("a", encoding="utf-8") as fh:
|
|
26
|
+
fh.write(markdown.rstrip() + "\n")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def cmd_scan(args: argparse.Namespace) -> int:
|
|
30
|
+
records, errors = extract_tools(parse_paths(args.paths))
|
|
31
|
+
payload = to_json(records, errors) if args.format == "json" else to_markdown(records, errors)
|
|
32
|
+
write_report(payload, Path(args.out).resolve() if args.out else None)
|
|
33
|
+
if args.github_step_summary:
|
|
34
|
+
append_step_summary(to_markdown(records, errors))
|
|
35
|
+
summary = summarize(records)
|
|
36
|
+
failed = False
|
|
37
|
+
if args.max_tokens is not None and summary.total_tax_tokens > args.max_tokens:
|
|
38
|
+
failed = True
|
|
39
|
+
if args.max_tool_tokens is not None and summary.worst_tool_tokens > args.max_tool_tokens:
|
|
40
|
+
failed = True
|
|
41
|
+
if args.fail_on_grade:
|
|
42
|
+
ranks = {"lean": 0, "warm": 1, "expensive": 2, "brutal": 3}
|
|
43
|
+
failed = ranks[summary.grade] >= ranks[args.fail_on_grade]
|
|
44
|
+
return 2 if failed else 0
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def cmd_diff(args: argparse.Namespace) -> int:
|
|
48
|
+
base_records, base_errors = extract_tools([Path(args.base)])
|
|
49
|
+
head_records, head_errors = extract_tools([Path(args.head)])
|
|
50
|
+
errors = [f"base: {error}" for error in base_errors] + [f"head: {error}" for error in head_errors]
|
|
51
|
+
if args.format == "json":
|
|
52
|
+
payload = to_diff_json(base_records, head_records, errors)
|
|
53
|
+
write_report(dump_diff_json(payload), Path(args.out).resolve() if args.out else None)
|
|
54
|
+
else:
|
|
55
|
+
payload = to_diff_markdown(base_records, head_records, errors)
|
|
56
|
+
write_report(payload, Path(args.out).resolve() if args.out else None)
|
|
57
|
+
if args.github_step_summary:
|
|
58
|
+
append_step_summary(to_diff_markdown(base_records, head_records, errors))
|
|
59
|
+
summary = to_diff_json(base_records, head_records, errors)["summary"]
|
|
60
|
+
failed = False
|
|
61
|
+
if args.fail_on_increase and summary["delta_tax_tokens"] > 0:
|
|
62
|
+
failed = True
|
|
63
|
+
if args.max_delta_tokens is not None and summary["delta_tax_tokens"] > args.max_delta_tokens:
|
|
64
|
+
failed = True
|
|
65
|
+
if args.max_tool_delta_tokens is not None and summary["worst_tool_delta_tokens"] > args.max_tool_delta_tokens:
|
|
66
|
+
failed = True
|
|
67
|
+
return 2 if failed else 0
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def cmd_pack(args: argparse.Namespace) -> int:
|
|
71
|
+
records, errors = extract_tools(parse_paths(args.paths))
|
|
72
|
+
if errors and not args.ignore_errors:
|
|
73
|
+
for error in errors:
|
|
74
|
+
print(f"ERROR: {error}", file=sys.stderr)
|
|
75
|
+
return 1
|
|
76
|
+
write_pack(records, Path(args.out).resolve())
|
|
77
|
+
summary = summarize(records)
|
|
78
|
+
print(
|
|
79
|
+
f"packed {summary.tool_count} tools: "
|
|
80
|
+
f"{summary.total_tax_tokens:,} -> {summary.total_index_tokens:,} est. tokens "
|
|
81
|
+
f"({summary.estimated_savings_percent:.1f}% smaller)"
|
|
82
|
+
)
|
|
83
|
+
return 0
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def cmd_comment_pr(args: argparse.Namespace) -> int:
|
|
87
|
+
repo = args.repo or os.environ.get("GITHUB_REPOSITORY")
|
|
88
|
+
token = args.token or os.environ.get("GITHUB_TOKEN") or os.environ.get("GH_TOKEN")
|
|
89
|
+
pr_number = args.pr or resolve_pr_number()
|
|
90
|
+
report = Path(args.body_file).read_text(encoding="utf-8")
|
|
91
|
+
if args.dry_run:
|
|
92
|
+
print(json.dumps({"repo": repo, "pr": pr_number, "body": report}, ensure_ascii=False, indent=2))
|
|
93
|
+
return 0
|
|
94
|
+
missing = []
|
|
95
|
+
if not repo:
|
|
96
|
+
missing.append("--repo or GITHUB_REPOSITORY")
|
|
97
|
+
if not pr_number:
|
|
98
|
+
missing.append("--pr or pull_request event payload")
|
|
99
|
+
if not token:
|
|
100
|
+
missing.append("--token, GITHUB_TOKEN, or GH_TOKEN")
|
|
101
|
+
if missing:
|
|
102
|
+
print("ERROR: missing " + ", ".join(missing), file=sys.stderr)
|
|
103
|
+
return 1
|
|
104
|
+
result = upsert_pr_comment(repo, pr_number, report, token, args.marker)
|
|
105
|
+
print(f"{result['action']} PR comment: {result['url']}")
|
|
106
|
+
return 0
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
110
|
+
parser = argparse.ArgumentParser(
|
|
111
|
+
prog="tool-tax",
|
|
112
|
+
description="Measure the hidden token bill of MCP and agent tool catalogs.",
|
|
113
|
+
)
|
|
114
|
+
parser.add_argument("--version", action="version", version=f"tool-tax {__version__}")
|
|
115
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
116
|
+
|
|
117
|
+
scan = sub.add_parser("scan", help="scan JSON/OpenAPI/tool catalogs")
|
|
118
|
+
scan.add_argument("paths", nargs="+", help="files or directories to scan")
|
|
119
|
+
scan.add_argument("--format", choices=["md", "json"], default="md")
|
|
120
|
+
scan.add_argument("--out", help="write report to file")
|
|
121
|
+
scan.add_argument("--max-tokens", type=int, help="fail if total tool tax is above this")
|
|
122
|
+
scan.add_argument("--max-tool-tokens", type=int, help="fail if any one tool is above this")
|
|
123
|
+
scan.add_argument("--fail-on-grade", choices=["lean", "warm", "expensive", "brutal"])
|
|
124
|
+
scan.add_argument("--github-step-summary", action="store_true", help="append Markdown report to GitHub step summary")
|
|
125
|
+
scan.set_defaults(func=cmd_scan)
|
|
126
|
+
|
|
127
|
+
diff = sub.add_parser("diff", help="compare base and head tool catalogs")
|
|
128
|
+
diff.add_argument("base", help="base file or directory")
|
|
129
|
+
diff.add_argument("head", help="head file or directory")
|
|
130
|
+
diff.add_argument("--format", choices=["md", "json"], default="md")
|
|
131
|
+
diff.add_argument("--out", help="write diff report to file")
|
|
132
|
+
diff.add_argument("--fail-on-increase", action="store_true", help="fail if total tool tax increases")
|
|
133
|
+
diff.add_argument("--max-delta-tokens", type=int, help="fail if total token delta exceeds this")
|
|
134
|
+
diff.add_argument("--max-tool-delta-tokens", type=int, help="fail if one tool grows more than this")
|
|
135
|
+
diff.add_argument("--github-step-summary", action="store_true", help="append Markdown diff to GitHub step summary")
|
|
136
|
+
diff.set_defaults(func=cmd_diff)
|
|
137
|
+
|
|
138
|
+
pack = sub.add_parser("pack", help="write slim tool index and schema files")
|
|
139
|
+
pack.add_argument("paths", nargs="+", help="files or directories to scan")
|
|
140
|
+
pack.add_argument("--out", required=True, help="output directory")
|
|
141
|
+
pack.add_argument("--ignore-errors", action="store_true")
|
|
142
|
+
pack.set_defaults(func=cmd_pack)
|
|
143
|
+
|
|
144
|
+
comment = sub.add_parser("comment-pr", help="create or update a GitHub PR comment from a report")
|
|
145
|
+
comment.add_argument("--body-file", required=True, help="Markdown report file")
|
|
146
|
+
comment.add_argument("--repo", help="owner/repo, defaults to GITHUB_REPOSITORY")
|
|
147
|
+
comment.add_argument("--pr", type=int, help="pull request number")
|
|
148
|
+
comment.add_argument("--token", help="GitHub token, defaults to GITHUB_TOKEN or GH_TOKEN")
|
|
149
|
+
comment.add_argument("--marker", default=DEFAULT_MARKER, help="hidden marker for updating an existing comment")
|
|
150
|
+
comment.add_argument("--dry-run", action="store_true", help="print resolved comment payload without calling GitHub")
|
|
151
|
+
comment.set_defaults(func=cmd_comment_pr)
|
|
152
|
+
return parser
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def main(argv: list[str] | None = None) -> int:
|
|
156
|
+
parser = build_parser()
|
|
157
|
+
args = parser.parse_args(argv)
|
|
158
|
+
return args.func(args)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
if __name__ == "__main__":
|
|
162
|
+
raise SystemExit(main())
|