An mcp.run client for Python
Project description
mcpx-py
A Python library for interacting with LLMs using mcp.run tools
Features
AI Provider Support
mcpx-py supports all models supported by PydanticAI
Dependencies
uvnpmollama(optional)
mcp.run Setup
You will need to get an mcp.run session ID by running:
npx --yes -p @dylibso/mcpx gen-session --write
This will generate a new session and write the session ID to a configuration file that can be used
by mcpx-py.
If you need to store the session ID in an environment variable you can run gen-session
without the --write flag:
npx --yes -p @dylibso/mcpx gen-session
which should output something like:
Login successful!
Session: kabA7w6qH58H7kKOQ5su4v3bX_CeFn4k.Y4l/s/9dQwkjv9r8t/xZFjsn2fkLzf+tkve89P1vKhQ
Then set the MPC_RUN_SESSION_ID environment variable:
$ export MCP_RUN_SESSION_ID=kabA7w6qH58H7kKOQ5su4v3bX_CeFn4k.Y4l/s/9dQwkjv9r8t/xZFjsn2fkLzf+tkve89P1vKhQ
Python Usage
Installation
Using uv:
uv add mcpx-py
Or pip:
pip install mcpx-py
Example code
from mcpx_py import Chat
llm = Chat("claude-3-5-sonnet-latest")
# Or OpenAI
# llm = Chat("gpt-4o")
# Or Ollama
# llm = Chat("ollama:qwen2.5")
# Or Gemini
# llm = Chat("gemini-2.0-flash")
response = llm.send_message_sync(
"summarize the contents of example.com"
)
print(response.data)
It's also possible to get structured output by setting result_type
from mcpx_py import Chat, BaseModel, Field
from typing import List
class Summary(BaseModel):
"""
A summary of some longer text
"""
source: str = Field("The source of the original_text")
original_text: str = Field("The original text to be summarized")
items: List[str] = Field("A list of summary points")
llm = Chat("claude-3-5-sonnet-latest", result_type=Summary)
response = llm.send_message_sync(
"summarize the contents of example.com"
)
print(response.data)
More examples can be found in the examples/ directory
Command Line Usage
Installation
uv tool install mcpx-py
From git:
uv tool install git+https://github.com/dylibso/mcpx-py
Or from the root of the repo:
uv tool install .
uvx
mcpx-client can also be executed without being installed using uvx:
uvx --from mcpx-py mcpx-client
Or from git:
uvx --from git+https://github.com/dylibso/mcpx-py mcpx-client
Running
Get usage/help
mcpx-client --help
Chat with an LLM
mcpx-client chat
List tools
mcpx-client list
Call a tool
mcpx-client tool eval-js '{"code": "2+2"}'
LLM Configuration
Provider Setup
Claude
- Sign up for an Anthropic API account at https://console.anthropic.com
- Get your API key from the console
- Set the environment variable:
ANTHROPIC_API_KEY=your_key_here
OpenAI
- Create an OpenAI account at https://platform.openai.com
- Generate an API key in your account settings
- Set the environment variable:
OPENAI_API_KEY=your_key_here
Gemini
- Create an Gemini account at https://aistudio.google.com
- Generate an API key in your account settings
- Set the environment variable:
GEMINI_API_KEY=your_key_here
Ollama
- Install Ollama from https://ollama.ai
- Pull your desired model:
ollama pull llama3.2 - No API key needed - runs locally
Llamafile
- Download a Llamafile model from https://github.com/Mozilla-Ocho/llamafile/releases
- Make the file executable:
chmod +x your-model.llamafile - Run in JSON API mode:
./your-model.llamafile --json-api --host 127.0.0.1 --port 8080 - Use with the OpenAI provider pointing to
http://localhost:8080
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcpx_py-0.5.3.tar.gz.
File metadata
- Download URL: mcpx_py-0.5.3.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a022d6cd6e06c6cd226e6bd41e55a533818ecb2b693d924e36adeacf8d15687
|
|
| MD5 |
3bbeb16c62890ecf17179193f19b8c23
|
|
| BLAKE2b-256 |
76e91b506109502caa24803d4db780a8710be8bd28b28d77d72c1255560577cf
|
File details
Details for the file mcpx_py-0.5.3-py3-none-any.whl.
File metadata
- Download URL: mcpx_py-0.5.3-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f31d732b65d2afec8445d135d8358c0b538737a5ed3cbf8db7aa5380af93d232
|
|
| MD5 |
39a85d23fd773a3083443b2321e03dda
|
|
| BLAKE2b-256 |
d47b4a884fc74d20f335da485d2d56fa410bad070f758c2a0744fcd4cae012d9
|