mcpx-py is a Python library that enables interaction with various Large Language Models (LLMs) using mcp.run tools, supporting models from PydanticAI, OpenAI, Ollama, and Gemini. mcpx-py is a Python library
A Python library for interacting with LLMs using mcp.run tools. It supports various AI providers through PydanticAI.
mcpx-py
supports all models supported by PydanticAI
uv
npm
ollama
(optional)An mcp.run session ID is required, obtainable via npx --yes -p @dylibso/mcpx gen-session
. This can be written to a configuration file or stored in the MPC_RUN_SESSION_ID
environment variable.
Install using uv add mcpx-py
or pip install mcpx-py
.
The library offers a Chat
class for interacting with LLMs. It supports models like Claude, OpenAI, Ollama, and Gemini. You can send messages and receive responses, with options for structured output using Pydantic BaseModel
. Examples are available in the examples/ directory.
Install via uv tool install mcpx-py
or from git.
The mcpx-client
tool allows chatting with LLMs (mcpx-client chat
), listing available tools (mcpx-client list
), and calling specific tools (mcpx-client tool eval-js '{"code": "2+2"}'
).
Configuration steps are provided for Claude, OpenAI, Gemini, Ollama, and Llamafile, including API key setup and Ollama model pulling.
dylibso/mcpx-py
December 4, 2024
March 28, 2025
Python