Skip to main content

A CLI for the MCP Modelservice Example

Project description

mcp-modelservice-sdk

🚀 Easily build and deploy MCP (Model Context Protocol) services from your Python functions

PyPI version Python 3.10+ License: MIT

mcp-modelservice-sdk is a powerful toolkit that transforms your Python functions into fully-featured MCP services with minimal configuration. Perfect for developers who want to quickly expose their Python code as MCP tools without the complexity of manual service setup.

✨ Key Features

  • 📦 Zero-Config Packaging: Convert Python functions to MCP services instantly
  • 🚀 One-Command Deployment: Start services with a single command
  • 🔄 Smart Auto-Routing: Automatic endpoint generation based on your code structure
  • 🌐 Production Ready: Built-in support for Docker, cloud platforms, and scaling
  • 🛠️ Developer Friendly: Interactive testing interface and comprehensive documentation
  • 🎯 Type Safe: Full support for Python type hints and automatic validation

🚀 Quick Start

Installation

# Using pip
pip install mcp-modelservice-sdk

# Using uv (recommended)
pip install uv
uv pip install mcp-modelservice-sdk

Basic Usage

  1. Create your Python functions:
# my_tools.py
def add_numbers(a: float, b: float) -> float:
    """Add two numbers together"""
    return a + b

def get_weather(city: str) -> str:
    """Get weather information for a city"""
    return f"Weather in {city}: Sunny, 25°C"
  1. Run as MCP service:
# Start local development server
mcp-modelservice run --source-path my_tools.py --port 8080

# Or with uv
uvx mcp-modelservice-sdk run --source-path my_tools.py --port 8080
  1. Test your service:
    • Visit http://localhost:8080/mcp for interactive testing
    • Use any MCP client to connect and call your functions

Production Packaging

# Package for deployment
mcp-modelservice package --source-path ./my_code --output my-service.zip

# Extract and deploy
unzip my-service.zip
cd my-service/project
python main.py

🏗️ How It Works

The SDK automatically:

  • Discovers all functions in your Python files
  • Converts them to MCP-compatible tools with proper schemas
  • Generates REST endpoints and documentation
  • Packages everything into deployable services
  • Provides interactive testing interfaces

Architecture Modes

  • Composed Mode: All tools accessible from a single endpoint
  • Routed Mode: Directory-based routing with separate endpoints per module

🌐 Deployment Options

Deploy anywhere Python runs:

  • Local Development: Direct execution with python main.py
  • Docker: Pre-configured Dockerfile included
  • Cloud Platforms: Compatible with Heroku, AWS Lambda, Google Cloud Run, Azure
  • Traditional Servers: Standard WSGI/ASGI deployment

📚 Client Integration

Python Client Example

import requests

def call_tool(tool_name, params):
    response = requests.post(
        "http://localhost:8080/mcp",
        json={
            "jsonrpc": "2.0",
            "method": tool_name,
            "params": params,
            "id": 1
        }
    )
    return response.json()

# Use your functions
result = call_tool("add_numbers", {"a": 5, "b": 3})
print(result)  # {"jsonrpc": "2.0", "result": 8, "id": 1}

FastMCP Client Example

from fastmcp import FastMCP

client = FastMCP("http://localhost:8080")
result = await client.call_tool("add_numbers", {"a": 5, "b": 3})

⚙️ Configuration

Command Line Options

Option Description Default
--source-path Path to Python files/directory Current directory
--port Service port 8080
--host Service host 127.0.0.1
--mcp-name Service name Auto-generated

Environment Variables

# .env file
HOST=0.0.0.0
PORT=8080
MCP_SERVER_NAME=my-service
LOG_LEVEL=INFO

🤝 Use Cases

Perfect for:

  • Rapid Prototyping: Quickly expose Python functions as web services
  • Microservices: Convert existing Python modules to independent services
  • API Generation: Auto-generate REST APIs from Python functions
  • Tool Integration: Make Python tools accessible to MCP clients
  • Development Testing: Interactive testing of Python functions

🛠️ Requirements

  • Python: 3.10 or higher
  • Dependencies: FastAPI, FastMCP, Pydantic, Uvicorn (auto-installed)

📖 Documentation & Support

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


Made with ❤️ for the Python and MCP communities

Ready to transform your Python functions into powerful MCP services? Install mcp-modelservice-sdk today!

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

mcp_modelservice_sdk-0.2.6.tar.gz (56.0 kB view details)

Uploaded Source

Built Distribution

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

mcp_modelservice_sdk-0.2.6-py3-none-any.whl (55.4 kB view details)

Uploaded Python 3

File details

Details for the file mcp_modelservice_sdk-0.2.6.tar.gz.

File metadata

File hashes

Hashes for mcp_modelservice_sdk-0.2.6.tar.gz
Algorithm Hash digest
SHA256 de6404d4daa5cd5d1dcf7151fb4789692bd6951c71b1cc8dcf98997ab885f7e1
MD5 58c519d7b0d0bf1c52ede90b3c0506cc
BLAKE2b-256 b77a82a1276055364dfab5342fb0762afa2ded590f2ee75bb1d676343a499c86

See more details on using hashes here.

File details

Details for the file mcp_modelservice_sdk-0.2.6-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_modelservice_sdk-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 fcb7757a7f25fe123ad3e5eaab3010fdb9dfd0a33fcb82cd245e51ae070135a2
MD5 96238c9dff48f60aa0373fad91bb46d9
BLAKE2b-256 a9fa16b4864eb05e525ea75e22d8c0b89b677488940dd442e78ac5deacac870c

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