toolpreflight 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.
- toolpreflight-0.1.0/LICENSE +21 -0
- toolpreflight-0.1.0/PKG-INFO +142 -0
- toolpreflight-0.1.0/README.md +108 -0
- toolpreflight-0.1.0/pyproject.toml +71 -0
- toolpreflight-0.1.0/setup.cfg +4 -0
- toolpreflight-0.1.0/src/toolpreflight/__init__.py +36 -0
- toolpreflight-0.1.0/src/toolpreflight/__main__.py +8 -0
- toolpreflight-0.1.0/src/toolpreflight/analyzer.py +74 -0
- toolpreflight-0.1.0/src/toolpreflight/cli.py +224 -0
- toolpreflight-0.1.0/src/toolpreflight/compat.py +429 -0
- toolpreflight-0.1.0/src/toolpreflight/loaders.py +262 -0
- toolpreflight-0.1.0/src/toolpreflight/models.py +162 -0
- toolpreflight-0.1.0/src/toolpreflight/render.py +144 -0
- toolpreflight-0.1.0/src/toolpreflight/rules.py +333 -0
- toolpreflight-0.1.0/src/toolpreflight/stdio_probe.py +217 -0
- toolpreflight-0.1.0/src/toolpreflight/tokens.py +73 -0
- toolpreflight-0.1.0/src/toolpreflight.egg-info/PKG-INFO +142 -0
- toolpreflight-0.1.0/src/toolpreflight.egg-info/SOURCES.txt +24 -0
- toolpreflight-0.1.0/src/toolpreflight.egg-info/dependency_links.txt +1 -0
- toolpreflight-0.1.0/src/toolpreflight.egg-info/entry_points.txt +2 -0
- toolpreflight-0.1.0/src/toolpreflight.egg-info/requires.txt +13 -0
- toolpreflight-0.1.0/src/toolpreflight.egg-info/top_level.txt +1 -0
- toolpreflight-0.1.0/tests/test_compat.py +81 -0
- toolpreflight-0.1.0/tests/test_loaders.py +129 -0
- toolpreflight-0.1.0/tests/test_rules.py +76 -0
- toolpreflight-0.1.0/tests/test_stdio_and_cli.py +71 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 toolpreflight contributors
|
|
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.
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: toolpreflight
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Zero-dependency pre-flight linter, token auditor, cross-provider schema checker, and live stdio smoke-tester for MCP servers and AI agent tools.
|
|
5
|
+
Author: Open Source Contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Sarbojit10/toolpreflight
|
|
8
|
+
Project-URL: Repository, https://github.com/Sarbojit10/toolpreflight
|
|
9
|
+
Project-URL: Issues, https://github.com/Sarbojit10/toolpreflight/issues
|
|
10
|
+
Keywords: mcp,model-context-protocol,ai-agents,llm,json-schema,openai,gemini,anthropic,linter,devtools
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
20
|
+
Classifier: Topic :: Software Development :: Testing
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Provides-Extra: tiktoken
|
|
25
|
+
Requires-Dist: tiktoken>=0.7.0; extra == "tiktoken"
|
|
26
|
+
Provides-Extra: rich
|
|
27
|
+
Requires-Dist: rich>=13.0.0; extra == "rich"
|
|
28
|
+
Provides-Extra: pydantic
|
|
29
|
+
Requires-Dist: pydantic>=2.0.0; extra == "pydantic"
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: ruff>=0.6.0; extra == "dev"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# toolpreflight
|
|
36
|
+
|
|
37
|
+
**Zero-dependency pre-flight linter, context-token auditor, cross-provider schema checker, and live stdio probe for MCP servers & AI agent tools.**
|
|
38
|
+
|
|
39
|
+
AI agents fail silently when tool schemas are vague, redundant, oversized, missing safety annotations, or incompatible with a target LLM provider's structured-output / function-calling rules. `toolpreflight` catches those issues in milliseconds—offline or against a live MCP `stdio` server—before your users or CI hit `400 Bad Request` or tool-selection errors.
|
|
40
|
+
|
|
41
|
+
## Why `toolpreflight`?
|
|
42
|
+
|
|
43
|
+
- **Zero mandatory dependencies:** Pure Python 3.10+ stdlib core (with automatic `tiktoken` and `rich` enhancement if installed).
|
|
44
|
+
- **Format-agnostic:** Inspects MCP `tools/list` JSON, OpenAI `tools`, Anthropic `tools`, Gemini `functionDeclarations`, Python files (typed functions & Pydantic models), or live MCP `stdio` servers.
|
|
45
|
+
- **Context-window budget guard:** Measures per-tool and total token overhead (`--max-tokens`) so tool schemas don't quietly eat your prompt budget.
|
|
46
|
+
- **Cross-provider compatibility:** Validates schemas against **OpenAI Strict** (`strict: true`), **Gemini**, **Anthropic**, and **Local GBNF** (Ollama / llama.cpp) constraints.
|
|
47
|
+
- **Auto-normalization (`fix`):** Compiles schemas for a target provider (inlining `$defs`/`$ref`, enforcing `additionalProperties: false`, and preserving stripped constraint ranges in descriptions).
|
|
48
|
+
- **CI-native:** Supports `--format text | json | markdown` and `--fail-on error | warning`.
|
|
49
|
+
|
|
50
|
+
## Quickstart
|
|
51
|
+
|
|
52
|
+
Install locally in editable mode:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install -e .
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 1. Audit a tool manifest (MCP, OpenAI, Anthropic, Gemini, or Python module)
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
toolpreflight check examples/sample_mcp_tools.json --target openai_strict,gemini,anthropic --max-tokens 2000
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 2. Probe a live MCP `stdio` server
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
toolpreflight probe --stdio "python examples/demo_mcp_server.py"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Pass `--smoke-invalid` to safely send malformed/empty arguments **only** to tools marked `readOnlyHint: true` and verify the server returns a clean protocol error instead of crashing.
|
|
71
|
+
|
|
72
|
+
### 3. Normalize schemas for a target provider
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
toolpreflight fix examples/sample_mcp_tools.json --target openai_strict -o fixed_tools.json
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 4. Generate a GitHub PR Markdown report in CI
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
toolpreflight check tools.json --format markdown --fail-on error
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Example Output
|
|
85
|
+
|
|
86
|
+
Running `toolpreflight check examples/sample_mcp_tools.json --fail-on none`:
|
|
87
|
+
|
|
88
|
+
```text
|
|
89
|
+
toolpreflight report | source: examples/sample_mcp_tools.json
|
|
90
|
+
====================================================================
|
|
91
|
+
Grade: F | Tools: 2 | Context Tax: ~300 tokens
|
|
92
|
+
Findings: 8 error(s), 7 warning(s)
|
|
93
|
+
|
|
94
|
+
Provider Compatibility:
|
|
95
|
+
[FAIL] openai_strict errors=4 warnings=2
|
|
96
|
+
[FAIL] gemini errors=3 warnings=0
|
|
97
|
+
[PASS] anthropic errors=0 warnings=0
|
|
98
|
+
[PASS] local_gbnf errors=0 warnings=0
|
|
99
|
+
|
|
100
|
+
Token Breakdown (heaviest first):
|
|
101
|
+
- search_issues ~ 187 tok (desc=19, schema=156, heuristic)
|
|
102
|
+
- delete_issue_comment ~ 113 tok (desc=4, schema=95, heuristic)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Running `toolpreflight probe --stdio "python examples/demo_mcp_server.py" --target openai_strict,anthropic --smoke-invalid`:
|
|
106
|
+
|
|
107
|
+
```text
|
|
108
|
+
toolpreflight report | source: stdio:python examples/demo_mcp_server.py
|
|
109
|
+
====================================================================
|
|
110
|
+
Grade: A | Tools: 1 | Context Tax: ~95 tokens
|
|
111
|
+
Findings: 0 error(s), 0 warning(s)
|
|
112
|
+
Live Probe: demo-weather-mcp v0.1.0 (protocol 2024-11-05, init 81.55 ms, tools/list 0.51 ms)
|
|
113
|
+
- Smoke invalid probe [PASS] get_weather (tool_result)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Lint Rules
|
|
117
|
+
|
|
118
|
+
| Code | Severity | Description |
|
|
119
|
+
| --- | --- | --- |
|
|
120
|
+
| `TP001` | `error` | Tool is missing a description. |
|
|
121
|
+
| `TP002` | `warning` | Tool description is too short (`< 20` chars) or overly generic. |
|
|
122
|
+
| `TP003` | `error` | Missing `inputSchema` or root schema is not `"type": "object"`. |
|
|
123
|
+
| `TP004` | `warning` | Schema property is missing a `description`. |
|
|
124
|
+
| `TP005` | `error` | Array property is missing `items` definition. |
|
|
125
|
+
| `TP006` | `warning` | Schema nesting exceeds recommended depth (`> 4`). |
|
|
126
|
+
| `TP007` | `error` / `warning` | `required` references undefined properties, or object properties lack a `required` list. |
|
|
127
|
+
| `TP008` | `warning` | Mutating/destructive tool name lacks MCP safety annotations (`readOnlyHint` / `destructiveHint`). |
|
|
128
|
+
| `TP009` | `warning` | Single tool exceeds recommended per-tool token threshold (`> 500` tokens). |
|
|
129
|
+
| `TP010` | `warning` | High lexical overlap between two tools in the same server (risks LLM tool confusion). |
|
|
130
|
+
| `TP011` | `error` | Duplicate tool name detected in the manifest. |
|
|
131
|
+
|
|
132
|
+
## Running Tests
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
python -m unittest discover -s tests -v
|
|
136
|
+
# or with pytest:
|
|
137
|
+
pytest -v
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Contributing
|
|
141
|
+
|
|
142
|
+
Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on adding new lint rules, provider profiles, and tests.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# toolpreflight
|
|
2
|
+
|
|
3
|
+
**Zero-dependency pre-flight linter, context-token auditor, cross-provider schema checker, and live stdio probe for MCP servers & AI agent tools.**
|
|
4
|
+
|
|
5
|
+
AI agents fail silently when tool schemas are vague, redundant, oversized, missing safety annotations, or incompatible with a target LLM provider's structured-output / function-calling rules. `toolpreflight` catches those issues in milliseconds—offline or against a live MCP `stdio` server—before your users or CI hit `400 Bad Request` or tool-selection errors.
|
|
6
|
+
|
|
7
|
+
## Why `toolpreflight`?
|
|
8
|
+
|
|
9
|
+
- **Zero mandatory dependencies:** Pure Python 3.10+ stdlib core (with automatic `tiktoken` and `rich` enhancement if installed).
|
|
10
|
+
- **Format-agnostic:** Inspects MCP `tools/list` JSON, OpenAI `tools`, Anthropic `tools`, Gemini `functionDeclarations`, Python files (typed functions & Pydantic models), or live MCP `stdio` servers.
|
|
11
|
+
- **Context-window budget guard:** Measures per-tool and total token overhead (`--max-tokens`) so tool schemas don't quietly eat your prompt budget.
|
|
12
|
+
- **Cross-provider compatibility:** Validates schemas against **OpenAI Strict** (`strict: true`), **Gemini**, **Anthropic**, and **Local GBNF** (Ollama / llama.cpp) constraints.
|
|
13
|
+
- **Auto-normalization (`fix`):** Compiles schemas for a target provider (inlining `$defs`/`$ref`, enforcing `additionalProperties: false`, and preserving stripped constraint ranges in descriptions).
|
|
14
|
+
- **CI-native:** Supports `--format text | json | markdown` and `--fail-on error | warning`.
|
|
15
|
+
|
|
16
|
+
## Quickstart
|
|
17
|
+
|
|
18
|
+
Install locally in editable mode:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install -e .
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### 1. Audit a tool manifest (MCP, OpenAI, Anthropic, Gemini, or Python module)
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
toolpreflight check examples/sample_mcp_tools.json --target openai_strict,gemini,anthropic --max-tokens 2000
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### 2. Probe a live MCP `stdio` server
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
toolpreflight probe --stdio "python examples/demo_mcp_server.py"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Pass `--smoke-invalid` to safely send malformed/empty arguments **only** to tools marked `readOnlyHint: true` and verify the server returns a clean protocol error instead of crashing.
|
|
37
|
+
|
|
38
|
+
### 3. Normalize schemas for a target provider
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
toolpreflight fix examples/sample_mcp_tools.json --target openai_strict -o fixed_tools.json
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 4. Generate a GitHub PR Markdown report in CI
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
toolpreflight check tools.json --format markdown --fail-on error
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Example Output
|
|
51
|
+
|
|
52
|
+
Running `toolpreflight check examples/sample_mcp_tools.json --fail-on none`:
|
|
53
|
+
|
|
54
|
+
```text
|
|
55
|
+
toolpreflight report | source: examples/sample_mcp_tools.json
|
|
56
|
+
====================================================================
|
|
57
|
+
Grade: F | Tools: 2 | Context Tax: ~300 tokens
|
|
58
|
+
Findings: 8 error(s), 7 warning(s)
|
|
59
|
+
|
|
60
|
+
Provider Compatibility:
|
|
61
|
+
[FAIL] openai_strict errors=4 warnings=2
|
|
62
|
+
[FAIL] gemini errors=3 warnings=0
|
|
63
|
+
[PASS] anthropic errors=0 warnings=0
|
|
64
|
+
[PASS] local_gbnf errors=0 warnings=0
|
|
65
|
+
|
|
66
|
+
Token Breakdown (heaviest first):
|
|
67
|
+
- search_issues ~ 187 tok (desc=19, schema=156, heuristic)
|
|
68
|
+
- delete_issue_comment ~ 113 tok (desc=4, schema=95, heuristic)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Running `toolpreflight probe --stdio "python examples/demo_mcp_server.py" --target openai_strict,anthropic --smoke-invalid`:
|
|
72
|
+
|
|
73
|
+
```text
|
|
74
|
+
toolpreflight report | source: stdio:python examples/demo_mcp_server.py
|
|
75
|
+
====================================================================
|
|
76
|
+
Grade: A | Tools: 1 | Context Tax: ~95 tokens
|
|
77
|
+
Findings: 0 error(s), 0 warning(s)
|
|
78
|
+
Live Probe: demo-weather-mcp v0.1.0 (protocol 2024-11-05, init 81.55 ms, tools/list 0.51 ms)
|
|
79
|
+
- Smoke invalid probe [PASS] get_weather (tool_result)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Lint Rules
|
|
83
|
+
|
|
84
|
+
| Code | Severity | Description |
|
|
85
|
+
| --- | --- | --- |
|
|
86
|
+
| `TP001` | `error` | Tool is missing a description. |
|
|
87
|
+
| `TP002` | `warning` | Tool description is too short (`< 20` chars) or overly generic. |
|
|
88
|
+
| `TP003` | `error` | Missing `inputSchema` or root schema is not `"type": "object"`. |
|
|
89
|
+
| `TP004` | `warning` | Schema property is missing a `description`. |
|
|
90
|
+
| `TP005` | `error` | Array property is missing `items` definition. |
|
|
91
|
+
| `TP006` | `warning` | Schema nesting exceeds recommended depth (`> 4`). |
|
|
92
|
+
| `TP007` | `error` / `warning` | `required` references undefined properties, or object properties lack a `required` list. |
|
|
93
|
+
| `TP008` | `warning` | Mutating/destructive tool name lacks MCP safety annotations (`readOnlyHint` / `destructiveHint`). |
|
|
94
|
+
| `TP009` | `warning` | Single tool exceeds recommended per-tool token threshold (`> 500` tokens). |
|
|
95
|
+
| `TP010` | `warning` | High lexical overlap between two tools in the same server (risks LLM tool confusion). |
|
|
96
|
+
| `TP011` | `error` | Duplicate tool name detected in the manifest. |
|
|
97
|
+
|
|
98
|
+
## Running Tests
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
python -m unittest discover -s tests -v
|
|
102
|
+
# or with pytest:
|
|
103
|
+
pytest -v
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Contributing
|
|
107
|
+
|
|
108
|
+
Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on adding new lint rules, provider profiles, and tests.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "toolpreflight"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Zero-dependency pre-flight linter, token auditor, cross-provider schema checker, and live stdio smoke-tester for MCP servers and AI agent tools."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Open Source Contributors" }
|
|
15
|
+
]
|
|
16
|
+
keywords = [
|
|
17
|
+
"mcp",
|
|
18
|
+
"model-context-protocol",
|
|
19
|
+
"ai-agents",
|
|
20
|
+
"llm",
|
|
21
|
+
"json-schema",
|
|
22
|
+
"openai",
|
|
23
|
+
"gemini",
|
|
24
|
+
"anthropic",
|
|
25
|
+
"linter",
|
|
26
|
+
"devtools",
|
|
27
|
+
]
|
|
28
|
+
classifiers = [
|
|
29
|
+
"Development Status :: 4 - Beta",
|
|
30
|
+
"Environment :: Console",
|
|
31
|
+
"Intended Audience :: Developers",
|
|
32
|
+
"Programming Language :: Python :: 3",
|
|
33
|
+
"Programming Language :: Python :: 3.10",
|
|
34
|
+
"Programming Language :: Python :: 3.11",
|
|
35
|
+
"Programming Language :: Python :: 3.12",
|
|
36
|
+
"Programming Language :: Python :: 3.13",
|
|
37
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
38
|
+
"Topic :: Software Development :: Testing",
|
|
39
|
+
]
|
|
40
|
+
dependencies = []
|
|
41
|
+
|
|
42
|
+
[project.urls]
|
|
43
|
+
Homepage = "https://github.com/Sarbojit10/toolpreflight"
|
|
44
|
+
Repository = "https://github.com/Sarbojit10/toolpreflight"
|
|
45
|
+
Issues = "https://github.com/Sarbojit10/toolpreflight/issues"
|
|
46
|
+
|
|
47
|
+
[project.optional-dependencies]
|
|
48
|
+
tiktoken = ["tiktoken>=0.7.0"]
|
|
49
|
+
rich = ["rich>=13.0.0"]
|
|
50
|
+
pydantic = ["pydantic>=2.0.0"]
|
|
51
|
+
dev = [
|
|
52
|
+
"pytest>=8.0.0",
|
|
53
|
+
"ruff>=0.6.0",
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
[project.scripts]
|
|
57
|
+
toolpreflight = "toolpreflight.cli:main"
|
|
58
|
+
|
|
59
|
+
[tool.setuptools.packages.find]
|
|
60
|
+
where = ["src"]
|
|
61
|
+
|
|
62
|
+
[tool.pytest.ini_options]
|
|
63
|
+
testpaths = ["tests"]
|
|
64
|
+
pythonpath = ["src"]
|
|
65
|
+
|
|
66
|
+
[tool.ruff]
|
|
67
|
+
line-length = 100
|
|
68
|
+
target-version = "py310"
|
|
69
|
+
|
|
70
|
+
[tool.ruff.lint]
|
|
71
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""toolpreflight: Pre-flight linter, token auditor, and compatibility checker for AI tools."""
|
|
2
|
+
|
|
3
|
+
from toolpreflight.analyzer import analyze_tools
|
|
4
|
+
from toolpreflight.compat import SUPPORTED_PROVIDERS, check_compatibility, normalize_schema
|
|
5
|
+
from toolpreflight.loaders import load_tools, parse_tool_payload
|
|
6
|
+
from toolpreflight.models import (
|
|
7
|
+
Finding,
|
|
8
|
+
PreflightReport,
|
|
9
|
+
ProbeMetadata,
|
|
10
|
+
ProviderSummary,
|
|
11
|
+
Severity,
|
|
12
|
+
TokenBreakdown,
|
|
13
|
+
ToolSpec,
|
|
14
|
+
)
|
|
15
|
+
from toolpreflight.render import render_report
|
|
16
|
+
from toolpreflight.stdio_probe import McpProbeError, probe_stdio_server
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"SUPPORTED_PROVIDERS",
|
|
20
|
+
"Finding",
|
|
21
|
+
"McpProbeError",
|
|
22
|
+
"PreflightReport",
|
|
23
|
+
"ProbeMetadata",
|
|
24
|
+
"ProviderSummary",
|
|
25
|
+
"Severity",
|
|
26
|
+
"TokenBreakdown",
|
|
27
|
+
"ToolSpec",
|
|
28
|
+
"analyze_tools",
|
|
29
|
+
"check_compatibility",
|
|
30
|
+
"load_tools",
|
|
31
|
+
"normalize_schema",
|
|
32
|
+
"parse_tool_payload",
|
|
33
|
+
"probe_stdio_server",
|
|
34
|
+
"render_report",
|
|
35
|
+
]
|
|
36
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""High-level analysis orchestration for toolpreflight."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from toolpreflight.compat import SUPPORTED_PROVIDERS, check_compatibility
|
|
6
|
+
from toolpreflight.models import (
|
|
7
|
+
PreflightReport,
|
|
8
|
+
ProbeMetadata,
|
|
9
|
+
Severity,
|
|
10
|
+
ToolSpec,
|
|
11
|
+
)
|
|
12
|
+
from toolpreflight.rules import lint_tools
|
|
13
|
+
from toolpreflight.tokens import measure_tool_tokens
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def analyze_tools(
|
|
17
|
+
tools: list[ToolSpec],
|
|
18
|
+
*,
|
|
19
|
+
source: str = "<memory>",
|
|
20
|
+
targets: list[str] | None = None,
|
|
21
|
+
max_tokens_budget: int | None = None,
|
|
22
|
+
per_tool_token_limit: int = 500,
|
|
23
|
+
probe: ProbeMetadata | None = None,
|
|
24
|
+
) -> PreflightReport:
|
|
25
|
+
"""Run token estimation, lint rules, and provider compatibility checks."""
|
|
26
|
+
active_targets = targets if targets is not None else list(SUPPORTED_PROVIDERS)
|
|
27
|
+
|
|
28
|
+
breakdowns = [measure_tool_tokens(tool) for tool in tools]
|
|
29
|
+
total_tokens = sum(item.total_tokens for item in breakdowns)
|
|
30
|
+
token_map = {item.tool_name: item.total_tokens for item in breakdowns}
|
|
31
|
+
|
|
32
|
+
lint_findings = lint_tools(
|
|
33
|
+
tools,
|
|
34
|
+
per_tool_token_limit=per_tool_token_limit,
|
|
35
|
+
token_totals=token_map,
|
|
36
|
+
)
|
|
37
|
+
compat_findings, provider_summaries = check_compatibility(tools, active_targets)
|
|
38
|
+
all_findings = lint_findings + compat_findings
|
|
39
|
+
|
|
40
|
+
budget_exceeded = (
|
|
41
|
+
max_tokens_budget is not None and total_tokens > max_tokens_budget
|
|
42
|
+
)
|
|
43
|
+
grade = _compute_grade(
|
|
44
|
+
error_count=sum(1 for f in all_findings if f.severity == Severity.ERROR),
|
|
45
|
+
warning_count=sum(1 for f in all_findings if f.severity == Severity.WARNING),
|
|
46
|
+
budget_exceeded=budget_exceeded,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
return PreflightReport(
|
|
50
|
+
source=source,
|
|
51
|
+
tool_count=len(tools),
|
|
52
|
+
total_tokens=total_tokens,
|
|
53
|
+
max_tokens_budget=max_tokens_budget,
|
|
54
|
+
grade=grade,
|
|
55
|
+
findings=all_findings,
|
|
56
|
+
token_breakdowns=breakdowns,
|
|
57
|
+
provider_summaries=provider_summaries,
|
|
58
|
+
probe=probe,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _compute_grade(
|
|
63
|
+
*, error_count: int, warning_count: int, budget_exceeded: bool
|
|
64
|
+
) -> str:
|
|
65
|
+
score = 100 - (error_count * 18) - (warning_count * 5) - (15 if budget_exceeded else 0)
|
|
66
|
+
if score >= 90 and error_count == 0:
|
|
67
|
+
return "A"
|
|
68
|
+
if score >= 75:
|
|
69
|
+
return "B"
|
|
70
|
+
if score >= 60:
|
|
71
|
+
return "C"
|
|
72
|
+
if score >= 40:
|
|
73
|
+
return "D"
|
|
74
|
+
return "F"
|