Skip to main content

MTPX

PyPI version Python 3.11+ License: MIT

MTPX is a Python SDK and CLI for building agents that can use tools without turning your application into a pile of prompt glue.

It gives you a small runtime for model-tool-model loops, provider adapters for popular LLM APIs, local toolkits for files and code work, session storage, streaming events, and MCP-compatible transports when you need interoperability.

Why MTPX

  • Build agents with explicit tool contracts instead of hidden ad hoc callbacks.
  • Run dependency-aware batches of tool calls, including references between calls.
  • Swap providers without rewriting your agent loop.
  • Stream text, reasoning, tool events, and usage metadata from one runtime.
  • Persist sessions in JSON, Postgres, or MySQL.
  • Expose the same tools through SDK code, a CLI/TUI, Streamlit Agent OS, or MCP JSON-RPC.

MTPX is still alpha, but the shape is practical: install it, register tools, choose a provider, and start building.

Install

pip install mtpx

Common extras:

pip install "mtpx[groq,dotenv]"
pip install "mtpx[openai,anthropic,dotenv]"
pip install "mtpx[ollama,lmstudio]"
pip install "mtpx[toolkits-web]"
pip install "mtpx[stores-db]"
pip install "mtpx[all]"

From source:

git clone https://github.com/GodBoii/Model-Tool-protocol-.git
cd Model-Tool-protocol-
python -m venv .venv
.venv\Scripts\activate
pip install -e ".[dotenv,groq]"

MTPX does not load .env automatically. Install python-dotenv and call Agent.load_dotenv_if_available(), or export provider keys in your shell.

SDK Quickstart

from mtp import Agent
from mtp.providers import Groq
from mtp.toolkits import CalculatorToolkit, FileToolkit

Agent.load_dotenv_if_available()

tools = Agent.ToolRegistry()
tools.register_toolkit_loader("calculator", CalculatorToolkit())
tools.register_toolkit_loader("file", FileToolkit(base_dir="."))

agent = Agent.MTPAgent(
    provider=Groq(model="llama-3.3-70b-versatile"),
    tools=tools,
    instructions="Use tools when they improve correctness. Keep answers concise.",
    strict_dependency_mode=True,
)

print(agent.run("What is 25 * 4 + 10? Then list the project files.", max_rounds=4))

Streaming:

agent.print_response(
    "Inspect this project and summarize the CLI entry points.",
    max_rounds=6,
    stream=True,
    stream_events=True,
)

Persistent sessions:

from mtp import Agent, JsonSessionStore
from mtp.providers import OpenAI

store = JsonSessionStore(db_path="tmp/mtp_json_db")
agent = Agent.MTPAgent(provider=OpenAI(model="gpt-4o"), tools=tools, session_store=store)

agent.run("Remember: project codename is Atlas.", session_id="chat-1", user_id="u1")
agent.run("What is the project codename?", session_id="chat-1", user_id="u1")

User-owned sessions must be read with the same user_id; this prevents accidental cross-user session reads.

CLI Quickstart

mtp --help
mtp providers list
mtp doctor
mtp new my-agent --template minimal
mtp run my-agent

Interactive terminal agent:

pip install "mtpx[groq,dotenv]"
mtp tui

Streamlit Agent OS:

pip install "mtpx[dotenv,ui-streamlit,groq,openai,openrouter]"
mtp agent-os

Agent OS starts with safer defaults: calculator and file tools are enabled first, while shell/Python/web tools are opt-in from the sidebar.

Providers

Supported adapters include:

  • OpenAI
  • Groq
  • Anthropic
  • Gemini
  • OpenRouter
  • Mistral
  • Cohere
  • Cerebras
  • DeepSeek
  • SambaNova
  • Together AI
  • Fireworks AI
  • Xiaomi MiMo
  • Ollama
  • LM Studio
  • Mock planner for deterministic tests
  • Hugging Face Inference Providers
  • DeepInfra
  • Alibaba Cloud Model Studio / DashScope
  • OpenAI Responses as an opt-in API path

Xiaomi MiMo uses MIMO_API_KEY. You can override its endpoint with MIMO_BASE_URL, and live tests require both MIMO_API_KEY and RUN_LIVE_XIAOMI=1.

Toolkits

Built-in toolkit loaders:

  • CalculatorToolkit: arithmetic helpers.
  • FileToolkit: scoped file listing, reading, writing, and search.
  • PythonToolkit: isolated subprocess execution for code snippets/files.
  • ShellToolkit: bare-command allowlist execution in a scoped directory.
  • WebsiteToolkit: public HTTP/HTTPS page text extraction with private-network blocking by default.
  • WikipediaToolkit, NewspaperToolkit, Newspaper4kToolkit, Crawl4aiToolkit: optional web research helpers.

Local code execution tools are powerful. Keep their base directory narrow, use policy controls, and do not expose them to untrusted users without an approval layer.

MCP And Transports

MTPX includes:

  • line-delimited stdio envelopes
  • HTTP envelope transport
  • optional WebSocket transport
  • MCP-compatible JSON-RPC server
  • MCP HTTP and WebSocket transports with progress replay

MCP auth is explicit: require_auth=True must be paired with an auth_token, auth_validator, or auth_provider.

Testing

Fast local checks:

python -m pytest -q -m "not integration and not live"
python -m compileall -q src tests

Integration checks:

python -m pytest -q -m "integration and not live"

Live provider tests are opt-in. For Xiaomi:

set RUN_LIVE_XIAOMI=1
set MIMO_API_KEY=...
python -m pytest -q tests/test_e2e_xiaomi.py

Docs

Repository Map

  • src/mtp/agent.py: agent loop, streaming, sessions, orchestration modes.
  • src/mtp/runtime.py: tool registry, lazy toolkit loading, policy checks, execution plans.
  • src/mtp/protocol.py: protocol dataclasses.
  • src/mtp/schema.py: envelope and argument validation.
  • src/mtp/providers/: LLM provider adapters.
  • src/mtp/toolkits/: local and web toolkit loaders.
  • src/mtp/cli/: CLI, TUI, scaffolding, doctor, Agent OS launcher.
  • src/mtp/mcp.py: MCP-compatible JSON-RPC adapter.
  • src/mtp/mcp_transport.py: MCP HTTP/WebSocket transports.
  • docs/: guides and reference material.
  • examples/: runnable provider and toolkit examples.

License

MIT License. See LICENSE.

Metadata

Release files for mtpx 0.1.39

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

Source distribution (sdist)

Source distribution for mtpx 0.1.39
File Size Uploaded Provenance Actions
mtpx-0.1.39.tar.gz 336.2 kB Without provenance Details for mtpx-0.1.39.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mtpx 0.1.39
File Interpreter ABI Platform Actions
mtpx-0.1.39-py3-none-any.whl Python 3 none any Details for mtpx-0.1.39-py3-none-any.whl

Total release size: 655.3 kB

Release files / mtpx-0.1.39.tar.gz

Download URL mtpx-0.1.39.tar.gz
Size 336.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b4cc3525a8e96bf95975ab63b508f4122564b90c849f9f0046284126acf890ef
BLAKE2b-256 checksum
How to use checksums
b22a0a4ff8b0a76c519cf63562708a661534249b9bb200324b603772b6c6d10f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / mtpx-0.1.39-py3-none-any.whl

Download URL mtpx-0.1.39-py3-none-any.whl
Size 319.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f07e6c68f1f88fa78300b1b8959dc6b32382263ada76aa193ece177cf53f6d28
BLAKE2b-256 checksum
How to use checksums
4b9914cc9fb7b1da81b0412b4685f615c2c8cff033284fc1102e767bfcd42d84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Security for mtpx 0.1.39

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.39 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