Skip to main content

MTPX: Model Tool Protocol and agent runtime for Python

Project description

MTPX

PyPI version Python 3.10+ 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

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.

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

mtpx-0.1.33.tar.gz (229.1 kB view details)

Uploaded Source

Built Distribution

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

mtpx-0.1.33-py3-none-any.whl (254.6 kB view details)

Uploaded Python 3

File details

Details for the file mtpx-0.1.33.tar.gz.

File metadata

  • Download URL: mtpx-0.1.33.tar.gz
  • Upload date:
  • Size: 229.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for mtpx-0.1.33.tar.gz
Algorithm Hash digest
SHA256 313a6a8d1cf075a5d99426e991ed74066d2fe6bb71b7fd1bde4667e6dbc3502f
MD5 f3a9df60e16233cc7ec989d33686e193
BLAKE2b-256 30e6a5d9cbca0802137cb4d9ddd85d6d7e8eb386b1ad4e88f5f0ab63f3108b35

See more details on using hashes here.

File details

Details for the file mtpx-0.1.33-py3-none-any.whl.

File metadata

  • Download URL: mtpx-0.1.33-py3-none-any.whl
  • Upload date:
  • Size: 254.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for mtpx-0.1.33-py3-none-any.whl
Algorithm Hash digest
SHA256 28d3898516298df02fd801cbc24a9e3f6f4d5c8c3084091e8e33d30e1868cb58
MD5 e5344f5e1be7f0b008ab71ba26daf444
BLAKE2b-256 234264048b53c1a48650635f54a9ec73c997a7feaa3bd9722940ed029f7f9e5a

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