MCP2Py

v1.0.0Developer Toolsstable

Turn any MCP server into a Python module

mcp2pymcpai-integration
Share:
251
Stars
0
Downloads
0
Weekly
0/5

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

Convert any MCP server into a reusable Python module.
Import MCP functionality directly in Python code.
Integrate MCP servers with Python projects seamlessly.
MaximeRivest

Maintainer

LicenseMIT
Languagepython
Versionv1.0.0
UpdatedMay 16, 2026
Statushealthy
Maintenanceactive

Works with

ClaudeOpenAIwindowsmacoslinux

Installation

Manual Installation

npx mcp2py

Configuration

Configuration Details

Config File

claude_desktop_config.json

Performance

Response Metrics

Response Time< 200ms
ThroughputMedium

Resource Usage

Memory UsageLow
CPU UsageLow

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
1

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 mcp2py
2

Load 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)
3

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)
4

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-...
5

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())
6

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 hints

MCP2Py 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.

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.

Quick Config Preview

{ "mcpServers": { "mcp2py": { "command": "npx", "args": ["-y", "mcp2py"] } } }

Add this to your claude_desktop_config.json or .cursor/mcp.json

Read the full setup guide →

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.

33,000+ ServersFree & Open SourceStep-by-Step Guides