QV MCP Client
A Python client library for the Model Context Protocol (MCP) that provides clean, async connectivity to MCP servers.
What is MCP?
The Model Context Protocol (MCP) is an open standard that enables AI assistants to securely connect to external data sources and tools. It provides a standardized way for AI models to interact with various systems including databases, file systems, APIs, and other services.
Features
- Async Support: Full async/await pattern for non-blocking operations
- Multiple Transports: Support for stdio and HTTP-based connections
- Connection Management: Built-in manager for handling multiple server connections
- Cross-Platform: Windows-specific command handling included
- Error Handling: Comprehensive exception hierarchy with detailed error information
- Type Safety: Complete type hints throughout the codebase
- Modular Design: Clean separation of concerns for easy maintenance
Installation
pip install mcp
pip install -e .
Quick Start
Basic Client Usage
import asyncio
from qv_mcp_client import MCPClient, MCPServerConfig, MCPTransportType
async def main():
config = MCPServerConfig(
name="filesystem",
transport=MCPTransportType.STDIO,
command="npx",
args=["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
)
client = MCPClient()
await client.connect(config)
# List available tools
tools = await client.list_tools()
print(f"Available tools: {[tool['name'] for tool in tools]}")
# Call a tool
result = await client.call_tool("read_file", {"path": "/tmp/test.txt"})
print(f"Result: {result}")
await client.disconnect()
asyncio.run(main())
Managing Multiple Connections
from qv_mcp_client import MCPManager
async def main():
manager = MCPManager()
# Add multiple servers
await manager.add_server(MCPServerConfig(
name="filesystem",
transport=MCPTransportType.STDIO,
command="npx",
args=["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
))
await manager.add_server(MCPServerConfig(
name="api-server",
transport=MCPTransportType.STREAMABLE_HTTP,
url="http://localhost:3000/mcp"
))
# Use specific client
fs_client = manager.get_client("filesystem")
if fs_client:
tools = await fs_client.list_tools()
print(f"Filesystem tools: {len(tools)}")
await manager.disconnect_all()
Transport Types
STDIO Transport
For local subprocess-based servers (Python, Node.js, etc.)
config = MCPServerConfig(
name="python-server",
transport=MCPTransportType.STDIO,
command="python",
args=["-m", "my_mcp_server"],
env={"DEBUG": "1"}
)
HTTP Transport
For remote or web-based MCP servers
config = MCPServerConfig(
name="web-server",
transport=MCPTransportType.STREAMABLE_HTTP,
url="https://api.example.com/mcp"
)
API Overview
MCPClient Methods
Connection:
connect(config)- Connect to MCP serverdisconnect()- Disconnect from server
Tools:
list_tools()- Get available toolscall_tool(name, arguments)- Execute a tool
Resources:
list_resources()- Get available resourcesread_resource(uri)- Read resource content
Prompts:
list_prompts()- Get available promptsget_prompt(name, arguments)- Retrieve formatted prompt
MCPManager Methods
add_server(config)- Add and connect to serverremove_server(name)- Remove server connectionget_client(name)- Get specific client instancelist_servers()- List connected serversdisconnect_all()- Close all connections
Error Handling
The library provides specific exception types for different error scenarios:
from qv_mcp_client.exceptions import MCPConnectionError, MCPToolError
try:
await client.connect(config)
result = await client.call_tool("example_tool", {})
except MCPConnectionError as e:
print(f"Connection failed: {e}")
except MCPToolError as e:
print(f"Tool execution failed: {e}")
Platform Support
- Windows: Automatic handling of
.cmdand.batfiles - Linux/macOS: Direct command execution
- Python 3.10+: Full compatibility
Project Structure
src/qv_mcp_client/
├── __init__.py # Package exports
├── client.py # Main MCPClient implementation
├── manager.py # Multi-connection manager
├── config.py # Configuration classes
├── utils.py # Platform utilities
└── exceptions.py # Custom exceptions
Examples
The examples/ directory contains working examples for different use cases:
- Basic client usage with filesystem server
- Multi-server management
- Error handling patterns
Requirements
- Python 3.10 or higher
mcppackage (Model Context Protocol SDK)- Platform-specific requirements for server execution
MCP Server Compatibility
This client works with any MCP-compliant server including:
- Official MCP servers (filesystem, database, etc.)
- Custom Python MCP servers
- Docker-based MCP services
- HTTP/REST MCP endpoints
Development Status
This is a personal project developed for specific use cases. The code is provided as-is and will be maintained and improved based on personal requirements. While the library is functional and well-tested in its intended environments, it may not cover all edge cases or use scenarios.
License
MIT License - see LICENSE file for details.
Related Links
Metadata
Release files for qv-mcp-client 0.1.0
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 | |
|---|---|---|---|---|
| qv_mcp_client-0.1.0.tar.gz | 9.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| qv_mcp_client-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.3 kB
Release files / qv_mcp_client-0.1.0.tar.gz
| Download URL | qv_mcp_client-0.1.0.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2a96e45cbfab7ba5e992469de6357b6f2e5b4bfa3401c4228e32e4ea25d0208f
|
|
BLAKE2b-256 checksum How to use checksums |
e032dccbd32c9e8ed092400356fb8cb8a18b81cad66a39f1555dd1d68e03a3c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.5
|
Release files / qv_mcp_client-0.1.0-py3-none-any.whl
| Download URL | qv_mcp_client-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
203ca00f15c736c8a2b9de19bec77d491f2929544c68f3dd5644223c41e12c04
|
|
BLAKE2b-256 checksum How to use checksums |
e6736b7b6fc74de3fa65d6de7806efc9ec6764379e50b55ffb908f3e6bc59f46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.5
|
Security for qv-mcp-client 0.1.0
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.