Skip to main content

A simple, extensible git like CLI framework.

Project description

monxcli

Getting started

an arg parser decorator to simplify argument parsing

Name

monxcli

Description

"A lightweight and extensible CLI framework for building modular, Git-like command-line tools. Simplify command grouping, subcommand handling, and argument parsing with a decorator-based approach."

Usage

the following structure should be use. Scripts are group according to modules

<folder>/
        + <folder>/
            - yourscript.py
        main.py

example
monxcli
├── monxcli/
├── main.py
├── mc <-- example scripts are in this module 
│   ├── __init__.py
│   └── math_commands.py

using the decorator example:

MonxCLI integrates with fastmcp to seamlessly expose your CLI commands as AI-callable tools, prompts, and resources. This is achieved using specialized decorators.

Exposing Commands as mcp.tool with @monx_tool

Import monx_tool from monxcli.mcp_bridge and use it to define your CLI commands. This decorator automatically registers your functions with both the MonxCLI command parser and the fastmcp server as an mcp.tool. The function's docstring and type hints are used to generate the tool's description and schema for AI systems.

For example, the mc_example/math_commands.py file defines math operations:

from monxcli.mcp_bridge import monx_tool


@monx_tool(desc="Add two numbers together.")
@staticmethod
def add(x: int, y: int):
    """Adds two numbers."""
    print(f"The result of {x} + {y} is {x + y}")

@monx_tool(desc="subtract two numbers.")
@staticmethod
def subtract(x: int, y: int):
    """Subtracts two numbers."""
    print(f"The result of {x} - {y} is {x - y}")

@monx_tool(desc="Multiply two numbers.")
@staticmethod
def multiply(a: int, b: int):
    return a * b

@monx_tool(desc="Divide two numbers.")
@staticmethod
def divide(a: int, b: int):
    """Divides two numbers."""
    if b == 0:
        raise ValueError("Cannot divide by zero.")
    return a / b

Exposing Prompts as mcp.prompt with @monx_prompt

The @monx_prompt decorator is used to define reusable prompt templates for Large Language Models (LLMs). These prompts also become callable MonxCLI commands.

For example, the monxcli/prompts.py file demonstrates:

from monxcli.mcp_bridge import monx_prompt

@monx_prompt(desc="Generates a prompt to summarize a given document.")
def summarize_document(document_text: str, length: str = "short"):
    """
    Generates a prompt to summarize a given document.
    The length can be 'short', 'medium', or 'long'.
    """
    if length == "short":
        return f"Please provide a concise summary of the following document:\n\n{document_text}"
    elif length == "medium":
        return f"Summarize the key points of the following document:\n\n{document_text}"
    else:
        return f"Provide a detailed summary of the following document, including all important aspects:\n\n{document_text}"

@monx_prompt(desc="Generates a prompt to translate text to a target language.")
def translate_text(text: str, target_language: str):
    """
    Generates a prompt to translate text to a target language.
    """
    return f"Translate the following text to {target_language}:\n\n{text}"

Exposing Data as mcp.resource with @monx_resource

The @monx_resource decorator exposes data as resources that AI assistants can access, and also registers them as MonxCLI commands.

For example, the monxcli/resources.py file demonstrates:

from monxcli.mcp_bridge import monx_resource

@monx_resource(desc="Provides a list of languages supported for translation.")
def available_languages():
    """
    Provides a list of languages supported for translation.
    """
    return ["English", "Spanish", "French", "German", "Italian", "Portuguese"]

@monx_resource(desc="Retrieves user-specific preferences.")
def get_user_preferences(user_id: str):
    """
    Retrieves user-specific preferences.
    """
    # In a real application, this would fetch data from a database or API
    preferences = {
        "user123": {"theme": "dark", "notifications": True},
        "user456": {"theme": "light", "notifications": False},
    }
    return preferences.get(user_id, {"theme": "system", "notifications": True})

To activate the CLI, your main function should just import the modules where the commands are defined. Monxcli will take of the rest.

from mc import math_commands  # just import your module/script here

from monxcli.commands import commands  # Shared LazyCommandParser


if __name__ == "__main__":
    # Execute commands only if the script is run as the main module
    commands()

running the main script example:

> python3 main.py mc math_commands add --x 3 --y 3

mc is the folder or module and math_commands is the submodule, 'add' is the function you want to call then --x and --y are the arguments passed to your functions.

result:

$ python3 main.py mc math_commands add --x 3 --y 3
The result of 3 + 3 is 6

Support

contact author https://gitlab.com/mongkoy/

Project status

on-going

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

monxcli-1.0.2.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

monxcli-1.0.2-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file monxcli-1.0.2.tar.gz.

File metadata

  • Download URL: monxcli-1.0.2.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for monxcli-1.0.2.tar.gz
Algorithm Hash digest
SHA256 40567a327e0bce266a15d490bc437aace9d1f0348c78bf665e2b8ae7a1cb02b1
MD5 87cb23919836a38d8749eb3e5bfdd255
BLAKE2b-256 6b8c39ff7fddf16307da402ab833371474eefb06fbabe68a06b5ddd7d3cf551d

See more details on using hashes here.

File details

Details for the file monxcli-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: monxcli-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for monxcli-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2308b069b736f9503f9e53da85909c4fb975861302dd7ccea7c4d467a3c63a45
MD5 bc3786405a5dabf5593dcc42a96ee246
BLAKE2b-256 d4bab61e47ad4d23472d9e190bd2ff4f833e3fc7e8ad4128debded7061cf05fe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page