Skip to main content

Quick MCP server creation from Python functions

Project description

py2mcp

Quick MCP (Model Context Protocol) server creation from Python functions.

Installation

pip install py2mcp

Quick Start

from py2mcp import mk_mcp_server

def add(a: int, b: int) -> int:
    """Add two numbers"""
    return a + b

def greet(name: str = "world") -> str:
    """Greet someone"""
    return f"Hello, {name}!"

# Create and run MCP server
mcp = mk_mcp_server([add, greet])

if __name__ == '__main__':
    mcp.run()

That's it! Your functions are now available as MCP tools.

Features

  • Simple: Just pass functions to mk_mcp_server()
  • Flexible: Supports input/output transformations
  • Pythonic: Clean, decorator-free function definitions
  • Powerful: Built on FastMCP for production-ready servers

Input Transformations

Transform inputs before they reach your functions:

from py2mcp import mk_mcp_server, mk_input_trans
import numpy as np

def add_arrays(a, b):
    """Add two numpy arrays"""
    return (a + b).tolist()

# Convert list inputs to numpy arrays
input_trans = mk_input_trans({'a': np.array, 'b': np.array})
mcp = mk_mcp_server([add_arrays], input_trans=input_trans)

From Stores (MutableMapping)

Automatically expose CRUD operations from any mapping:

from py2mcp import mk_mcp_from_store

projects = {'proj1': {'name': 'Project 1'}, 'proj2': {'name': 'Project 2'}}
mcp = mk_mcp_from_store(projects, name="project")

# Automatically creates: list_projects, get_project, set_project, delete_project

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py2mcp-0.1.4.tar.gz (25.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py2mcp-0.1.4-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file py2mcp-0.1.4.tar.gz.

File metadata

  • Download URL: py2mcp-0.1.4.tar.gz
  • Upload date:
  • Size: 25.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for py2mcp-0.1.4.tar.gz
Algorithm Hash digest
SHA256 a04943d4be4a7ea39d3a0c77d5c6f7d380c8bb3173d25964d4fd4f4ca24c3480
MD5 4f425ecb137d99731085d15b1333f85b
BLAKE2b-256 b49236d3428a8ac7ac3573799580551f0160e2a45681b40088ce6bb45dd9a465

See more details on using hashes here.

File details

Details for the file py2mcp-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: py2mcp-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for py2mcp-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a3203861e39b0545a3fe4522b22cbc37be95495cacd19e65bf3c01a0d3776e74
MD5 854d3b9a983c5d533c1e4c6298119ad2
BLAKE2b-256 e30f6846ebcfd1e09e2896e57de2fb280ea05d4e8e513a83b7a1f9bc05ef45bf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page