toolpreflight
Zero-dependency pre-flight linter, context-token auditor, cross-provider schema checker, and live stdio probe for MCP servers & AI agent tools.
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.
Why toolpreflight?
- Zero mandatory dependencies: Pure Python 3.10+ stdlib core (with automatic
tiktokenandrichenhancement if installed). - Format-agnostic: Inspects MCP
tools/listJSON, OpenAItools, Anthropictools, GeminifunctionDeclarations, Python files (typed functions & Pydantic models), or live MCPstdioservers. - Context-window budget guard: Measures per-tool and total token overhead (
--max-tokens) so tool schemas don't quietly eat your prompt budget. - Cross-provider compatibility: Validates schemas against OpenAI Strict (
strict: true), Gemini, Anthropic, and Local GBNF (Ollama / llama.cpp) constraints. - Auto-normalization (
fix): Compiles schemas for a target provider (inlining$defs/$ref, enforcingadditionalProperties: false, and preserving stripped constraint ranges in descriptions). - CI-native: Supports
--format text | json | markdownand--fail-on error | warning.
Quickstart
Install locally in editable mode:
pip install -e .
1. Audit a tool manifest (MCP, OpenAI, Anthropic, Gemini, or Python module)
toolpreflight check examples/sample_mcp_tools.json --target openai_strict,gemini,anthropic --max-tokens 2000
2. Probe a live MCP stdio server
toolpreflight probe --stdio "python examples/demo_mcp_server.py"
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.
3. Normalize schemas for a target provider
toolpreflight fix examples/sample_mcp_tools.json --target openai_strict -o fixed_tools.json
4. Generate a GitHub PR Markdown report in CI
toolpreflight check tools.json --format markdown --fail-on error
Example Output
Running toolpreflight check examples/sample_mcp_tools.json --fail-on none:
toolpreflight report | source: examples/sample_mcp_tools.json
====================================================================
Grade: F | Tools: 2 | Context Tax: ~300 tokens
Findings: 8 error(s), 7 warning(s)
Provider Compatibility:
[FAIL] openai_strict errors=4 warnings=2
[FAIL] gemini errors=3 warnings=0
[PASS] anthropic errors=0 warnings=0
[PASS] local_gbnf errors=0 warnings=0
Token Breakdown (heaviest first):
- search_issues ~ 187 tok (desc=19, schema=156, heuristic)
- delete_issue_comment ~ 113 tok (desc=4, schema=95, heuristic)
Running toolpreflight probe --stdio "python examples/demo_mcp_server.py" --target openai_strict,anthropic --smoke-invalid:
toolpreflight report | source: stdio:python examples/demo_mcp_server.py
====================================================================
Grade: A | Tools: 1 | Context Tax: ~95 tokens
Findings: 0 error(s), 0 warning(s)
Live Probe: demo-weather-mcp v0.1.0 (protocol 2024-11-05, init 81.55 ms, tools/list 0.51 ms)
- Smoke invalid probe [PASS] get_weather (tool_result)
Lint Rules
| Code | Severity | Description |
|---|---|---|
TP001 |
error |
Tool is missing a description. |
TP002 |
warning |
Tool description is too short (< 20 chars) or overly generic. |
TP003 |
error |
Missing inputSchema or root schema is not "type": "object". |
TP004 |
warning |
Schema property is missing a description. |
TP005 |
error |
Array property is missing items definition. |
TP006 |
warning |
Schema nesting exceeds recommended depth (> 4). |
TP007 |
error / warning |
required references undefined properties, or object properties lack a required list. |
TP008 |
warning |
Mutating/destructive tool name lacks MCP safety annotations (readOnlyHint / destructiveHint). |
TP009 |
warning |
Single tool exceeds recommended per-tool token threshold (> 500 tokens). |
TP010 |
warning |
High lexical overlap between two tools in the same server (risks LLM tool confusion). |
TP011 |
error |
Duplicate tool name detected in the manifest. |
Running Tests
python -m unittest discover -s tests -v
# or with pytest:
pytest -v
Contributing
Contributions are welcome! See CONTRIBUTING.md for guidelines on adding new lint rules, provider profiles, and tests.
Metadata
Release files for toolpreflight 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| toolpreflight-0.1.0.tar.gz | 26.6 kB | Without provenance | Details for toolpreflight-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| toolpreflight-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for toolpreflight-0.1.0-py3-none-any.whl |
Total release size: 51.6 kB
Release files / toolpreflight-0.1.0.tar.gz
| Download URL | toolpreflight-0.1.0.tar.gz |
|---|---|
| Size | 26.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7ac9b28192835dbb675699df30ceae04277055e4d499c59ffb1df291fbac65df
|
|
BLAKE2b-256 checksum How to use checksums |
920dde0d3c9828e5ad4a07b04b1e9a08b85a3bd3e128bac4a51406b0b93e8723
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.6
|
Release files / toolpreflight-0.1.0-py3-none-any.whl
| Download URL | toolpreflight-0.1.0-py3-none-any.whl |
|---|---|
| Size | 25.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3be56f12b1acb6bc551e5cfca23cf9c67b3186d87c93e8aa621aea492feecba2
|
|
BLAKE2b-256 checksum How to use checksums |
ca5f0700509864dace2ce413cb34fdc60d0923e50f71983449c5c9b29d3dd4a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.6
|
Security for toolpreflight 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.