Skip to main content

Turn existing projects into MCP servers

Project description

MCPify

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
  • MCP Server Generation: Convert any project into a fully functional MCP server
  • Multiple Backend Support: Works with command-line tools, HTTP APIs, 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
  • Flexible Configuration: Fine-tune tool definitions and parameters through JSON configuration

๐Ÿ“ฆ Installation

Using pip (recommended)

pip install mcpify

From source

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

๐Ÿ› ๏ธ Quick Start

1. Detect APIs in your project

mcpify detect /path/to/your/project

This will analyze your project and generate a project-name.json configuration file containing the detected API structure.

2. Validate the configuration

mcpify validate project-name.json --verbose

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

3. Start the MCP server

mcpify start project-name.json

Your project is now running as an MCP server, ready to be used by AI assistants and other MCP clients!

๐Ÿ“‹ Usage Examples

Command-Line Tool Integration

For CLI tools with argparse:

# cli_tool.py
import argparse

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--hello', action='store_true', help='Say hello')
    parser.add_argument('--echo', type=str, help='Echo a message')
    parser.add_argument('--add', nargs=2, type=float, help='Add two numbers')
    args = parser.parse_args()

    if args.hello:
        print("Hello!")
    elif args.echo:
        print(f"Echo: {args.echo}")
    elif args.add:
        print(f"Result: {args.add[0] + args.add[1]}")

MCPify automatically generates:

{
  "backend": {
    "type": "commandline",
    "config": {
      "command": "python3",
      "args": ["cli_tool.py"],
      "cwd": "."
    }
  },
  "tools": [
    {
      "name": "hello",
      "description": "Say hello",
      "args": ["--hello"],
      "parameters": []
    },
    {
      "name": "echo",
      "description": "Echo a message",
      "args": ["--echo", "{message}"],
      "parameters": [
        {
          "name": "message",
          "type": "string",
          "description": "The message value"
        }
      ]
    }
  ]
}

Interactive Command Applications

MCPify can detect interactive command-based applications:

# server.py
def main():
    while True:
        line = input()
        if line.lower() == 'hello':
            print("Hello there!")
        elif line.lower().startswith('echo '):
            message = line[5:]
            print(f"Echo: {message}")
        elif line.lower() == 'quit':
            break

Detected commands:

  • hello - Simple command
  • echo - Command with message parameter

FastAPI Application

MCPify can automatically detect FastAPI applications and their endpoints:

# main.py
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "Hello World"}

@app.get("/todos/{todo_id}")
async def get_todo(todo_id: int):
    return {"id": todo_id, "title": "Sample todo"}

@app.post("/todos")
async def create_todo(todo: dict):
    return {"id": 1, **todo}

MCPify will detect:

  • Route parameters ({todo_id})
  • HTTP methods (GET, POST, PUT, DELETE, PATCH)
  • Query parameters
  • Proper parameter types

Generated configuration:

{
  "name": "fastapi-app",
  "description": "FastAPI application",
  "backend": {
    "type": "http",
    "config": {
      "base_url": "http://localhost:8000",
      "timeout": 30
    }
  },
  "tools": [
    {
      "name": "root",
      "description": "GET / endpoint",
      "args": ["/"],
      "parameters": []
    },
    {
      "name": "get_todo",
      "description": "GET /todos/{todo_id} endpoint",
      "args": ["/todos/{todo_id}", "{todo_id}"],
      "parameters": [
        {
          "name": "todo_id",
          "type": "integer",
          "description": "The todo_id parameter"
        }
      ]
    }
  ]
}

๐Ÿ”ง Configuration

MCPify uses JSON configuration files to define how your project should be exposed as an MCP server.

Backend Types

  • commandline: Execute command-line tools
  • http: Call HTTP REST APIs
  • websocket: Connect to WebSocket endpoints

Parameter Types

MCPify supports various parameter types:

  • string: Text input
  • integer: Whole number input
  • number/float: Numeric input
  • boolean: True/false values
  • array: List of values

Validation

The built-in validation system checks:

  • Required fields presence
  • Parameter type consistency
  • Backend configuration validity
  • Tool name uniqueness
  • Parameter usage in arguments

๐Ÿ“ Example Projects

The repository includes several example projects:

FastAPI Todo Server

cd example-projects/fastapi-todo-server
uvicorn main:app --reload
# In another terminal:
mcpify detect . --output todo-api.json
mcpify validate todo-api.json

Features:

  • Complete CRUD API for todo management
  • Path parameters ({todo_id})
  • Query parameters for filtering
  • Automatic OpenAPI documentation

Python Server Project

cd example-projects/python-server-project
python server.py &
mcpify detect . --output server-api.json

Features:

  • Interactive command processing
  • Simple text-based protocol
  • Multiple command types

๐Ÿงช 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 test files
python -m pytest tests/test_detect.py tests/test_validate.py -v

Project Structure

mcpify/
โ”œโ”€โ”€ mcpify/           # Main package
โ”‚   โ”œโ”€โ”€ cli.py        # Command-line interface
โ”‚   โ”œโ”€โ”€ detect.py     # API detection engine
โ”‚   โ”œโ”€โ”€ validate.py   # Configuration validation
โ”‚   โ”œโ”€โ”€ backend.py    # Backend abstraction layer
โ”‚   โ”œโ”€โ”€ wrapper.py    # MCP protocol wrapper
โ”‚   โ””โ”€โ”€ __init__.py
โ”œโ”€โ”€ tests/            # Test suite
โ”‚   โ”œโ”€โ”€ test_detect.py
โ”‚   โ”œโ”€โ”€ test_validate.py
โ”‚   โ””โ”€โ”€ __init__.py
โ”œโ”€โ”€ example-projects/ # Example configurations
โ”‚   โ”œโ”€โ”€ fastapi-todo-server/
โ”‚   โ””โ”€โ”€ python-server-project/
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ pyproject.toml

Available Commands

# Detect APIs in a project
mcpify detect <project_path> [--output <file>] [--openai-key <key>]

# Validate a configuration file
mcpify validate <config_file> [--verbose]

# Start an MCP server (coming soon)
mcpify start <config_file>

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guidelines for details on:

  • Setting up the development environment
  • Running tests and linting
  • Submitting pull requests
  • Reporting issues

Development Setup

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

๐Ÿ“„ License

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

๐Ÿ”— Related Projects

๐Ÿ“ž Support


Made with โค๏ธ by the MCPify team

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.0.tar.gz (35.1 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.0-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mcpify-0.1.0.tar.gz
  • Upload date:
  • Size: 35.1 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.0.tar.gz
Algorithm Hash digest
SHA256 428c5a5e127a97f184930fc2df4808fffcba8290e0ebe589c1d0bfdc7b7ecef1
MD5 008cae3813d350ffab9daef06adc132b
BLAKE2b-256 8ca585aff7295c9e9b3ee2a53c2b66ab9feabc0d1b3d703b1f3e1447b1c4adca

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mcpify-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9ac556604308ca53dc6cdd477e64102aad5240639493d630b9ed8d612a57b270
MD5 6bded9032a8796edd6579e06206090f5
BLAKE2b-256 5b930d5cf08cff831829d5c4de172214aaf1d055196b72e34154ac13743bd904

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