Skip to main content

appport-sdk

CI Python

Define once, expose twice. Write a Python function, get an MCP server and a command-line tool from the same definition — no duplicated schemas, no drifting help text.

                    ┌──────────────────────────┐
  Python function → │  @tool  →  ToolDefinition │ → MCP server  (stdio, tools/list + tools/call)
  (one definition)  └──────────────────────────┘ → CLI         (one subcommand per tool, JSON out)

Both exits are generated from the same ToolDefinition: to_json_schema() feeds the MCP inputSchema, to_cli_args() feeds the Typer options. Every call — from either exit — returns the shared envelope, so an LLM and a shell script see identical results.

Quick start

python -m venv .venv
.\.venv\Scripts\python.exe -m pip install -e ".[test]"

Requires mcp>=2,<3 and typer>=0.12 on Python 3.11+. The MCP exit is built on the mcp 2.x low-level Server API (on_list_tools / on_call_tool); the older 1.x mcp.server.fastmcp API no longer exists in 2.x. appport-bridge already runs on mcp v2, so both repositories pin the same mcp>=2,<3 window and stay installable side by side.

Define a tool (examples/demo_tools.py has three):

from appport_sdk import Returns, ToolRegistry, tool

@tool(returns=Returns(type="str", description="The echoed text."))
def echo(text: str, loud: bool = False) -> str:
    """Echo text back.

    Args:
        text: Text to echo.
        loud: Upper-case the result.
    """
    return text.upper() if loud else text

TOOLS = ToolRegistry([echo])

Exit 1 — CLI

appport-sdk --tools examples.demo_tools:TOOLS echo --text "hi" --loud
{
  "ok": true,
  "data": "HI"
}

Each tool becomes a subcommand; parameters become --kebab-case options, bools become --flag/--no-flag pairs, and required params are enforced by Click. A call that reaches the tool prints the JSON envelope on stdout and exits 0 (or 1 when the tool itself fails). A Click-level usage or type error — a missing required option, an unparseable value — is reported by Click as usual and exits 2 without JSON. Without --tools the CLI reads APPPORT_TOOLS.

Exit 2 — MCP

appport-sdk-mcp --tools examples.demo_tools:TOOLS     # or: python -m appport_sdk.mcp_server

Add it to any MCP client (Claude Desktop / Cursor / …):

{
  "mcpServers": {
    "appport-demo": {
      "command": "appport-sdk-mcp",
      "args": ["--tools", "examples.demo_tools:TOOLS"]
    }
  }
}

tools/list advertises exactly the shared ToolDefinition schema (additionalProperties: false), and tools/call returns the envelope:

{"ok": true, "data": "HI"}

Both exits at once

python examples/demo_tools.py

This drives the CLI through real subprocesses and then starts the MCP server as a real stdio subprocess and calls it with the official mcp client — the single definition, exercised twice.

The shared ToolDefinition spec (v0.1)

{
  "name": "snake_case_unique",
  "description": "what the LLM reads",
  "params": [{"name": str, "type": "str|int|float|bool",
              "description": str, "required": bool, "default": any}],
  "returns": {"type": "str|json", "description": str},
  "examples": [{"args": {...}, "result_hint": str}],   # optional
}

Result envelope — success {"ok": true, "data": ...}, failure {"ok": false, "error": {"code": ..., "message": ...}}. Every call that reaches the SDK — from MCP or from the CLI — returns that envelope, and the SDK converts missing/invalid arguments and any exception raised by your function into the failure form; it never lets a raw traceback escape.

One caveat on the CLI: Click parses arguments before the SDK sees them, so an unknown option or an unparseable value is rejected by Click itself with a usage message and exit code 2 — no JSON for those. Failures after parsing (validation against the definition, your function raising, a ToolError) are always JSON with exit 1. MCP calls always go through the SDK, so they get the envelope in every case.

Error codes: MISSING_PARAMETER, INVALID_ARGUMENT, UNKNOWN_PARAMETER (CLI/local calls), UNKNOWN_TOOL (an MCP tools/call for a name that is not registered), TOOL_ERROR (your ToolError), INTERNAL_ERROR.

API notes

Piece Where Notes
ToolDefinition, Param, Returns, Example appport_sdk.definition immutable; to_json_schema(), to_cli_args(), to_dict(), from_dict()
@tool(...) appport_sdk.decorators returns the original function with .definition attached; ToolRegistry collects them
invoke() / invoke_async() appport_sdk.runner validation, coercion, envelope wrapping
build_cli() / serve_cli() appport_sdk.cli Typer app; build_cli returns an app you can test
build_mcp_server() / serve_mcp() appport_sdk.mcp_server mcp v2 low-level Server over stdio
  • Type mapping: str → string, int → integer, float → number, bool → boolean. A parameter with a default is required: false and its default lands in the JSON Schema.
  • description comes from @tool(description=...), else the first paragraph of the docstring, else the function name.
  • Optional[str]-style annotations unwrap to their base type.
  • mcp>=2,<3 (v2 low-level Server API); typer>=0.12. Python 3.11+.

Relation to appport-bridge

AppPort Bridge gives an existing Windows desktop app an MCP port; this SDK is the other half — it produces ToolDefinitions in the exact same v0.1 shape, so tools built here and definitions produced by the bridge are interchangeable.

Development

.\.venv\Scripts\python.exe -m pytest -q

License

MIT

Business model: open core with enterprise features.

Metadata

Release files for appport-sdk 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for appport-sdk 0.1.0
File Size Uploaded Provenance Actions
appport_sdk-0.1.0.tar.gz 31.4 kB Without provenance Details for appport_sdk-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for appport-sdk 0.1.0
File Interpreter ABI Platform Actions
appport_sdk-0.1.0-py3-none-any.whl Python 3 none any Details for appport_sdk-0.1.0-py3-none-any.whl

Total release size: 53.2 kB

Release files / appport_sdk-0.1.0.tar.gz

Download URL appport_sdk-0.1.0.tar.gz
Size 31.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ca1101d3a5d61053ed77f77504589fc16f5f8c3a4bd96ac2a90877d327919c85
BLAKE2b-256 checksum
How to use checksums
6fbfa55ba6280e975ea127d03ff9ec74de53b9c719550a962bdc23095b758752
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.14

Release files / appport_sdk-0.1.0-py3-none-any.whl

Download URL appport_sdk-0.1.0-py3-none-any.whl
Size 21.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
12c7d6fd78abbb33585aee1f306507ed2b7c15fa7a7be2dad2483659e9c68e96
BLAKE2b-256 checksum
How to use checksums
f23e9e114d6985de7ca33bc6aac7551e923da1627a62521b22098586781d25fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.14

Security for appport-sdk 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page