An open-source Python package for MCP (Model Context Protocol)
Project description
Open-MCP
An open-source Python package for Model Context Protocol (MCP) - enabling seamless integration between language models and external tools, data sources, and services.
🚀 Features
- 🔧 Tool Integration: Execute external tools and functions from language models
- 📊 Resource Access: Access and manage external data sources and files
- 💬 Prompt Management: Dynamic prompt templates with parameter substitution
- 🌐 Client & Server: Full MCP client and server implementations
- ⚡ Async Support: Built with modern async/await patterns
- 🔒 Type Safe: Full type hints and Pydantic validation
- 🧪 Well Tested: Comprehensive test suite with high coverage
- 📚 Documented: Complete API documentation and examples
📦 Installation
Via pip (PyPI)
pip install open-mcp
Via uv (Recommended)
uv add open-mcp
Via conda
conda install -c conda-forge open-mcp
Development Installation
git clone https://github.com/2796gaurav/open-mcp.git
cd open-mcp
uv sync --all-extras --dev
🏃 Quick Start
MCP Client
import asyncio
from open_mcp import MCPClient
async def main():
async with MCPClient("http://localhost:8000") as client:
# List available tools
tools = await client.list_tools()
print(f"Available tools: {[tool.name for tool in tools]}")
# Execute a tool
result = await client.call_tool("calculator", {
"operation": "add",
"a": 5,
"b": 3
})
print(f"Result: {result.content}")
# Access resources
resources = await client.list_resources()
content = await client.get_resource("file://data.json")
# Use prompts
prompt_content = await client.get_prompt("summarize", {
"text": "Long text to summarize...",
"max_words": 100
})
asyncio.run(main())
MCP Server
from open_mcp import MCPServer
from open_mcp.models import Tool, ToolResult
# Create server instance
server = MCPServer("My MCP Server")
# Register a tool
@server.tool("calculator", "Perform basic calculations")
async def calculator(operation: str, a: float, b: float) -> ToolResult:
operations = {
"add": a + b,
"subtract": a - b,
"multiply": a * b,
"divide": a / b if b != 0 else "Error: Division by zero"
}
result = operations.get(operation, "Unknown operation")
return ToolResult(content=result)
# Register a resource
@server.resource("file://config.json", "Application configuration")
async def get_config():
return {"setting1": "value1", "setting2": "value2"}
# Start server
if __name__ == "__main__":
import uvicorn
uvicorn.run(server.app, host="0.0.0.0", port=8000)
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
open_mcp_protocol-0.0.1.tar.gz
(14.3 kB
view details)
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 open_mcp_protocol-0.0.1.tar.gz.
File metadata
- Download URL: open_mcp_protocol-0.0.1.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6d3a8894298315571694a9c85aef18d7539e148fcabc5c725aa699446e96720
|
|
| MD5 |
59bf67ec7348ccb585ef71f3f5122394
|
|
| BLAKE2b-256 |
196e0bb3e10071ca4398cb4c8c1372dfb7a3cb04fe1b06273f44d9b9a8787d9b
|
File details
Details for the file open_mcp_protocol-0.0.1-py3-none-any.whl.
File metadata
- Download URL: open_mcp_protocol-0.0.1-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c06b4d11321f571f49bd6da9b78042d1cb583cae0e274541d16cca259579fd2
|
|
| MD5 |
97bd515a1839fccf835802ebfff197be
|
|
| BLAKE2b-256 |
0b232302621f9bb32cb08d1ff65574e9fd4932350e5d7c48804a73dc1f09383e
|