MCPClient Python Library Overview The MCPClient is a Python client for interacting with an MCP (Message Control Protocol) server via Server-Sent Events (SSE) and JSON-RPC. It provides functionality to connect to an MCP server, initialize a session, list available tools, and execute tools interactively or programmatically. Features
Connects to an MCP server using SSE Supports JSON-RPC 2.0 for sending requests and notifications Automatically discovers and parses available tools and their schemas Provides an interactive command-line interface for running tools Validates required parameters before tool execution Handles both required and optional parameters with type checking
Installation No external dependencies are required beyond the Python standard library (json, urllib.request, urllib.parse). To use the library, save the provided Python code as py_mcp_client.py and import it into your project. Usage Basic Example from py_mcp_client import MCPClient
Initialize client with SSE URL
client = MCPClient("https://example.com/sse")
try: # Connect to the server client.connect()
# Initialize session and get available tools
init_response, tools = client.initialize()
print(f"Connected to server: {init_response['result']['serverInfo']['name']}")
print(f"Available tools: {list(tools.keys())}")
# Run a tool programmatically
result = client.run_tool("example_tool", {"param1": "value1"})
print(result)
# Start interactive mode
client.interactive_run()
except Exception as e: print(f"Error: {e}")
Command-Line Usage Run the script directly and provide the SSE URL as a command-line argument or input it when prompted: python py_mcp_client.py https://example.com/sse
The script will:
Connect to the specified SSE URL Initialize the session Display server information and available tools Enter an interactive mode where you can select and run tools
Interactive Mode In interactive mode, the client:
Lists all available tools with their descriptions Allows selection of a tool by number Prompts for required and optional parameters Executes the selected tool and displays the result Continues until you choose to exit (option 0)
Methods
connect(): Establishes a connection to the SSE endpoint and retrieves the message URL. send_request(method, params): Sends a JSON-RPC request with an ID and returns the request ID. send_notification(method, params): Sends a JSON-RPC notification without an ID. initialize(): Initializes the MCP session and retrieves available tools. run_tool(tool_name, arguments): Executes a specified tool with provided arguments. interactive_run(): Starts the interactive command-line interface.
Error Handling
The client validates required parameters before tool execution. It handles various response formats (JSON and plain strings) for robustness. Errors during connection, initialization, or tool execution are caught and displayed.
Limitations
Requires a stable internet connection for SSE communication. Assumes the server follows the MCP protocol with JSON-RPC 2.0. Limited to the capabilities provided by the server's toolset.
Contributing Feel free to fork the repository, make improvements, and submit pull requests. For issues or feature requests, please open an issue on the repository. License This project is licensed under the MIT License.
Metadata
Release files for py-mcp-client 0.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| py_mcp_client-0.0.8.tar.gz | 7.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| py_mcp_client-0.0.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.8 kB
Release files / py_mcp_client-0.0.8.tar.gz
| Download URL | py_mcp_client-0.0.8.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ea237646b75c43e86f8d677d7be07e9e549f9777ed970ad96366944d82bade2e
|
|
BLAKE2b-256 checksum How to use checksums |
0f26e881d1d9d72b9d7f4bb266a49b1c458695cc9806193a1ef5cc43a9eddbfa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / py_mcp_client-0.0.8-py3-none-any.whl
| Download URL | py_mcp_client-0.0.8-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7fb45b3c3bfa8f6b384e550ae18b2dcc00c4d02b087b6d23c849d9a05f43fa66
|
|
BLAKE2b-256 checksum How to use checksums |
fad2677ac10f77794f8e35a2f1191373d2743ef87b0799733d8d8ba0711a6a85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Security for py-mcp-client 0.0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.