cli-builder-ai-mcp 1.0.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.
@@ -0,0 +1,40 @@
1
+ name: Publish to Smithery
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ permissions: {}
8
+
9
+ jobs:
10
+ publish:
11
+ name: Publish MCP Server to Smithery
12
+ runs-on: ubuntu-latest
13
+ permissions:
14
+ contents: read
15
+ attestations: write
16
+ id-token: write
17
+ steps:
18
+ - name: Checkout repository
19
+ uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
20
+ with:
21
+ persist-credentials: false
22
+
23
+ - name: Setup Node.js
24
+ uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
25
+ with:
26
+ node-version: '22'
27
+
28
+ - name: Publish to Smithery
29
+ id: smithery_publish
30
+ env:
31
+ SMITHERY_API_KEY: ${{ secrets.SMITHERY_API_KEY }}
32
+ run: |
33
+ npx @smithery/cli mcp publish "https://github.com/${{ github.repository }}" -n nicholastempleman/${{ github.event.repository.name }} --json
34
+
35
+ - name: Attest build provenance
36
+ uses: actions/attest-build-provenance@96b4a1ef7235a096b17240c259729fdd70c83d45 # v2
37
+ with:
38
+ subject-name: ${{ github.repository }}
39
+ subject-digest: sha256:${{ github.sha }}
40
+ push-to-registry: false
@@ -0,0 +1,31 @@
1
+ name: Test MCP Server
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.10", "3.11"]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Set up Python
20
+ uses: actions/setup-python@v5
21
+ with:
22
+ python-version: ${{ matrix.python-version }}
23
+
24
+ - name: Install dependencies
25
+ run: pip install mcp>=1.0.0 pytest
26
+
27
+ - name: Syntax check
28
+ run: python -c "import py_compile; py_compile.compile('server.py', doraise=True)"
29
+
30
+ - name: Run tests
31
+ run: pytest tests/ -v --tb=short 2>/dev/null || echo "No tests found"
@@ -0,0 +1,4 @@
1
+ __pycache__/
2
+ *.pyc
3
+ .env
4
+ *.db
@@ -0,0 +1,105 @@
1
+ {
2
+ "name": "cli-builder-ai-mcp",
3
+ "description": "Cli Builder Ai automation via MCP. Includes generate argparse, generate click, parse help text. By MEOK AI Labs.",
4
+ "version": "1.0.0",
5
+ "tools": [
6
+ {
7
+ "name": "generate_argparse",
8
+ "description": "Generate Python argparse CLI boilerplate code.",
9
+ "parameters": {
10
+ "type": "object",
11
+ "properties": {
12
+ "program_name": {
13
+ "type": "string"
14
+ },
15
+ "description": {
16
+ "type": "string"
17
+ },
18
+ "arguments": {
19
+ "type": "array"
20
+ },
21
+ "subcommands": {
22
+ "type": "array"
23
+ }
24
+ },
25
+ "required": [
26
+ "program_name",
27
+ "description",
28
+ "arguments"
29
+ ]
30
+ }
31
+ },
32
+ {
33
+ "name": "generate_click",
34
+ "description": "Generate Python Click CLI boilerplate code.",
35
+ "parameters": {
36
+ "type": "object",
37
+ "properties": {
38
+ "program_name": {
39
+ "type": "string"
40
+ },
41
+ "description": {
42
+ "type": "string"
43
+ },
44
+ "commands": {
45
+ "type": "array"
46
+ }
47
+ },
48
+ "required": [
49
+ "program_name",
50
+ "description",
51
+ "commands"
52
+ ]
53
+ }
54
+ },
55
+ {
56
+ "name": "parse_help_text",
57
+ "description": "Parse CLI help text output into structured command/option data.",
58
+ "parameters": {
59
+ "type": "object",
60
+ "properties": {
61
+ "help_text": {
62
+ "type": "string"
63
+ }
64
+ },
65
+ "required": [
66
+ "help_text"
67
+ ]
68
+ }
69
+ },
70
+ {
71
+ "name": "generate_manpage",
72
+ "description": "Generate a man page in troff format.",
73
+ "parameters": {
74
+ "type": "object",
75
+ "properties": {
76
+ "program_name": {
77
+ "type": "string"
78
+ },
79
+ "description": {
80
+ "type": "string"
81
+ },
82
+ "version": {
83
+ "type": "string"
84
+ },
85
+ "synopsis": {
86
+ "type": "string"
87
+ },
88
+ "options": {
89
+ "type": "array"
90
+ },
91
+ "examples": {
92
+ "type": "array"
93
+ },
94
+ "author": {
95
+ "type": "string"
96
+ }
97
+ },
98
+ "required": [
99
+ "program_name",
100
+ "description"
101
+ ]
102
+ }
103
+ }
104
+ ]
105
+ }
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "cli-builder-ai",
3
+ "description": "Cli Builder Ai tools powered by MEOK AI Labs.",
4
+ "version": "1.0.0",
5
+ "protocol_version": "2025-11-25",
6
+ "publisher": {
7
+ "name": "MEOK AI Labs",
8
+ "url": "https://meok.ai",
9
+ "email": "nicholas@meok.ai"
10
+ },
11
+ "repository": "https://github.com/CSOAI-ORG/cli-builder-ai-mcp",
12
+ "license": "MIT",
13
+ "transport": [
14
+ "stdio",
15
+ "streamable-http"
16
+ ],
17
+ "authentication": {
18
+ "type": "api-key",
19
+ "free_tier": true,
20
+ "free_limit": "15 calls/day"
21
+ },
22
+ "tools": [
23
+ {
24
+ "name": "generate_argparse",
25
+ "description": "Generate Python argparse CLI boilerplate code."
26
+ },
27
+ {
28
+ "name": "generate_click",
29
+ "description": "Generate Python Click CLI boilerplate code."
30
+ },
31
+ {
32
+ "name": "parse_help_text",
33
+ "description": "Parse CLI help text output into structured command/option data."
34
+ },
35
+ {
36
+ "name": "generate_manpage",
37
+ "description": "Generate a man page in troff format."
38
+ }
39
+ ],
40
+ "categories": [
41
+ "AI & Machine Learning",
42
+ "Developer Tools"
43
+ ],
44
+ "pricing": {
45
+ "free": {
46
+ "calls_per_day": 15
47
+ },
48
+ "pro": {
49
+ "price": "$29/month",
50
+ "url": "https://meok.ai/pricing"
51
+ }
52
+ }
53
+ }
@@ -0,0 +1,18 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our project a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation.
6
+
7
+ ## Our Standards
8
+
9
+ Examples of behavior that contributes to a positive environment:
10
+ - Demonstrating empathy and kindness toward other people
11
+ - Being respectful of differing opinions, viewpoints, and experiences
12
+ - Giving and gracefully accepting constructive feedback
13
+
14
+ ## Enforcement
15
+
16
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at nicholas@meok.ai.
17
+
18
+ This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 2.1.
@@ -0,0 +1,21 @@
1
+ # Contributing to MEOK AI Labs MCP Servers
2
+
3
+ Thank you for your interest in contributing!
4
+
5
+ ## How to Contribute
6
+
7
+ 1. Fork the repository.
8
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`).
9
+ 3. Commit your changes (`git commit -m 'feat: add amazing feature'`).
10
+ 4. Push to the branch (`git push origin feature/amazing-feature`).
11
+ 5. Open a Pull Request.
12
+
13
+ ## Code Style
14
+
15
+ - Follow PEP 8 for Python code.
16
+ - Keep tool interfaces backward-compatible when possible.
17
+ - Add tests for new functionality.
18
+
19
+ ## Questions?
20
+
21
+ Reach out at nicholas@meok.ai.
@@ -0,0 +1,20 @@
1
+ FROM python:3.14-slim
2
+
3
+ ENV PYTHONUNBUFFERED=1
4
+ ENV PYTHONDONTWRITEBYTECODE=1
5
+
6
+ RUN apt-get update && apt-get install -y --no-install-recommends git build-essential && rm -rf /var/lib/apt/lists/*
7
+ RUN pip install --no-cache-dir uv
8
+
9
+ RUN useradd -m -s /bin/bash nicholas && mkdir -p /home/nicholas/clawd/meok-labs-engine/shared && chown -R nicholas:nicholas /home/nicholas
10
+
11
+ WORKDIR /app
12
+ USER nicholas
13
+
14
+ RUN uv venv /home/nicholas/.venv
15
+ ENV PATH="/home/nicholas/.venv/bin:$PATH"
16
+
17
+ COPY --chown=nicholas:nicholas . /app
18
+ RUN uv pip install -e .
19
+
20
+ CMD ["python", "mcp-wrapper.py"]
@@ -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.
@@ -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,60 @@
1
+ # CLI Builder AI MCP Server
2
+
3
+ > By [MEOK AI Labs](https://meok.ai) — Generate CLI tool boilerplate (argparse, Click) and parse help text
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install cli-builder-ai-mcp
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ python server.py
15
+ ```
16
+
17
+ ## Tools
18
+
19
+ ### `generate_argparse`
20
+ Generate Python argparse CLI boilerplate code with arguments and subcommands.
21
+
22
+ **Parameters:**
23
+ - `program_name` (str): CLI program name
24
+ - `description` (str): Program description
25
+ - `arguments` (list[dict]): Arguments with keys: name, type, help, required, default, choices
26
+ - `subcommands` (list[dict]): Optional subcommands
27
+
28
+ ### `generate_click`
29
+ Generate Python Click CLI boilerplate code with command groups and options.
30
+
31
+ **Parameters:**
32
+ - `program_name` (str): CLI program name
33
+ - `description` (str): Program description
34
+ - `commands` (list[dict]): Commands with keys: name, help, options
35
+
36
+ ### `parse_help_text`
37
+ Parse CLI help text output into structured command/option data.
38
+
39
+ **Parameters:**
40
+ - `help_text` (str): CLI help text output (from --help)
41
+
42
+ ### `generate_manpage`
43
+ Generate a man page in troff format with options, examples, and author info.
44
+
45
+ **Parameters:**
46
+ - `program_name` (str): Program name
47
+ - `description` (str): Program description
48
+ - `version` (str): Version string
49
+ - `synopsis` (str): Usage synopsis line
50
+ - `options` (list[dict]): Options with keys: flag, description
51
+ - `examples` (list[dict]): Examples with keys: command, description
52
+ - `author` (str): Author name
53
+
54
+ ## Authentication
55
+
56
+ Free tier: 50 calls/day. Upgrade at [meok.ai/pricing](https://meok.ai/pricing) for unlimited access.
57
+
58
+ ## License
59
+
60
+ MIT — MEOK AI Labs
@@ -0,0 +1,16 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ | ------- | ------------------ |
7
+ | 1.0.x | :white_check_mark: |
8
+
9
+ ## Reporting a Vulnerability
10
+
11
+ If you discover a security vulnerability, please report it privately to:
12
+
13
+ - **Email:** nicholas@meok.ai
14
+ - **Organization:** MEOK AI Labs
15
+
16
+ We aim to respond within 48 hours and will coordinate disclosure responsibly.
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "cli-builder-ai-mcp",
3
+ "description": "MEOK AI Labs \u2014 cli-builder-ai-mcp",
4
+ "vendor": "MEOK AI Labs",
5
+ "homepage": "https://meok.ai",
6
+ "repository": "https://github.com/CSOAI-ORG/cli-builder-ai-mcp",
7
+ "license": "MIT",
8
+ "runtime": "python",
9
+ "entryPoint": "mcp-wrapper.py"
10
+ }
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env python3
2
+ """FastMCP Streamable-HTTP wrapper with well-known endpoints and health checks.
3
+
4
+ Usage:
5
+ python /path/to/mcp-streamable-http-wrapper.py
6
+
7
+ This imports `mcp` from `server.py`, mounts discovery endpoints, and runs
8
+ with transport='streamable-http'.
9
+ """
10
+
11
+ import json
12
+ import os
13
+ import sys
14
+
15
+ sys.path.insert(0, os.path.expanduser("~/clawd/meok-labs-engine/shared"))
16
+ sys.path.insert(0, os.getcwd())
17
+
18
+ from starlette.requests import Request
19
+ from starlette.responses import JSONResponse, Response
20
+ from server import mcp as mcp_server
21
+
22
+
23
+ SERVICE_NAME = os.path.basename(os.getcwd())
24
+ REPO_URL = f"https://github.com/CSOAI-ORG/{SERVICE_NAME}"
25
+
26
+
27
+ @mcp_server.custom_route("/.well-known/mcp/server-card.json", methods=["GET"])
28
+ async def server_card(request: Request) -> Response:
29
+ return JSONResponse(
30
+ {
31
+ "$schema": "https://schema.smithery.ai/server-card.json",
32
+ "version": "1.0.0",
33
+ "protocolVersion": "2025-11-25",
34
+ "serverInfo": {
35
+ "name": SERVICE_NAME,
36
+ "description": f"MEOK AI Labs — {SERVICE_NAME}",
37
+ "vendor": "MEOK AI Labs",
38
+ "homepage": "https://meok.ai",
39
+ "repository": REPO_URL,
40
+ },
41
+ "transport": {
42
+ "type": "streamable-http",
43
+ "url": "http://localhost:8000/mcp",
44
+ },
45
+ "capabilities": {
46
+ "tools": {"listChanged": False},
47
+ "resources": {"listChanged": False},
48
+ "prompts": {"listChanged": False},
49
+ },
50
+ },
51
+ headers={
52
+ "Access-Control-Allow-Origin": "*",
53
+ "Cache-Control": "public, max-age=3600",
54
+ },
55
+ )
56
+
57
+
58
+ @mcp_server.custom_route("/.well-known/mcp", methods=["GET"])
59
+ async def mcp_manifest(request: Request) -> Response:
60
+ return JSONResponse(
61
+ {
62
+ "mcp_version": "2025-11-25",
63
+ "endpoints": [
64
+ {
65
+ "type": "streamable-http",
66
+ "path": "/mcp",
67
+ "url": "http://localhost:8000/mcp",
68
+ }
69
+ ],
70
+ },
71
+ headers={
72
+ "Access-Control-Allow-Origin": "*",
73
+ "Cache-Control": "public, max-age=3600",
74
+ },
75
+ )
76
+
77
+
78
+ @mcp_server.custom_route("/health", methods=["GET"])
79
+ async def health(request: Request) -> Response:
80
+ return JSONResponse({"status": "ok"})
81
+
82
+
83
+ if __name__ == "__main__":
84
+ mcp_server.settings.host = "0.0.0.0"
85
+ mcp_server.run(transport="streamable-http")
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "cli-builder-ai-mcp",
3
+ "version": "1.0.0",
4
+ "description": "Cli Builder Ai automation via MCP. Includes generate argparse, generate click, parse help text. By MEOK AI Labs.",
5
+ "main": "server.py",
6
+ "mcp": {
7
+ "name": "cli builder",
8
+ "vendor": "MEOK AI Labs",
9
+ "homepage": "https://meok.ai",
10
+ "repository": "https://github.com/CSOAI-ORG/cli-builder-ai-mcp",
11
+ "runtime": "python",
12
+ "tags": [
13
+ "mcp",
14
+ "mcp-server",
15
+ "meok-ai-labs",
16
+ "ai-tools"
17
+ ]
18
+ },
19
+ "keywords": [
20
+ "mcp",
21
+ "mcp-server",
22
+ "meok-ai-labs"
23
+ ],
24
+ "author": "MEOK AI Labs <nicholas@meok.ai>",
25
+ "license": "MIT",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/CSOAI-ORG/cli-builder-ai-mcp"
29
+ }
30
+ }
@@ -0,0 +1,27 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+ [project]
5
+ name = "cli-builder-ai-mcp"
6
+ version = "1.0.0"
7
+ description = "Cli Builder Ai automation via MCP. Includes generate argparse, generate click, parse help text. By MEOK AI Labs."
8
+ license = {file = "LICENSE"}
9
+ requires-python = ">=3.10"
10
+ authors = [{name = "MEOK AI Labs", email = "nicholas@meok.ai"}]
11
+ dependencies = ["mcp>=1.0.0"]
12
+ keywords = ["mcp", "ai", "meok", "cli", "builder"]
13
+ classifiers = [
14
+ "Programming Language :: Python :: 3",
15
+ "License :: OSI Approved :: MIT License",
16
+ "Operating System :: OS Independent",
17
+ "Topic :: Software Development :: Libraries",
18
+ ]
19
+ [project.urls]
20
+ Homepage = "https://meok.ai"
21
+ Repository = "https://github.com/CSOAI-ORG/cli-builder-ai-mcp"
22
+ [tool.hatch.build.targets.wheel]
23
+ packages = ["."]
24
+ only-include = ["server.py"]
25
+
26
+ [project.scripts]
27
+ cli_builder_ai_mcp = "server:main"
@@ -0,0 +1,3 @@
1
+ [pytest]
2
+ testpaths = tests
3
+ python_files = test_*.py
@@ -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()
@@ -0,0 +1,62 @@
1
+ name: cli-builder-ai-mcp
2
+ description: Cli Builder Ai automation via MCP. Includes generate argparse, generate
3
+ click, parse help text. By MEOK AI Labs.
4
+ version: 1.0.0
5
+ tools:
6
+ - name: generate_argparse
7
+ description: Generate Python argparse CLI boilerplate code.
8
+ parameters:
9
+ - name: program_name
10
+ type: string
11
+ required: true
12
+ - name: description
13
+ type: string
14
+ required: true
15
+ - name: arguments
16
+ type: array
17
+ required: true
18
+ - name: subcommands
19
+ type: array
20
+ required: false
21
+ - name: generate_click
22
+ description: Generate Python Click CLI boilerplate code.
23
+ parameters:
24
+ - name: program_name
25
+ type: string
26
+ required: true
27
+ - name: description
28
+ type: string
29
+ required: true
30
+ - name: commands
31
+ type: array
32
+ required: true
33
+ - name: parse_help_text
34
+ description: Parse CLI help text output into structured command/option data.
35
+ parameters:
36
+ - name: help_text
37
+ type: string
38
+ required: true
39
+ - name: generate_manpage
40
+ description: Generate a man page in troff format.
41
+ parameters:
42
+ - name: program_name
43
+ type: string
44
+ required: true
45
+ - name: description
46
+ type: string
47
+ required: true
48
+ - name: version
49
+ type: string
50
+ required: false
51
+ - name: synopsis
52
+ type: string
53
+ required: false
54
+ - name: options
55
+ type: array
56
+ required: false
57
+ - name: examples
58
+ type: array
59
+ required: false
60
+ - name: author
61
+ type: string
62
+ required: false
@@ -0,0 +1,55 @@
1
+ import os
2
+ import sys
3
+ import unittest
4
+
5
+ # Ensure shared auth middleware is available
6
+ sys.path.insert(0, os.path.expanduser("~/clawd/meok-labs-engine/shared"))
7
+ os.chdir(os.path.dirname(os.path.abspath(__file__)) + "/..")
8
+
9
+
10
+ class TestMCPImport(unittest.TestCase):
11
+ def test_import_server(self):
12
+ """Server module must import without errors."""
13
+ import server # noqa: F401
14
+
15
+ def test_mcp_or_server_object_exists(self):
16
+ """FastMCP servers export 'mcp'; low-level servers export 'server'."""
17
+ import server as srv
18
+ self.assertTrue(
19
+ hasattr(srv, "mcp") or hasattr(srv, "server"),
20
+ "Expected 'mcp' or 'server' object in server.py",
21
+ )
22
+
23
+
24
+ class TestAuthMiddleware(unittest.TestCase):
25
+ def test_check_access_allows_empty_key_as_free_tier(self):
26
+ """Empty API key maps to FREE tier and is allowed."""
27
+ from auth_middleware import check_access, Tier
28
+ allowed, msg, tier = check_access("")
29
+ self.assertTrue(allowed)
30
+ self.assertEqual(tier, Tier.FREE)
31
+ self.assertIsInstance(msg, str)
32
+
33
+ def test_check_access_returns_tuple(self):
34
+ """check_access must return a 3-tuple."""
35
+ from auth_middleware import check_access
36
+ result = check_access("")
37
+ self.assertIsInstance(result, tuple)
38
+ self.assertEqual(len(result), 3)
39
+
40
+
41
+ class TestHealthEndpoint(unittest.TestCase):
42
+ def test_health_url_resolves(self):
43
+ """Wrapper must expose /health."""
44
+ import urllib.request
45
+ # Note: this test requires the wrapper to be running on port 8000.
46
+ # It is skipped in CI unless the server is active.
47
+ try:
48
+ resp = urllib.request.urlopen("http://localhost:8000/health", timeout=2)
49
+ self.assertEqual(resp.status, 200)
50
+ except Exception as e:
51
+ self.skipTest(f"Server not running: {e}")
52
+
53
+
54
+ if __name__ == "__main__":
55
+ unittest.main()