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.13.tar.gz (164.7 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.13-py3-none-any.whl (173.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mtpx-0.1.13.tar.gz
  • Upload date:
  • Size: 164.7 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.13.tar.gz
Algorithm Hash digest
SHA256 db8a0ba89fa22e5e4ccf3926a17db1c9cff79654f05e0b06eac90fa0c9802f41
MD5 f735ae732d38c2b4c04aa684e04ab257
BLAKE2b-256 e2509aadd3ccdd9fadc07819f246b4c2596598ff6021e5442631cc763cee38bc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mtpx-0.1.13-py3-none-any.whl
  • Upload date:
  • Size: 173.3 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.13-py3-none-any.whl
Algorithm Hash digest
SHA256 31f4b42eff06b1446027ed1a815643d3291f32be0b2853c61d1bdbb48e309c67
MD5 186f6c917b1fc9b8a5f4c36629d30f6d
BLAKE2b-256 dc649aeecf3fc15461f4d44970f0494e8036071a65795211e238b0121960dc8f

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