Python client for interacting with MCP servers and LLMs
Project description
MCP Python Client
A reusable Python client for interacting with MCP (Machine Conversation Protocol) servers and LLMs.
Features
- Connect to and interact with multiple MCP servers
- Call tools provided by MCP servers
- Process user queries using various LLM models via LiteLLM
- Support for synchronous and asynchronous operations
- Streaming response support
Installation
pip install mcp-python-client
Quick Start
import asyncio
from mcp_python_client import MCPClient
async def main():
# Create a client with your preferred LLM settings
client = MCPClient(
model="anthropic/claude-3-sonnet-20240229",
api_key="your_api_key_here" # Or set via env var
)
# Connect to MCP servers defined in your config
await client.connect_to_all_servers()
# Process a query
query = "What is the current weather in New York?"
# Stream response
async for chunk in client.aprocess_query(query):
print(chunk, end="", flush=True)
# Clean up
await client.cleanup()
# Run the example
asyncio.run(main())
Configuration
The client looks for a configuration file in the following locations:
- Path specified when creating the client
~/.config/mcp-client/config.json~/.mcp-client.json./mcp-client.json./config.json
Example configuration file:
{
"mcpServers": {
"shell-server": {
"command": "mcp-shell-server",
"args": ["--use_cache"],
"env": {
"SHELL_SERVER_CACHE_DIR": "/tmp/shell-server-cache"
}
},
"python-server": {
"command": "mcp-python-server",
"args": []
}
}
}
Advanced Usage
See the documentation for more advanced usage examples and API details.
Publishing
uv build
uv publish
License
MIT
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 mcp_python_client-0.1.4.tar.gz.
File metadata
- Download URL: mcp_python_client-0.1.4.tar.gz
- Upload date:
- Size: 105.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4407a5d06d2391e4606a5e698da42bf55aa20168d48c3b3efa790ea3ee0dd992
|
|
| MD5 |
3b69983b93c271f7e5b4ca289e8b2bd8
|
|
| BLAKE2b-256 |
cfd610e4735d3c38cc054ea0232c18c5caa7b0e55cc14fda0e7c0622acc79aeb
|
File details
Details for the file mcp_python_client-0.1.4-py3-none-any.whl.
File metadata
- Download URL: mcp_python_client-0.1.4-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04ddfc07ff8648a869e4d51890864e2c6089859cf686fe995f4b26f6573486f2
|
|
| MD5 |
c92cb4e5a15f6f672eb1682087744bf4
|
|
| BLAKE2b-256 |
e2df61d84a2a1fd5c514fd627cfb3e58a8529af75518c3da6848c1a9bf476e1b
|