universal-cli-mcp-server 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.
Files changed (78) hide show
  1. universal_cli_mcp_server-0.1.0/.gitignore +24 -0
  2. universal_cli_mcp_server-0.1.0/LICENSE +202 -0
  3. universal_cli_mcp_server-0.1.0/PKG-INFO +381 -0
  4. universal_cli_mcp_server-0.1.0/README.md +345 -0
  5. universal_cli_mcp_server-0.1.0/docs/architecture.md +58 -0
  6. universal_cli_mcp_server-0.1.0/docs/clients.md +92 -0
  7. universal_cli_mcp_server-0.1.0/docs/configuration.md +134 -0
  8. universal_cli_mcp_server-0.1.0/docs/discovery.md +79 -0
  9. universal_cli_mcp_server-0.1.0/docs/plugins.md +57 -0
  10. universal_cli_mcp_server-0.1.0/docs/security.md +165 -0
  11. universal_cli_mcp_server-0.1.0/docs/transports.md +66 -0
  12. universal_cli_mcp_server-0.1.0/examples/cli-mcp.yaml +100 -0
  13. universal_cli_mcp_server-0.1.0/examples/sample-clis/clicksample.py +41 -0
  14. universal_cli_mcp_server-0.1.0/examples/sample-clis/nodesample.js +81 -0
  15. universal_cli_mcp_server-0.1.0/examples/sample-clis/reducer.py +88 -0
  16. universal_cli_mcp_server-0.1.0/examples/sample-clis/typersample.py +42 -0
  17. universal_cli_mcp_server-0.1.0/examples/sample-clis/yargssample.js +28 -0
  18. universal_cli_mcp_server-0.1.0/pyproject.toml +100 -0
  19. universal_cli_mcp_server-0.1.0/src/cli_mcp/__init__.py +32 -0
  20. universal_cli_mcp_server-0.1.0/src/cli_mcp/cli/__init__.py +7 -0
  21. universal_cli_mcp_server-0.1.0/src/cli_mcp/cli/main.py +410 -0
  22. universal_cli_mcp_server-0.1.0/src/cli_mcp/config/__init__.py +31 -0
  23. universal_cli_mcp_server-0.1.0/src/cli_mcp/config/loader.py +133 -0
  24. universal_cli_mcp_server-0.1.0/src/cli_mcp/config/settings.py +171 -0
  25. universal_cli_mcp_server-0.1.0/src/cli_mcp/core.py +133 -0
  26. universal_cli_mcp_server-0.1.0/src/cli_mcp/detect.py +143 -0
  27. universal_cli_mcp_server-0.1.0/src/cli_mcp/discovery/__init__.py +49 -0
  28. universal_cli_mcp_server-0.1.0/src/cli_mcp/discovery/base.py +129 -0
  29. universal_cli_mcp_server-0.1.0/src/cli_mcp/discovery/engine.py +238 -0
  30. universal_cli_mcp_server-0.1.0/src/cli_mcp/discovery/grammars.py +170 -0
  31. universal_cli_mcp_server-0.1.0/src/cli_mcp/discovery/help_parser.py +627 -0
  32. universal_cli_mcp_server-0.1.0/src/cli_mcp/discovery/introspect.py +276 -0
  33. universal_cli_mcp_server-0.1.0/src/cli_mcp/discovery/manifest.py +161 -0
  34. universal_cli_mcp_server-0.1.0/src/cli_mcp/discovery/node_reflection.py +126 -0
  35. universal_cli_mcp_server-0.1.0/src/cli_mcp/discovery/pipeline.py +108 -0
  36. universal_cli_mcp_server-0.1.0/src/cli_mcp/discovery/python_reflection.py +54 -0
  37. universal_cli_mcp_server-0.1.0/src/cli_mcp/discovery/reflection_payload.py +92 -0
  38. universal_cli_mcp_server-0.1.0/src/cli_mcp/discovery/registry.py +124 -0
  39. universal_cli_mcp_server-0.1.0/src/cli_mcp/errors.py +37 -0
  40. universal_cli_mcp_server-0.1.0/src/cli_mcp/executor/__init__.py +19 -0
  41. universal_cli_mcp_server-0.1.0/src/cli_mcp/executor/approval.py +64 -0
  42. universal_cli_mcp_server-0.1.0/src/cli_mcp/executor/argv.py +63 -0
  43. universal_cli_mcp_server-0.1.0/src/cli_mcp/executor/runner.py +384 -0
  44. universal_cli_mcp_server-0.1.0/src/cli_mcp/executor/sandbox.py +31 -0
  45. universal_cli_mcp_server-0.1.0/src/cli_mcp/mcp/__init__.py +22 -0
  46. universal_cli_mcp_server-0.1.0/src/cli_mcp/mcp/server.py +80 -0
  47. universal_cli_mcp_server-0.1.0/src/cli_mcp/mcp/tool_adapter.py +120 -0
  48. universal_cli_mcp_server-0.1.0/src/cli_mcp/models.py +213 -0
  49. universal_cli_mcp_server-0.1.0/src/cli_mcp/plugins/__init__.py +41 -0
  50. universal_cli_mcp_server-0.1.0/src/cli_mcp/schema/__init__.py +31 -0
  51. universal_cli_mcp_server-0.1.0/src/cli_mcp/schema/docgen.py +104 -0
  52. universal_cli_mcp_server-0.1.0/src/cli_mcp/schema/jsonschema.py +104 -0
  53. universal_cli_mcp_server-0.1.0/src/cli_mcp/schema/openapi.py +57 -0
  54. universal_cli_mcp_server-0.1.0/src/cli_mcp/schema/validate.py +84 -0
  55. universal_cli_mcp_server-0.1.0/src/cli_mcp/security/__init__.py +26 -0
  56. universal_cli_mcp_server-0.1.0/src/cli_mcp/security/policy.py +91 -0
  57. universal_cli_mcp_server-0.1.0/src/cli_mcp/security/readonly.py +173 -0
  58. universal_cli_mcp_server-0.1.0/src/cli_mcp/transport/__init__.py +49 -0
  59. universal_cli_mcp_server-0.1.0/src/cli_mcp/version.py +3 -0
  60. universal_cli_mcp_server-0.1.0/tests/conftest.py +85 -0
  61. universal_cli_mcp_server-0.1.0/tests/test_cli.py +218 -0
  62. universal_cli_mcp_server-0.1.0/tests/test_config.py +121 -0
  63. universal_cli_mcp_server-0.1.0/tests/test_core.py +160 -0
  64. universal_cli_mcp_server-0.1.0/tests/test_detect.py +112 -0
  65. universal_cli_mcp_server-0.1.0/tests/test_e2e.py +84 -0
  66. universal_cli_mcp_server-0.1.0/tests/test_engine.py +286 -0
  67. universal_cli_mcp_server-0.1.0/tests/test_executor.py +212 -0
  68. universal_cli_mcp_server-0.1.0/tests/test_grammars.py +150 -0
  69. universal_cli_mcp_server-0.1.0/tests/test_help_parser.py +237 -0
  70. universal_cli_mcp_server-0.1.0/tests/test_manifest.py +279 -0
  71. universal_cli_mcp_server-0.1.0/tests/test_mcp.py +211 -0
  72. universal_cli_mcp_server-0.1.0/tests/test_models.py +94 -0
  73. universal_cli_mcp_server-0.1.0/tests/test_registry.py +198 -0
  74. universal_cli_mcp_server-0.1.0/tests/test_runner_safe.py +468 -0
  75. universal_cli_mcp_server-0.1.0/tests/test_safety.py +362 -0
  76. universal_cli_mcp_server-0.1.0/tests/test_schema.py +204 -0
  77. universal_cli_mcp_server-0.1.0/tests/test_security.py +141 -0
  78. universal_cli_mcp_server-0.1.0/tests/test_transport.py +72 -0
@@ -0,0 +1,24 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ .pytest_cache/
5
+ .mypy_cache/
6
+ .ruff_cache/
7
+ .coverage
8
+ coverage.xml
9
+ coverage-html/
10
+ dist/
11
+ build/
12
+ *.egg-info/
13
+ .venv/
14
+
15
+ # Generated documentation and exports
16
+ docs/*-mcp.md
17
+ tools.json
18
+ openapi.json
19
+
20
+ # Editors and OS
21
+ .idea/
22
+ .vscode/
23
+ .DS_Store
24
+ Thumbs.db
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for the direction
150
+ and management of the Work and the risks associated with using it,
151
+ and assume any risks associated with Your exercise of permissions
152
+ 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 [yyyy] [name of copyright owner]
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,381 @@
1
+ Metadata-Version: 2.5
2
+ Name: universal-cli-mcp-server
3
+ Version: 0.1.0
4
+ Summary: Swagger for command line tools — expose any CLI as a fully compliant MCP server
5
+ Project-URL: Homepage, https://github.com/AndreasHeine/cli-mcp
6
+ Project-URL: Repository, https://github.com/AndreasHeine/cli-mcp
7
+ Project-URL: Issues, https://github.com/AndreasHeine/cli-mcp/issues
8
+ Author: Andreas Heine
9
+ License: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: cli,discovery,json-schema,mcp,model-context-protocol,openapi
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Software Development :: Libraries
18
+ Classifier: Topic :: Software Development :: Testing
19
+ Requires-Python: >=3.13
20
+ Requires-Dist: httpx>=0.27
21
+ Requires-Dist: mcp>=1.9
22
+ Requires-Dist: pydantic>=2.9
23
+ Requires-Dist: pyyaml>=6.0
24
+ Requires-Dist: rich>=13.9
25
+ Requires-Dist: typer>=0.15
26
+ Requires-Dist: uvicorn>=0.30
27
+ Provides-Extra: dev
28
+ Requires-Dist: mypy>=1.13; extra == 'dev'
29
+ Requires-Dist: pre-commit>=4.0; extra == 'dev'
30
+ Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
31
+ Requires-Dist: pytest-cov>=6.0; extra == 'dev'
32
+ Requires-Dist: pytest>=8.3; extra == 'dev'
33
+ Requires-Dist: ruff>=0.8; extra == 'dev'
34
+ Requires-Dist: types-pyyaml>=6.0; extra == 'dev'
35
+ Description-Content-Type: text/markdown
36
+
37
+ # cli-mcp
38
+
39
+ **Swagger for Command Line Tools**
40
+
41
+ `cli-mcp` exposes command-line applications through a
42
+ [Model Context Protocol](https://modelcontextprotocol.io) (MCP) server — without you
43
+ writing a single line of MCP code.
44
+
45
+ Like Swagger/OpenAPI describes an HTTP API, cli-mcp describes CLI commands, their arguments,
46
+ and their results as structured tools. It also executes those tools with argument validation
47
+ and configured execution controls, and can export OpenAPI documentation.
48
+ Automatic discovery depends on the CLI's help format or supported framework; use a manifest
49
+ when explicit metadata is needed. Windows `.bat`/`.cmd` targets are not supported.
50
+
51
+ ```text
52
+ Today: CLI Tool -> custom MCP wrapper -> MCP client
53
+ With cli-mcp: CLI Tool -> cli-mcp -> MCP client
54
+ ```
55
+
56
+ ```bash
57
+ cli-mcp expose git
58
+ cli-mcp expose kubectl
59
+ cli-mcp expose docker
60
+ cli-mcp expose opcua-nodeset-linker
61
+ ```
62
+
63
+ ```text
64
+ ✓ Binary detected
65
+ ✓ Commands discovered
66
+ ✓ Schemas generated
67
+ ✓ MCP tools published
68
+ ✓ MCP server started
69
+ ```
70
+
71
+ Works with Claude, Copilot, Cursor, VS Code, Cline, Roo Code, Open WebUI and any other
72
+ MCP-compatible client.
73
+
74
+ ---
75
+
76
+ ## Install
77
+
78
+ Requires Python 3.13 or newer. CI covers Windows and Linux with Python 3.13 and 3.14.
79
+
80
+ ```bash
81
+ pip install cli-mcp
82
+ ```
83
+
84
+ or, for development:
85
+
86
+ ```bash
87
+ git clone https://github.com/AndreasHeine/cli-mcp
88
+ cd cli-mcp
89
+ uv sync --extra dev
90
+ uv run cli-mcp --help
91
+ ```
92
+
93
+ ## Quick start
94
+
95
+ Only expose trusted programs. These quick-start examples do **not** enable read-only mode
96
+ or sandboxing; discovery itself runs help commands on the host.
97
+
98
+ ```bash
99
+ # Discover commands and serve them over stdio (the default transport)
100
+ cli-mcp expose git
101
+
102
+ # Look at the generated tools without starting a server
103
+ cli-mcp inspect kubectl
104
+
105
+ # Serve over Streamable HTTP
106
+ cli-mcp serve docker --transport streamable-http --port 8801
107
+
108
+ # Export machine-readable artefacts
109
+ cli-mcp export git -o tools.md
110
+ cli-mcp export-schema git -o schemas.json
111
+ cli-mcp export-openapi git -o openapi.json
112
+
113
+ # Validate discovery quality
114
+ cli-mcp doctor git
115
+
116
+ # Generate a configuration template
117
+ cli-mcp init opcua-nodeset-linker -o cli-mcp.yaml
118
+ ```
119
+
120
+ Client configuration (`.mcp.json`, Claude Desktop, Cursor, VS Code, …):
121
+
122
+ The following is a common client configuration shape; VS Code and other clients may use
123
+ different keys. See [clients.md](docs/clients.md) for client-specific recipes.
124
+
125
+ ```json
126
+ {
127
+ "mcpServers": {
128
+ "git": {
129
+ "command": "cli-mcp",
130
+ "args": ["serve", "git"]
131
+ },
132
+ "docker": {
133
+ "url": "http://127.0.0.1:8801/mcp"
134
+ }
135
+ }
136
+ }
137
+ ```
138
+
139
+ ---
140
+
141
+ ## Working directory and Windows shells
142
+
143
+ Some CLIs resolve paths inside their input configuration relative to the process working
144
+ directory, not relative to that configuration file. Configure an absolute existing directory
145
+ for both discovery and execution:
146
+
147
+ ```yaml
148
+ binary: my-cli
149
+ execution:
150
+ cwd: 'C:\projects\my-cli'
151
+ ```
152
+
153
+ Without `execution.cwd`, the launch directory is used. Use an absolute manifest path when
154
+ changing the discovery directory. Configuration and tool definitions are loaded at startup:
155
+ restart the server and reconnect the client after changes.
156
+
157
+ PowerShell:
158
+
159
+ ```powershell
160
+ $env:PYTHONDONTWRITEBYTECODE = '1'
161
+ & 'C:\projects\cli-mcp\.venv\Scripts\python.exe' -B -m cli_mcp.cli.main expose --config 'C:\projects\cli-mcp\cli-mcp.yaml'
162
+ ```
163
+
164
+ cmd.exe (run these as two separate commands):
165
+
166
+ ```bat
167
+ set PYTHONDONTWRITEBYTECODE=1
168
+ "C:\projects\cli-mcp\.venv\Scripts\python.exe" -B -m cli_mcp.cli.main expose --config "C:\projects\cli-mcp\cli-mcp.yaml"
169
+ ```
170
+
171
+ These examples assume an existing development environment at the shown location.
172
+
173
+ ---
174
+
175
+ ## How discovery works
176
+
177
+ `cli-mcp` tries discovery strategies in order. The first strategy that yields usable commands
178
+ wins; manifest entries then add tools or replace discovered tools with the same name.
179
+ The final include/exclude filters select which tools are published, not which help commands
180
+ may execute.
181
+
182
+ Import reflection is **disabled by default** and requires `--allow-reflection` or
183
+ `discovery.allow_import_reflection: true`. It may execute target code.
184
+ `discovery.max_depth` limits the recursive walk; `discovery.max_commands` limits both published
185
+ tools and uncached help invocations, including root queries, failures and fallback flags.
186
+ The help budget is checked before spawning processes; cache hits do not consume it.
187
+
188
+ | Strategy | How it works | Frameworks |
189
+ | --- | --- | --- |
190
+ | **Native reflection** | Inspects the real command objects in the target process | Python: argparse, click, typer · Node.js: commander.js |
191
+ | **Framework help grammars** | Parses framework-specific help output with type/default/required semantics | Go: cobra · Rust: clap · .NET: System.CommandLine · Node.js: yargs · click · argparse |
192
+ | **Generic help parsing** | Recursive `tool --help` / `tool <command> --help` parser | anything with `--help` |
193
+ | **Manifest file** | User-provided YAML metadata, authoritative for matching tool names | supported executables and scripts |
194
+
195
+ Every discovered command becomes an MCP tool:
196
+
197
+ ```json
198
+ {
199
+ "name": "reduce",
200
+ "description": "Reduce an OPC UA nodeset",
201
+ "inputSchema": {
202
+ "type": "object",
203
+ "properties": {
204
+ "input": { "type": "string", "description": "Input nodeset file" },
205
+ "output": { "type": "string", "description": "Reduced nodeset file" }
206
+ },
207
+ "required": ["input", "output"]
208
+ }
209
+ }
210
+ ```
211
+
212
+ Calling the tool executes the original CLI:
213
+
214
+ ```bash
215
+ linker reduce --input model.xml --output reduced.xml
216
+ ```
217
+
218
+ and returns:
219
+
220
+ ```json
221
+ {
222
+ "stdout": "...",
223
+ "stderr": "",
224
+ "exitCode": 0,
225
+ "executionTimeMs": 125,
226
+ "argv": ["linker", "reduce", "--input", "model.xml", "--output", "reduced.xml"],
227
+ "sandboxed": false,
228
+ "truncated": false
229
+ }
230
+ ```
231
+
232
+ The actual `argv` contains the resolved launch command, including interpreter prefixes where
233
+ needed. A connected client or completed MCP call does not prove CLI success: inspect `exitCode`
234
+ and `stderr`. Exitcode 0 does not establish side-effect freedom; `sandboxed: false` means the
235
+ target ran on the host.
236
+
237
+ ---
238
+
239
+ ## Security
240
+
241
+ Security is a first-class concern, not an afterthought.
242
+
243
+ ```yaml
244
+ binary: opcua-nodeset-linker
245
+
246
+ security:
247
+ allowlist: [git, kubectl, docker, opcua-nodeset-linker]
248
+ readonly: true # deny unless the complete argv is explicitly listed
249
+ readonly_argv: [] # configure verified exact invocations before use
250
+ approval: true # human confirmation required
251
+ timeout_seconds: 30
252
+ max_output_bytes: 200000
253
+ sandbox:
254
+ backend: docker
255
+ image: my-cli-image:latest
256
+ network: false
257
+ ```
258
+
259
+ - **Allow list** — a non-empty list restricts configured binaries by basename;
260
+ an empty list permits the configured binary. This is not an OS permission boundary.
261
+ - **Read-only mode** — only explicitly listed complete argv vectors may execute;
262
+ known risky commands and flags are additionally blocked. An empty `readonly_argv` blocks
263
+ every execution and triggers a startup warning; publishing tools does not authorize them.
264
+ - **Approval mode** — `auto`/`prompt` require a local human at a terminal; without a TTY
265
+ approval-required execution is refused. Clients cannot approve their own calls. Legacy
266
+ `explicit` refuses approval-required calls. Normal stdio clients do not provide a local TTY.
267
+ - **Sandboxing** — run the CLI inside Docker or Podman; the default working-directory
268
+ mount is writable. Discovery still runs on the host. Firecracker support planned.
269
+ - **Argument validation** — arguments are validated against the generated JSON schema
270
+ before the requested tool process is spawned. Arguments are not interpolated into
271
+ a shell string.
272
+
273
+ Read-only, approval and sandboxing are opt-in. Exact argv permissions do not prove that a
274
+ program, its environment or its input files are harmless. Discovery is outside tool execution
275
+ guards. Output limits bound retained stdout/stderr, not the target's own CPU or memory use.
276
+ HTTP/SSE defaults to loopback and does not configure authentication or TLS; do not expose it
277
+ publicly without appropriate protection.
278
+
279
+ Windows batch targets (`.bat`/`.cmd`) are rejected. Output is retained within a byte budget,
280
+ including timeouts. See [security.md](docs/security.md) for limitations, configuration migration,
281
+ and non-invasive Windows/Linux tests using a single loopback ping.
282
+
283
+ ---
284
+
285
+ ## Architecture
286
+
287
+ Clean architecture, one responsibility per package:
288
+
289
+ ```text
290
+ src/cli_mcp/
291
+ ├── cli/ # Typer entry point (expose/inspect/serve/export/doctor/init)
292
+ ├── discovery/ # provider protocol + strategies
293
+ ├── schema/ # JSON Schema, Markdown docs, OpenAPI
294
+ ├── executor/ # argv building, subprocess execution, approval, sandbox
295
+ ├── mcp/ # MCPServer assembly, tool adapters
296
+ ├── security/ # allow list, read-only rules, access policy
297
+ ├── config/ # pydantic settings + YAML loading
298
+ ├── transport/ # stdio, HTTP, Streamable HTTP, SSE
299
+ └── plugins/ # entry-point based provider discovery
300
+ ```
301
+
302
+ Dependencies point inward: the CLI depends on discovery/schema/executor/security; the MCP
303
+ layer depends on nothing framework-specific. See
304
+ [docs/architecture.md](docs/architecture.md).
305
+
306
+ ---
307
+
308
+ ## Plugin system
309
+
310
+ Third parties add discovery providers without touching core code:
311
+
312
+ ```python
313
+ from cli_mcp.discovery.base import DiscoveryContext, DiscoveryResult, TargetInfo
314
+
315
+
316
+ class MyProvider:
317
+ name = "my-framework"
318
+ strategy = "help"
319
+ frameworks = ("my-framework",)
320
+
321
+ def supports(self, target: TargetInfo) -> bool:
322
+ return target.framework == "my-framework"
323
+
324
+ def discover(self, target: TargetInfo, ctx: DiscoveryContext) -> DiscoveryResult | None:
325
+ ... # return CommandSpecs
326
+ ```
327
+
328
+ Register it:
329
+
330
+ ```toml
331
+ [project.entry-points."cli_mcp.discovery"]
332
+ my-framework = "my_pkg.provider:MyProvider"
333
+ ```
334
+
335
+ `cli-mcp providers` lists every registered provider.
336
+
337
+ ---
338
+
339
+ ## Development
340
+
341
+ ```bash
342
+ uv run ruff check .
343
+ uv run mypy src
344
+ uv run pytest # unit + integration + e2e, coverage gate at 90%
345
+ pre-commit run --all-files
346
+ ```
347
+
348
+ The full test suite creates temporary files and runs Git integration commands.
349
+ For non-invasive validation without test caches, coverage files or generated target scripts,
350
+ use the focused Windows/Linux commands in [security.md](docs/security.md).
351
+
352
+ GitHub Actions run lint, type checking, Windows/Linux tests (Python 3.13/3.14), and
353
+ distribution builds on pushes to `master`/`main` and pull requests. CI can also be started
354
+ manually from the Actions tab. Dependencies are installed from the checked-in lockfile.
355
+
356
+ Published GitHub releases (or a manual Release workflow run) validate and build distributions,
357
+ then upload wheels and source distributions as workflow artifacts. **PyPI publishing is
358
+ disabled** until a publishing account and trusted publisher are explicitly configured.
359
+
360
+ ---
361
+
362
+ ## Examples
363
+
364
+ - [`examples/cli-mcp.yaml`](examples/cli-mcp.yaml) — full configuration
365
+ - [`examples/sample-clis/`](examples/sample-clis) — small argparse/click/typer/commander apps used by the tests
366
+
367
+ ## Documentation
368
+
369
+ - [configuration.md](docs/configuration.md) — every config key and CLI flag
370
+ - [discovery.md](docs/discovery.md) — reflection, help parsing and manifests
371
+ - [security.md](docs/security.md) — allow list, read-only, approval, sandboxing
372
+ - [transports.md](docs/transports.md) — stdio, HTTP, Streamable HTTP, SSE
373
+ - [clients.md](docs/clients.md) — configuration recipes for Claude, VS Code, Cursor, Cline, Open WebUI
374
+ - [plugins.md](docs/plugins.md) — adding a discovery provider for a new framework
375
+ - [architecture.md](docs/architecture.md) — how the pipeline fits together
376
+
377
+ ---
378
+
379
+ ## License
380
+
381
+ Apache License 2.0 — see [LICENSE](LICENSE).