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")

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: mtpx-0.1.5.tar.gz
  • Upload date:
  • Size: 115.6 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.5.tar.gz
Algorithm Hash digest
SHA256 952b45f944448a4e9d69b533e6f51a23f2a06d2c58865bb124cfe42be1c98a24
MD5 e5e23f78bc458a76662dfa3f67f30653
BLAKE2b-256 da02abf011bc02d1914b83c815f99d2bc785405ff0f7b4dddb53aa9c5a9b52a2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mtpx-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 123.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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6d22b169868a6d1ea40f770f69ce5548f7d566bc0eaa3bebef3c7025f34fe4d2
MD5 3865f25ced1c51572f5fa23e64a4fbbc
BLAKE2b-256 b294a1bae8e932eee51c646faa784591391911e5b392a51aed10cf8caf1874be

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