MCP2Py
Turn any MCP server into a Python module
What is MCP2Py?
MCP2Py is a Model Context Protocol (MCP) server that allows AI assistants like Claude, Cursor, and VS Code to turn any mcp server into a python module
Turn any MCP server into a Python module
This server falls under the Developer Tools category on MCPgee, the world's largest MCP server directory with 33,000+ servers.
Features
- Turn any MCP server into a Python module
Use Cases
Maintainer
Works with
Installation
Manual Installation
npx mcp2pyConfiguration
Configuration Details
claude_desktop_config.json
Performance
Response Metrics
Resource Usage
How to Set Up and Use MCP2Py
mcp2py is a Python library that converts any MCP server — whether running locally via a shell command, over HTTP(S), or through a remote URL — into a native Python module with fully type-hinted callable functions. It exposes MCP tools as regular Python functions, MCP resources as properties or constants, and MCP prompts as template functions, making it trivial to integrate any MCP server into Python scripts, notebooks, or AI frameworks like DSPy and Claudette. Developers use it to call MCP functionality directly from Python code without needing to manage the underlying protocol, authentication flows, or JSON serialization manually.
Prerequisites
- Python 3.7 or higher installed
- uv package manager recommended (curl -LsSf https://astral.sh/uv/install.sh | sh) or pip
- ANTHROPIC_API_KEY or OPENAI_API_KEY if the server uses LLM sampling
- The MCP server you want to wrap must be accessible (as a CLI command, HTTP URL, or local process)
- An MCP client such as Claude Desktop or Claude Code to test integration
Install mcp2py
Install the mcp2py package using pip or uv. The uv workflow is recommended for clean dependency isolation.
pip install mcp2py
# or with uv:
uv add mcp2pyLoad an MCP server as a Python module
Use the load() function to launch any MCP server command and receive a Python object whose attributes are the server's tools. The server process is managed automatically.
from mcp2py import load
# Load a server by its shell command
weather = load("npx -y @h1deya/mcp-server-weather")
# Call a tool as a regular Python function
alerts = weather.get_alerts(state="CA")
print(alerts)Connect to a remote or authenticated server
For HTTP(S) servers or servers requiring OAuth, pass the URL and set auth='oauth'. mcp2py handles PKCE-based browser authentication and caches tokens automatically.
from mcp2py import load
# Remote server with OAuth
notion = load("https://mcp.notion.com/mcp", auth="oauth")
me = notion.notion_get_self()
print(me)Set environment variables for LLM sampling
If the MCP server requests LLM sampling (asking the client to run inference), mcp2py handles it automatically using whichever API key is available in the environment.
export ANTHROPIC_API_KEY=sk-ant-...
# or
export OPENAI_API_KEY=sk-...Use async support for non-blocking workflows
For async Python applications or notebooks, use aload() to load the server without blocking the event loop.
import asyncio
from mcp2py import aload
async def main():
server = await aload("npx async-server")
result = await server.fetch_data(url="https://example.com")
print(result)
asyncio.run(main())Integrate with AI frameworks
Access the server's tool list as callable objects compatible with DSPy, Claudette, or other AI frameworks that accept function signatures.
from mcp2py import load
server = load("npx my-mcp-server")
tools = server.tools # List of callables with type hintsMCP2Py Examples
Client configuration
Example MCP client configuration for Claude Desktop to expose mcp2py as a development utility. Since mcp2py is a Python library rather than an MCP server itself, the typical use is in scripts; however you can wrap it in a server entry if needed.
{
"mcpServers": {
"mcp2py-demo": {
"command": "python",
"args": ["-m", "mcp2py"],
"env": {
"ANTHROPIC_API_KEY": "sk-ant-YOUR_KEY_HERE"
}
}
}
}Prompts to try
Example Python snippets demonstrating real mcp2py usage patterns
- weather = load("npx -y @h1deya/mcp-server-weather"); weather.get_alerts(state="TX")
- server = load("uvx my-local-server"); print([t.__name__ for t in server.tools])
- notion = load("https://mcp.notion.com/mcp", auth="oauth"); notion.notion_search(query="project plan")
- server = load("npx my-server", env={"API_KEY": "abc"}); result = server.run_query(sql="SELECT 1")Troubleshooting MCP2Py
ModuleNotFoundError or tool call fails with 'server not found'
Ensure the MCP server command (e.g. npx ...) is executable in your shell before calling load(). Test it directly in the terminal first. Also confirm npx or the relevant runtime is on your PATH.
LLM sampling requests hang or raise an error
Set ANTHROPIC_API_KEY or OPENAI_API_KEY in your environment before importing mcp2py. Sampling only triggers if the MCP server explicitly requests it; if unexpected, check the server's documentation.
OAuth authentication loop or token not cached
Tokens are cached in ~/.config/mcp2py/tokens.json. If authentication keeps re-prompting, delete this file to force a fresh login. Ensure your browser can open the OAuth redirect URL.
Frequently Asked Questions about MCP2Py
What is MCP2Py?
MCP2Py is a Model Context Protocol (MCP) server that turn any mcp server into a python module It connects AI assistants to external tools and data sources through a standardized interface.
How do I install MCP2Py?
Follow the installation instructions on the MCP2Py GitHub repository. Clone the repo, install dependencies, and add the server config to your AI client.
Which AI clients work with MCP2Py?
MCP2Py works with all major MCP-compatible AI clients including Claude Desktop, Claude Code, Cursor, VS Code (GitHub Copilot), Windsurf, and Cline.
Is MCP2Py free to use?
Yes, MCP2Py is open source and available under the MIT license. You can use it freely in both personal and commercial projects.
MCP2Py Alternatives — Similar Developer Tools Servers
Looking for alternatives to MCP2Py? Here are other popular developer tools servers you can use with Claude, Cursor, and VS Code.
Ecc
★ 188.2kThe agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
Javaguide
★ 155.8kJava 面试 & 后端通用面试指南,覆盖计算机基础、数据库、分布式、高并发、系统设计与 AI 应用开发
Gemini CLI
★ 104.5kA secure MCP server that wraps the Google Gemini CLI, allowing clients to query Gemini models using local OAuth sessions without requiring an API key. It provides tools for model interaction and diagnostics with built-in protection against command in
Awesome MCP Servers
★ 87.3k⭐ Curated list of Model Context Protocol (MCP) servers - tools that extend Claude Desktop, Cursor, Windsurf, and other MCP clients with custom capabilities.
MCP Servers
★ 86.0kModel Context Protocol Servers
CC Switch
★ 77.5kA cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Gemini CLI & Hermes Agent. Only official website: ccswitch.io
Browse More Developer Tools MCP Servers
Explore all developer tools servers available in the MCPgee directory. Each server includes setup guides for Claude, Cursor, and VS Code.
Set Up MCP2Py in Your Editor
Choose your AI client for step-by-step setup instructions.
Quick Config Preview
Add this to your claude_desktop_config.json or .cursor/mcp.json
Ready to use MCP2Py?
Browse our complete directory of 33,000+ MCP servers, read setup guides for your editor, and start building with the Model Context Protocol.