Skip to main content

MTPX: Model Tool Protocol and agent runtime for Python

Project description

MTPX (Model Tool Protocol Extended)

PyPI version Python 3.10+ License: MIT

MTPX is a protocol-first Python library for agent tool orchestration, built to support:

  • Lazy tool loading by toolkit/category.
  • Dependency-aware batch tool execution.
  • Policy-aware execution based on tool risk.
  • Multi-round model-tool-model loops.
  • Provider adapters (now including Groq, Gemini, OpenAi, Anthropic, Openrouter, etc.).
  • Transport primitives (stdio + HTTP + optional WebSocket envelope transport).
  • Experimental MCP JSON-RPC adapter over the same runtime core.

Direction

This project has two explicit layers:

  • MTP protocol: protocol entities and execution semantics.
  • MTP Agent SDK: framework/runtime/providers/toolkits/transports built on top of MTP.

MCP support is an interoperability capability, not the product identity.

Canonical direction document:

Quickstart

Install

From PyPI (recommended)

pip install mtpx

Common optional installs:

# Groq + dotenv helper
pip install "mtpx[groq,dotenv]"

# OpenAI + Anthropic providers
pip install "mtpx[openai,anthropic,dotenv]"

# Web toolkits
pip install "mtpx[toolkits-web]"

# Database session stores
pip install "mtpx[stores-db]"

# Everything optional
pip install "mtpx[all]"

Verify installation:

python -c "import mtp; print(f'MTPX version {mtp.__version__} installed successfully!')"

From source (for development)

git clone https://github.com/yourusername/MTP.git  # Replace with your actual repo URL
cd MTP
python -m venv .venv
.venv\Scripts\activate  # On Windows
# source .venv/bin/activate  # On Linux/Mac
pip install -e .

Provider SDKs and dotenv (explicit alternative)

pip install "mtpx[groq,dotenv]"

Copy .env.example to .env and set your key:

GROQ_API_KEY=your_groq_api_key_here

Create an agent (local toolkits + Groq)

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

Agent.load_dotenv_if_available()

tools = Agent.ToolRegistry()
tools.register_toolkit_loader("calculator", CalculatorToolkit())
tools.register_toolkit_loader("file", FileToolkit(base_dir="."))
tools.register_toolkit_loader("python", PythonToolkit(base_dir="."))
tools.register_toolkit_loader("shell", ShellToolkit(base_dir="."))

provider = Groq(model="llama-3.3-70b-versatile")

agent = Agent.MTPAgent(
    provider=provider,
    tools=tools,
    instructions="Use tools when needed and return concise answers.",
    debug_mode=True,
    strict_dependency_mode=True,
)
response = agent.run("Calculate 25*4+10 and list files in current directory.", max_rounds=4)
print(response)

# Stream final response tokens:
agent.print_response("Give me a short summary.", max_rounds=4, stream=True)

# Stream structured runtime events (readable terminal logs by default):
agent.print_response("Give me a short summary.", max_rounds=4, stream=True, stream_events=True)
# Raw JSON lines:
agent.print_response("Give me a short summary.", max_rounds=4, stream=True, stream_events=True, event_format="json")

Autoresearch mode (persistent execution)

autoresearch=True enables persistent run behavior. The model is expected to end only when it calls agent.terminate(...), or when user/system limits stop the run.

agent = Agent.MTPAgent(
    provider=provider,
    tools=tools,
    autoresearch=True,
    research_instructions=(
        "Keep working until requirements are satisfied and verified. "
        "Call agent.terminate with reason+summary only when complete."
    ),
    debug_mode=True,
)

agent.print_response(
    "Compute the result and verify with tools. Terminate only after completion.",
    max_rounds=12,
    stream=True,
    stream_events=True,
)

Persist conversation sessions (JSON database)

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

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

agent.run("Remember this: 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")

PostgreSQL and MySQL session stores are also available:

from mtp import PostgresSessionStore, MySQLSessionStore

pg_store = PostgresSessionStore(db_url="postgresql://user:pass@localhost:5432/mtp")
my_store = MySQLSessionStore(
    host="localhost",
    user="root",
    password="secret",
    database="mtp",
    port=3306,
)

Run examples

python examples/quickstart.py
python examples/groq_agent.py
python examples/groq_agent_events.py
python examples/mcp_stdio_server.py
pip install -e ".[groq,dotenv,ui-streamlit]"
streamlit run examples/streamlit_groq_agent_chat.py
pip install -e ".[dotenv,ui-streamlit,groq,openai,openrouter]"
mtp agent-os

Docs map

Repository structure

  • src/mtp/protocol.py: Core protocol entities (ToolSpec, ToolCall, ExecutionPlan, etc.).
  • src/mtp/schema.py: Versioned envelope + execution plan validation.
  • src/mtp/policy.py: Risk policy (allow / ask / deny).
  • src/mtp/runtime.py: Tool registry, lazy loading, caching, batch execution.
  • src/mtp/agent.py: Agent loop around provider + runtime.
  • src/mtp/toolkits/: Local toolkits (calculator, file, python, shell).
  • src/mtp/transport/: Envelope transport over stdio and HTTP.
  • src/mtp/mcp.py: MCP-compatible JSON-RPC adapter around ToolRegistry.
  • src/mtp/providers/: Provider adapters (MockPlannerProvider + OpenAI/Groq/OpenRouter/Gemini/Anthropic/SambaNova/Cerebras/DeepSeek/Mistral/Cohere/TogetherAI/FireworksAI).
  • docs/: documentation and implementation guides.

Contributors

Created by Prajwal Ghadge with contributions from Himesh Mehta.

See CONTRIBUTORS.md for the full list of contributors.

License

MIT License - see LICENSE file for details.

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.11.tar.gz (160.8 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.11-py3-none-any.whl (169.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mtpx-0.1.11.tar.gz
  • Upload date:
  • Size: 160.8 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.11.tar.gz
Algorithm Hash digest
SHA256 3396b3ea222ebc47f638b82b491e92efff85e49aefae0587d21c1fbe308c08ba
MD5 3007d8f79cbf6c8445e7cf3d3b57a009
BLAKE2b-256 c42f50f3c1d67256ec05bd97de78f640b598e68599788990d65afef0a8f8ad13

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mtpx-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 169.5 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.11-py3-none-any.whl
Algorithm Hash digest
SHA256 d520407d95008600d3e045f2115d153b3a16578129bf33467cc73585be4273c5
MD5 94fc56aafb27ea77215612447bc5e3a1
BLAKE2b-256 8751906e120637dae546cc860022a4773ca011afd221d308b1a94571d47c9cd7

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