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.12.tar.gz (162.4 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.12-py3-none-any.whl (171.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mtpx-0.1.12.tar.gz
  • Upload date:
  • Size: 162.4 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.12.tar.gz
Algorithm Hash digest
SHA256 e7d2af9400b82a09d4bd1cc52c571886b2d6b1aeb5ca96065a8d5ec3dc45d92b
MD5 b6a53605c031df685e175490b85d3714
BLAKE2b-256 a260474ad8b367f560ac370e235d9866661f3deb7db9412f1d4cec117823028b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mtpx-0.1.12-py3-none-any.whl
  • Upload date:
  • Size: 171.0 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.12-py3-none-any.whl
Algorithm Hash digest
SHA256 35258e4fb6cf3c3a2dfd25c2f43fe753d4214bc5b9cae81733106f98cf57653a
MD5 416d3aa89fdd1dc32114751c94494b2e
BLAKE2b-256 92bd30668591f363e2920a9d2028c6eaa6cd4eb5b45a84072d3ca6bdf694cf36

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