Skip to main content

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:

  1. Path specified when creating the client
  2. ~/.config/mcp-client/config.json
  3. ~/.mcp-client.json
  4. ./mcp-client.json
  5. ./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

Metadata

Release files for mcp-python-client 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-python-client 0.1.9
File Size Uploaded
mcp_python_client-0.1.9.tar.gz 112.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mcp-python-client 0.1.9
File Interpreter ABI Platform
mcp_python_client-0.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 126.1 kB

Release files / mcp_python_client-0.1.9.tar.gz

Download URL mcp_python_client-0.1.9.tar.gz
Size 112.9 kB
Tags Source
SHA-256 checksum
How to use checksums
04f6ab6cdb5a8aaa71167dbd90b5e926d2d4b8504be0e67c57a51d32289c71ff
BLAKE2b-256 checksum
How to use checksums
7e8b87348b327e7b953ea52f0ffc9e588de1d57c724d8365695e3b426b4a5092
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.8

Release files / mcp_python_client-0.1.9-py3-none-any.whl

Download URL mcp_python_client-0.1.9-py3-none-any.whl
Size 13.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
008cb9799f5c0d28d252fcb3efaaee63239a4c782fa2373f796277992d3ea507
BLAKE2b-256 checksum
How to use checksums
1f806b3860130ef81d805f344d061d3d87f69a017b035d67703081dcba07a82b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.8

Release history Release notifications | RSS feed

This release

0.1.9 This release

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page