Skip to main content

Turn existing projects into MCP servers

Project description

MCPify - Export all projects as MCP servers!

Python 3.10+ License: MIT

MCPify is a powerful tool that automatically detects APIs in existing projects and transforms them into Model Context Protocol (MCP) servers. This enables seamless integration of your existing command-line tools, web APIs, and applications with AI assistants and other MCP-compatible clients.

๐Ÿš€ Features

  • Automatic API Detection: Analyze existing projects and extract their API structure
    • CLI Tools: Detect argparse-based command-line interfaces
    • Web APIs: Support for Flask and FastAPI applications with route detection
    • Interactive Commands: Identify command-based interactive applications
  • Flexible MCP Server: Multiple ways to start and control MCP servers
  • Multiple Backend Support: Works with command-line tools, HTTP APIs, Python modules, and more
  • Configuration Validation: Built-in validation system to ensure correct configurations
  • Parameter Detection: Automatically extract route parameters, query parameters, and CLI arguments
  • Zero Code Changes: Transform existing projects without modifying their source code
  • Professional Architecture: Clean separation between detection, configuration, and server execution

๐Ÿ“ฆ Installation

Using pip (recommended)

pip install mcpify

From source

git clone https://github.com/your-username/mcpify.git
cd mcpify
pip install -e .

๐Ÿ—๏ธ Project Architecture

mcpify/
โ”œโ”€โ”€ mcpify/                    # Core package
โ”‚   โ”œโ”€โ”€ cli.py                 # CLI interface (mcpify command)
โ”‚   โ”œโ”€โ”€ __main__.py            # Module entry point
โ”‚   โ”œโ”€โ”€ wrapper.py             # MCP protocol wrapper
โ”‚   โ”œโ”€โ”€ backend.py             # Backend adapters
โ”‚   โ”œโ”€โ”€ detect.py              # API detection engine
โ”‚   โ””โ”€โ”€ validate.py            # Configuration validation
โ”œโ”€โ”€ examples/                  # Example projects
โ”œโ”€โ”€ docs/                      # Documentation
โ”‚   โ””โ”€โ”€ usage.md               # Detailed usage guide
โ””โ”€โ”€ tests/                     # Test suite

๐Ÿ› ๏ธ Quick Start

1. Detect APIs in your project

mcpify detect /path/to/your/project --output config.json

This analyzes your project and generates a configuration file containing the detected API structure.

2. View and validate the configuration

mcpify view config.json
mcpify validate config.json

This validates the generated configuration and shows any warnings or errors.

3. Start the MCP server

MCPify provides multiple ways to start MCP servers:

# Method 1: Using mcpify CLI (recommended)
mcpify serve config.json

# Method 2: Direct module invocation
python -m mcpify serve config.json

# HTTP mode for web integration
mcpify serve config.json --mode streamable-http --port 8080

# Example with provided configurations
mcpify serve examples/python-server-project/server.json
mcpify serve examples/python-server-project/server.json --mode streamable-http --port 8888
mcpify serve examples/python-cmd-tool/cmd-tool.json

๐ŸŽฏ Usage Scenarios

For Developers (API Detection & Testing)

# Detect and test your APIs
mcpify detect my-project --output my-project.json
mcpify view my-project.json
mcpify serve my-project.json

For MCP Clients (Server Integration)

# MCP clients can start servers directly
mcpify serve config.json                    # stdio mode
mcpify serve config.json --mode streamable-http  # HTTP mode

For Production Deployment

# Deploy as HTTP server
mcpify serve config.json --mode streamable-http --host 0.0.0.0 --port 8080

๐Ÿ“‹ Backend Types & Examples

FastAPI/Flask Web Applications

{
  "name": "my-web-api",
  "description": "Web API server",
  "backend": {
    "type": "fastapi",
    "base_url": "http://localhost:8000"
  },
  "tools": [
    {
      "name": "get_user",
      "description": "Get user information",
      "endpoint": "/users/{user_id}",
      "method": "GET",
      "parameters": [
        {
          "name": "user_id",
          "type": "string",
          "description": "User ID"
        }
      ]
    }
  ]
}

Python Modules

{
  "name": "my-python-tools",
  "description": "Python module backend",
  "backend": {
    "type": "python",
    "module_path": "./my_module.py"
  },
  "tools": [
    {
      "name": "calculate",
      "description": "Perform calculation",
      "function": "calculate",
      "parameters": [
        {
          "name": "expression",
          "type": "string",
          "description": "Mathematical expression"
        }
      ]
    }
  ]
}

Command-Line Tools

{
  "name": "my-cli-tool",
  "description": "Command line tool backend",
  "backend": {
    "type": "commandline",
    "config": {
      "command": "python3",
      "args": ["./my_script.py"],
      "cwd": "."
    }
  },
  "tools": [
    {
      "name": "process_data",
      "description": "Process data with CLI tool",
      "args": ["--process", "{input_file}"],
      "parameters": [
        {
          "name": "input_file",
          "type": "string",
          "description": "Input file path"
        }
      ]
    }
  ]
}

๐Ÿ”ง Configuration

Supported Backend Types

  • fastapi: FastAPI web applications
  • python: Python modules and functions
  • commandline: Command-line tools and scripts
  • external: External programs and services

Server Modes

  • stdio: Standard input/output (default MCP mode)
  • streamable-http: HTTP Server-Sent Events mode

Parameter Types

  • string, integer, number, boolean, array
  • Automatic type detection from source code
  • Custom validation rules

โš™๏ธ Server Configuration

Command Line Options

# Basic usage
mcpify serve config.json

# Specify server mode
mcpify serve config.json --mode stdio              # Default mode
mcpify serve config.json --mode streamable-http    # HTTP mode

# Configure host and port (HTTP mode only)
mcpify serve config.json --mode streamable-http --host localhost --port 8080
mcpify serve config.json --mode streamable-http --host 0.0.0.0 --port 9999

# Real examples with provided configurations
mcpify serve examples/python-server-project/server.json
mcpify serve examples/python-server-project/server.json --mode streamable-http --port 8888
mcpify serve examples/python-cmd-tool/cmd-tool.json --mode stdio

Server Modes Explained

STDIO Mode (Default)

  • Uses standard input/output for communication
  • Best for local MCP clients and development
  • No network configuration needed
mcpify serve config.json
# or explicitly
mcpify serve config.json --mode stdio

Streamable HTTP Mode

  • Uses HTTP with Server-Sent Events
  • Best for web integration and remote clients
  • Requires host and port configuration
# Local development
mcpify serve config.json --mode streamable-http --port 8080

# Production deployment
mcpify serve config.json --mode streamable-http --host 0.0.0.0 --port 8080

Environment Integration

For MCP Clients

# Claude Desktop or other MCP clients can invoke:
mcpify serve your-config.json

For Web Applications

# Start HTTP server for web integration
mcpify serve your-config.json --mode streamable-http --port 8080
# Then connect from web clients to http://localhost:8080

๐Ÿ“ Examples

Explore the examples/ directory for ready-to-use configurations:

# View example configurations
mcpify view examples/python-server-project/server.json
mcpify view examples/python-cmd-tool/cmd-tool.json

# Test with examples - STDIO mode (default)
mcpify serve examples/python-server-project/server.json
mcpify serve examples/python-cmd-tool/cmd-tool.json

# Test with examples - HTTP mode
mcpify serve examples/python-server-project/server.json --mode streamable-http --port 8888
mcpify serve examples/python-cmd-tool/cmd-tool.json --mode streamable-http --port 9999

๐Ÿงช Development

Running Tests

# Run all tests
python -m pytest tests/ -v

# Run with coverage
python -m pytest tests/ --cov=mcpify --cov-report=html

# Run specific tests
python -m pytest tests/test_detect.py -v

Development Setup

git clone https://github.com/your-username/mcpify.git
cd mcpify
pip install -e ".[dev]"
python -m pytest tests/ -v

Available Commands

MCPify CLI Commands

mcpify detect <project_path> [--output <file>]    # Detect APIs
mcpify view <config_file>                         # View configuration
mcpify validate <config_file>                     # Validate configuration
mcpify serve <config_file> [--mode <mode>]        # Start server

๐Ÿš€ Deployment Options

1. Package Installation

pip install mcpify
# Use mcpify serve for all scenarios

2. Module Invocation

# Run as Python module
python -m mcpify serve config.json
python -m mcpify serve config.json --mode streamable-http --port 8080

3. Docker Deployment

FROM python:3.10-slim
COPY . /app
WORKDIR /app
RUN pip install .
CMD ["mcpify", "serve", "config.json", "--mode", "streamable-http", "--host", "0.0.0.0", "--port", "8080"]

4. Production HTTP Server

# Start HTTP server for production
mcpify serve config.json --mode streamable-http --host 0.0.0.0 --port 8080

# With custom configuration
mcpify serve config.json --mode streamable-http --host 127.0.0.1 --port 9999

๐Ÿค Contributing

We welcome contributions! Please see our development setup above and:

  • Fork the repository
  • Create a feature branch
  • Add tests for new functionality
  • Submit a pull request

Code Quality

# Linting and formatting
ruff check mcpify/
ruff format mcpify/

# Type checking
mypy mcpify/

๐Ÿ“„ License

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

๐Ÿ”— Related Projects

๐Ÿ“ž Support

  • Documentation: See docs/usage.md for detailed usage instructions
  • Examples: Check the examples/ directory for configuration templates
  • Issues: GitHub Issues
  • Discussions: GitHub Discussions

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

mcpify-0.1.4.tar.gz (38.2 kB view details)

Uploaded Source

Built Distribution

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

mcpify-0.1.4-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mcpify-0.1.4.tar.gz
  • Upload date:
  • Size: 38.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mcpify-0.1.4.tar.gz
Algorithm Hash digest
SHA256 494d836469b4abce014e954cff4a51213363bd892d73951ee5fd39422d6492f3
MD5 b3ba1990806d4570698d437d53189b58
BLAKE2b-256 e71f675aec29490de0ed0d5ecffa903125bff3cd606941017c3729d5e833379d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mcpify-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 24.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mcpify-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 17735b6ef835456e6e8c326ac74c657dc9f087a973dbd4b43540ab7154368306
MD5 16a6cd2cd8d0f5c77b8835b85c84cc2f
BLAKE2b-256 ddbf161030466b42c5c5f0a165004ccdd5ff155c19a683c27f981fbb4ff0f536

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