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/mcp_stdio_server.py

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: mtpx-0.1.7.tar.gz
  • Upload date:
  • Size: 133.3 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.7.tar.gz
Algorithm Hash digest
SHA256 43b3429628254034b1e40f256a7636f4b294f7c9b46f6874c7dec91bf9a23032
MD5 6dd3dc9cd07ef37a439a918c2a583c4a
BLAKE2b-256 5fc7fd650758739a1d32dc9df748b918cb7bfa9898ca3c869bed75f9e126b87c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mtpx-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 140.8 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 57313818a0c5f957699cd3cc4e11805a031163c4d3c04b42206893c5bbdce754
MD5 6e7fa4e6e847cf5f44995ccdd01f5693
BLAKE2b-256 9b49c138ceb4ee0b62e60e59703e7f40811a781f079b2a53edab25e1294f6517

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