cli-builder-ai-mcp 1.0.0__py3-none-any.whl
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.
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cli-builder-ai-mcp
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Cli Builder Ai automation via MCP. Includes generate argparse, generate click, parse help text. By MEOK AI Labs.
|
|
5
|
+
Project-URL: Homepage, https://meok.ai
|
|
6
|
+
Project-URL: Repository, https://github.com/CSOAI-ORG/cli-builder-ai-mcp
|
|
7
|
+
Author-email: MEOK AI Labs <nicholas@meok.ai>
|
|
8
|
+
License: MIT License
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2026 MEOK AI Labs
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
in the Software without restriction, including without limitation the rights
|
|
15
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
furnished to do so, subject to the following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
copies or substantial portions of the Software.
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Keywords: ai,builder,cli,mcp,meok
|
|
23
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
24
|
+
Classifier: Operating System :: OS Independent
|
|
25
|
+
Classifier: Programming Language :: Python :: 3
|
|
26
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
27
|
+
Requires-Python: >=3.10
|
|
28
|
+
Requires-Dist: mcp>=1.0.0
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
server.py,sha256=KRAlTtPrsESQypbYNKmDwDTeRhCT1FHNeuM-17S2d3w,10723
|
|
2
|
+
cli_builder_ai_mcp-1.0.0.dist-info/METADATA,sha256=UTBfqcwtt4K9zq8AN_J_lBKyYMqmeYyuXNRXtIDehLI,1361
|
|
3
|
+
cli_builder_ai_mcp-1.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
4
|
+
cli_builder_ai_mcp-1.0.0.dist-info/entry_points.txt,sha256=OYaBKAUs3k0U7ZewaRZ4mBnaXVrgLSgDfW1focykMKQ,51
|
|
5
|
+
cli_builder_ai_mcp-1.0.0.dist-info/licenses/LICENSE,sha256=ibFbFVuWMg3hkFJtLijRTUi6DDoUbdR4oE78M6MKq-I,607
|
|
6
|
+
cli_builder_ai_mcp-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MEOK AI Labs
|
|
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.
|
server.py
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CLI Builder AI MCP Server
|
|
3
|
+
CLI tool generation and parsing utilities powered by MEOK AI Labs.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
import sys, os
|
|
8
|
+
sys.path.insert(0, os.path.expanduser('~/clawd/meok-labs-engine/shared'))
|
|
9
|
+
from auth_middleware import check_access
|
|
10
|
+
|
|
11
|
+
import re
|
|
12
|
+
import time
|
|
13
|
+
from collections import defaultdict
|
|
14
|
+
from mcp.server.fastmcp import FastMCP
|
|
15
|
+
|
|
16
|
+
mcp = FastMCP("cli-builder-ai", instructions="MEOK AI Labs MCP Server")
|
|
17
|
+
|
|
18
|
+
_call_counts: dict[str, list[float]] = defaultdict(list)
|
|
19
|
+
FREE_TIER_LIMIT = 50
|
|
20
|
+
WINDOW = 86400
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _check_rate_limit(tool_name: str) -> None:
|
|
24
|
+
now = time.time()
|
|
25
|
+
_call_counts[tool_name] = [t for t in _call_counts[tool_name] if now - t < WINDOW]
|
|
26
|
+
if len(_call_counts[tool_name]) >= FREE_TIER_LIMIT:
|
|
27
|
+
raise ValueError(f"Rate limit exceeded for {tool_name}. Free tier: {FREE_TIER_LIMIT}/day. Upgrade at https://meok.ai/pricing")
|
|
28
|
+
_call_counts[tool_name].append(now)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@mcp.tool()
|
|
32
|
+
def generate_argparse(
|
|
33
|
+
program_name: str, description: str, arguments: list[dict], subcommands: list[dict] | None = None
|
|
34
|
+
, api_key: str = "") -> dict:
|
|
35
|
+
"""Generate Python argparse CLI boilerplate code.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
program_name: CLI program name
|
|
39
|
+
description: Program description
|
|
40
|
+
arguments: List of argument dicts with keys: name, type (str/int/float/bool), help, required (bool), default (optional), choices (list, optional)
|
|
41
|
+
subcommands: Optional list of subcommand dicts with keys: name, help, arguments (same format)
|
|
42
|
+
"""
|
|
43
|
+
allowed, msg, tier = check_access(api_key)
|
|
44
|
+
if not allowed:
|
|
45
|
+
return {"error": msg, "upgrade_url": "https://meok.ai/pricing"}
|
|
46
|
+
|
|
47
|
+
_check_rate_limit("generate_argparse")
|
|
48
|
+
lines = ['import argparse', '', '']
|
|
49
|
+
lines.append('def main():')
|
|
50
|
+
lines.append(f' parser = argparse.ArgumentParser(')
|
|
51
|
+
lines.append(f' prog="{program_name}",')
|
|
52
|
+
lines.append(f' description="{description}"')
|
|
53
|
+
lines.append(f' )')
|
|
54
|
+
|
|
55
|
+
def _add_arg(arg, indent=" "):
|
|
56
|
+
name = arg["name"]
|
|
57
|
+
is_positional = not name.startswith("-")
|
|
58
|
+
parts = [f'{indent}parser.add_argument(']
|
|
59
|
+
if is_positional:
|
|
60
|
+
parts.append(f'{indent} "{name}",')
|
|
61
|
+
else:
|
|
62
|
+
short = f'-{name.lstrip("-")[0]}'
|
|
63
|
+
parts.append(f'{indent} "{short}", "{name}",')
|
|
64
|
+
atype = arg.get("type", "str")
|
|
65
|
+
if atype == "bool":
|
|
66
|
+
parts.append(f'{indent} action="store_true",')
|
|
67
|
+
else:
|
|
68
|
+
type_map = {"str": "str", "int": "int", "float": "float"}
|
|
69
|
+
parts.append(f'{indent} type={type_map.get(atype, "str")},')
|
|
70
|
+
if arg.get("help"):
|
|
71
|
+
parts.append(f'{indent} help="{arg["help"]}",')
|
|
72
|
+
if arg.get("default") is not None:
|
|
73
|
+
d = arg["default"]
|
|
74
|
+
parts.append(f'{indent} default={repr(d)},')
|
|
75
|
+
if arg.get("required") and not is_positional:
|
|
76
|
+
parts.append(f'{indent} required=True,')
|
|
77
|
+
if arg.get("choices"):
|
|
78
|
+
parts.append(f'{indent} choices={arg["choices"]},')
|
|
79
|
+
parts.append(f'{indent})')
|
|
80
|
+
return parts
|
|
81
|
+
|
|
82
|
+
for arg in arguments:
|
|
83
|
+
lines.extend(_add_arg(arg))
|
|
84
|
+
|
|
85
|
+
if subcommands:
|
|
86
|
+
lines.append(' subparsers = parser.add_subparsers(dest="command", help="Available commands")')
|
|
87
|
+
for sub in subcommands:
|
|
88
|
+
var = sub["name"].replace("-", "_")
|
|
89
|
+
lines.append(f' parser_{var} = subparsers.add_parser("{sub["name"]}", help="{sub.get("help", "")}")')
|
|
90
|
+
for arg in sub.get("arguments", []):
|
|
91
|
+
old_lines = _add_arg(arg, " ")
|
|
92
|
+
for l in old_lines:
|
|
93
|
+
lines.append(l.replace("parser.add_argument", f"parser_{var}.add_argument"))
|
|
94
|
+
|
|
95
|
+
lines.append(' args = parser.parse_args()')
|
|
96
|
+
lines.append(' print(args)')
|
|
97
|
+
lines.append('')
|
|
98
|
+
lines.append('')
|
|
99
|
+
lines.append('if __name__ == "__main__":')
|
|
100
|
+
lines.append(' main()')
|
|
101
|
+
code = '\n'.join(lines)
|
|
102
|
+
return {"code": code, "language": "python", "program_name": program_name,
|
|
103
|
+
"argument_count": len(arguments), "subcommand_count": len(subcommands or [])}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
@mcp.tool()
|
|
107
|
+
def generate_click(
|
|
108
|
+
program_name: str, description: str, commands: list[dict]
|
|
109
|
+
, api_key: str = "") -> dict:
|
|
110
|
+
"""Generate Python Click CLI boilerplate code.
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
program_name: CLI program name
|
|
114
|
+
description: Program description
|
|
115
|
+
commands: List of command dicts with keys: name, help, options (list of dicts with: name, type, help, required, default)
|
|
116
|
+
"""
|
|
117
|
+
allowed, msg, tier = check_access(api_key)
|
|
118
|
+
if not allowed:
|
|
119
|
+
return {"error": msg, "upgrade_url": "https://meok.ai/pricing"}
|
|
120
|
+
|
|
121
|
+
_check_rate_limit("generate_click")
|
|
122
|
+
lines = ['import click', '', '']
|
|
123
|
+
lines.append(f'@click.group()')
|
|
124
|
+
lines.append(f'def cli():')
|
|
125
|
+
lines.append(f' """{description}"""')
|
|
126
|
+
lines.append(f' pass')
|
|
127
|
+
lines.append('')
|
|
128
|
+
|
|
129
|
+
for cmd in commands:
|
|
130
|
+
lines.append(f'@cli.command()')
|
|
131
|
+
for opt in cmd.get("options", []):
|
|
132
|
+
name = opt["name"].lstrip("-")
|
|
133
|
+
otype = opt.get("type", "str")
|
|
134
|
+
type_map = {"str": "str", "int": "int", "float": "float", "bool": "bool"}
|
|
135
|
+
click_type = type_map.get(otype, "str")
|
|
136
|
+
parts = [f'@click.option("--{name}"']
|
|
137
|
+
if click_type == "bool":
|
|
138
|
+
parts[0] = f'@click.option("--{name}/--no-{name}"'
|
|
139
|
+
else:
|
|
140
|
+
parts.append(f'type={click_type}')
|
|
141
|
+
if opt.get("help"):
|
|
142
|
+
parts.append(f'help="{opt["help"]}"')
|
|
143
|
+
if opt.get("required"):
|
|
144
|
+
parts.append('required=True')
|
|
145
|
+
if opt.get("default") is not None:
|
|
146
|
+
parts.append(f'default={repr(opt["default"])}')
|
|
147
|
+
lines.append(', '.join(parts) + ')')
|
|
148
|
+
params = ', '.join(opt["name"].lstrip("-").replace("-", "_") for opt in cmd.get("options", []))
|
|
149
|
+
lines.append(f'def {cmd["name"].replace("-", "_")}({params}):')
|
|
150
|
+
lines.append(f' """{cmd.get("help", "")}"""')
|
|
151
|
+
lines.append(f' click.echo(f"Running {cmd["name"]}")')
|
|
152
|
+
lines.append('')
|
|
153
|
+
|
|
154
|
+
lines.append('')
|
|
155
|
+
lines.append('if __name__ == "__main__":')
|
|
156
|
+
lines.append(' cli()')
|
|
157
|
+
code = '\n'.join(lines)
|
|
158
|
+
return {"code": code, "language": "python", "program_name": program_name,
|
|
159
|
+
"command_count": len(commands)}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
@mcp.tool()
|
|
163
|
+
def parse_help_text(help_text: str, api_key: str = "") -> dict:
|
|
164
|
+
"""Parse CLI help text output into structured command/option data.
|
|
165
|
+
|
|
166
|
+
Args:
|
|
167
|
+
help_text: CLI help text output (e.g., from --help)
|
|
168
|
+
"""
|
|
169
|
+
allowed, msg, tier = check_access(api_key)
|
|
170
|
+
if not allowed:
|
|
171
|
+
return {"error": msg, "upgrade_url": "https://meok.ai/pricing"}
|
|
172
|
+
|
|
173
|
+
_check_rate_limit("parse_help_text")
|
|
174
|
+
result = {"program": "", "description": "", "commands": [], "options": [], "positional_args": []}
|
|
175
|
+
lines = help_text.strip().split('\n')
|
|
176
|
+
if lines:
|
|
177
|
+
usage_match = re.match(r'[Uu]sage:\s*(\S+)', lines[0])
|
|
178
|
+
if usage_match:
|
|
179
|
+
result["program"] = usage_match.group(1)
|
|
180
|
+
in_section = None
|
|
181
|
+
for line in lines:
|
|
182
|
+
stripped = line.strip()
|
|
183
|
+
if re.match(r'^(options|optional arguments|flags):', stripped, re.IGNORECASE):
|
|
184
|
+
in_section = "options"
|
|
185
|
+
continue
|
|
186
|
+
elif re.match(r'^(commands|subcommands):', stripped, re.IGNORECASE):
|
|
187
|
+
in_section = "commands"
|
|
188
|
+
continue
|
|
189
|
+
elif re.match(r'^(positional arguments|arguments):', stripped, re.IGNORECASE):
|
|
190
|
+
in_section = "positional"
|
|
191
|
+
continue
|
|
192
|
+
elif stripped and not stripped.startswith('-') and not line.startswith(' ') and in_section is None:
|
|
193
|
+
if not result["description"]:
|
|
194
|
+
result["description"] = stripped
|
|
195
|
+
continue
|
|
196
|
+
if in_section == "options":
|
|
197
|
+
opt_match = re.match(r'\s+(-\w(?:,\s*)?)?(?:\s*(--[\w-]+))?\s*(\S.*)?', line)
|
|
198
|
+
if opt_match:
|
|
199
|
+
short = (opt_match.group(1) or "").strip().rstrip(',')
|
|
200
|
+
long_opt = (opt_match.group(2) or "").strip()
|
|
201
|
+
desc = (opt_match.group(3) or "").strip()
|
|
202
|
+
if short or long_opt:
|
|
203
|
+
result["options"].append({"short": short, "long": long_opt, "description": desc})
|
|
204
|
+
elif in_section == "commands":
|
|
205
|
+
cmd_match = re.match(r'\s+(\S+)\s+(.*)', line)
|
|
206
|
+
if cmd_match:
|
|
207
|
+
result["commands"].append({"name": cmd_match.group(1), "description": cmd_match.group(2).strip()})
|
|
208
|
+
elif in_section == "positional":
|
|
209
|
+
pos_match = re.match(r'\s+(\S+)\s+(.*)', line)
|
|
210
|
+
if pos_match:
|
|
211
|
+
result["positional_args"].append({"name": pos_match.group(1), "description": pos_match.group(2).strip()})
|
|
212
|
+
return result
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
@mcp.tool()
|
|
216
|
+
def generate_manpage(
|
|
217
|
+
program_name: str, description: str, version: str = "1.0.0",
|
|
218
|
+
synopsis: str = "", options: list[dict] | None = None, examples: list[dict] | None = None,
|
|
219
|
+
author: str = ""
|
|
220
|
+
, api_key: str = "") -> dict:
|
|
221
|
+
"""Generate a man page in troff format.
|
|
222
|
+
|
|
223
|
+
Args:
|
|
224
|
+
program_name: Program name
|
|
225
|
+
description: Program description
|
|
226
|
+
version: Version string
|
|
227
|
+
synopsis: Usage synopsis line
|
|
228
|
+
options: List of option dicts with keys: flag, description
|
|
229
|
+
examples: List of example dicts with keys: command, description
|
|
230
|
+
author: Author name
|
|
231
|
+
"""
|
|
232
|
+
allowed, msg, tier = check_access(api_key)
|
|
233
|
+
if not allowed:
|
|
234
|
+
return {"error": msg, "upgrade_url": "https://meok.ai/pricing"}
|
|
235
|
+
|
|
236
|
+
_check_rate_limit("generate_manpage")
|
|
237
|
+
from datetime import date
|
|
238
|
+
today = date.today().strftime("%B %Y")
|
|
239
|
+
name_upper = program_name.upper()
|
|
240
|
+
lines = [
|
|
241
|
+
f'.TH {name_upper} 1 "{today}" "v{version}" "User Commands"',
|
|
242
|
+
'.SH NAME',
|
|
243
|
+
f'{program_name} \\- {description}',
|
|
244
|
+
]
|
|
245
|
+
if synopsis:
|
|
246
|
+
lines.extend(['.SH SYNOPSIS', f'.B {program_name}', f'{synopsis}'])
|
|
247
|
+
lines.extend(['.SH DESCRIPTION', f'{description}'])
|
|
248
|
+
if options:
|
|
249
|
+
lines.append('.SH OPTIONS')
|
|
250
|
+
for opt in options:
|
|
251
|
+
lines.append(f'.TP')
|
|
252
|
+
lines.append(f'.B {opt["flag"]}')
|
|
253
|
+
lines.append(opt["description"])
|
|
254
|
+
if examples:
|
|
255
|
+
lines.append('.SH EXAMPLES')
|
|
256
|
+
for ex in examples:
|
|
257
|
+
lines.append(f'.TP')
|
|
258
|
+
lines.append(f'.B {ex["command"]}')
|
|
259
|
+
lines.append(ex.get("description", ""))
|
|
260
|
+
if author:
|
|
261
|
+
lines.extend(['.SH AUTHOR', f'Written by {author}.'])
|
|
262
|
+
lines.extend(['.SH VERSION', f'v{version}'])
|
|
263
|
+
manpage = '\n'.join(lines)
|
|
264
|
+
return {"manpage": manpage, "program": program_name, "format": "troff",
|
|
265
|
+
"sections": sum(1 for l in lines if l.startswith('.SH'))}
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
if __name__ == "__main__":
|
|
269
|
+
mcp.run()
|