Skip to main content

Add MTP --describe support to any Click CLI

Project description

mtp-sdk

Add MTP --describe support to any Click CLI. One function call, zero boilerplate.

Install

pip install mtp-sdk click

Quick Start

import click
from mtp_sdk import with_describe, DescribeOptions, CommandAnnotation, Example, IODescriptor

@click.group()
def cli():
    """Convert and validate files"""

@cli.command()
@click.argument("input")
@click.option("--format", default="json", help="Output format")
@click.option("--pretty", is_flag=True, help="Pretty-print output")
def convert(input, format, pretty):
    """Convert a file"""

with_describe(cli, DescribeOptions(
    version="1.0.0",
    commands={
        "convert": CommandAnnotation(
            arg_descriptions={"input": "Input file path"},
            stdin=IODescriptor(content_type="text/plain", description="Raw input"),
            stdout=IODescriptor(content_type="application/json"),
            examples=[
                Example(description="Convert CSV", command="filetool convert data.csv --format json"),
            ],
        ),
    },
))

if __name__ == "__main__":
    cli()
$ filetool --describe          # MTP JSON schema
$ filetool convert data.csv    # normal operation

API

with_describe(cli, options?)

Adds --describe to an existing Click command or group. When invoked, outputs MTP-compliant JSON and exits.

  • cli - a Click BaseCommand instance (your root command or group)
  • options.version - version string for the tool
  • options.commands - per-command annotations keyed by command name (stdin, stdout, examples, arg_types, arg_descriptions)
  • options.auth - authentication config to include in the schema
  • Returns the cli for chaining

describe(cli, options?)

Pure function. Returns the ToolSchema object without side effects. Useful for testing or programmatic access.

How It Works

The SDK introspects Click's own data structures (params, type objects, subcommands) so you never duplicate information. Supplemental metadata (stdin/stdout/examples) that Click doesn't model is provided via the options map.

Type Inference

Click signal MTP type
Option.is_flag "boolean"
click.Choice(...) "enum" + values
Option.multiple / nargs=-1 "array"
click.INT / IntRange "integer"
click.FLOAT / FloatRange "number"
click.BOOL "boolean"
click.Path(...) "path"
Option.count "integer"
explicit arg_types override whatever you say
everything else "string"

Command Naming

  • Groups with subcommands: each leaf command gets a space-separated path (e.g., "auth login")
  • Commands with no subcommands: single command named "_root"
  • Hidden commands and options are excluded

Argument Descriptions

Click arguments don't support help text natively. Use arg_descriptions in your annotation:

CommandAnnotation(
    arg_descriptions={"input_file": "Input file path"},
)

Filtered Options

These are automatically excluded from schema output: --help, --version, --describe, and any hidden options.

Single-Command Tools

Tools with no subcommands work the same way:

import click
from mtp_sdk import with_describe, DescribeOptions

@click.command()
@click.argument("name")
@click.option("--loud", is_flag=True, help="Shout the greeting")
def greet(name, loud):
    """Greet someone"""
    msg = f"Hello, {name}!"
    click.echo(msg.upper() if loud else msg)

with_describe(greet, DescribeOptions(version="1.0.0"))

if __name__ == "__main__":
    greet()

This produces a schema with a single _root command.

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

mtp_sdk-0.1.1.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

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

mtp_sdk-0.1.1-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file mtp_sdk-0.1.1.tar.gz.

File metadata

  • Download URL: mtp_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mtp_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5f5c7e107c4dc5c9d90ef47b847c437a8d97544d9a5148dd1200edec975b5c9f
MD5 46d192b7bfebb0d77f36f29a03ad97eb
BLAKE2b-256 c8ea8061f2985ee32235d7b461575f2a79d88e7dee2f8ba60889a093d0d9d478

See more details on using hashes here.

File details

Details for the file mtp_sdk-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mtp_sdk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mtp_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 de03eeac59cfb88104d0b3c039573174ac7d3fbea2fa5727f8a9ac412354cea3
MD5 8da04f026f67c1c0e82e9bd1642da9e0
BLAKE2b-256 7251ab08ba92220afe111e6fda591c7220af268b56ae189c302c4f73bdc0c0b7

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