Skip to main content

Generate dual-mode MCP servers with best practices

Project description

MCP Server Generator

A meta-generator for creating dual-mode MCP servers with best practices

Python Version License

Overview

Generate complete, production-ready MCP (Model Context Protocol) servers that work in two modes:

  • MCP Server Mode: For AI agents (Claude Desktop, etc.)
  • CLI Mode: For developers

This tool is itself an MCP server, enabling AI agents to generate other MCP servers! It demonstrates the dual-mode architecture pattern it creates.

Why Use This?

  • โšก Fast: Generate a complete MCP server in under 5 minutes
  • ๐Ÿ—๏ธ Complete: Includes tests, documentation, packaging, and CI/CD
  • โœ… Tested: Generated servers have comprehensive test suites with high coverage
  • ๐ŸŽฏ Best Practices: Follows validated patterns from production MCP servers
  • ๐Ÿ”ง Dual-Mode: Works as both MCP server and CLI tool
  • ๐Ÿ“ฆ Ready to Publish: GitHub Actions workflows included for PyPI publishing

Features

  • โœ… Dual-mode architecture (MCP + CLI)
  • โœ… Package prefix support (avoid PyPI namespace conflicts with AUTO detection)
  • โœ… Complete project scaffolding (tests, docs, packaging)
  • โœ… GitHub Actions workflows (via pypi-workflow-generator)
  • โœ… Comprehensive test suite (27+ tests with high coverage)
  • โœ… Type hints and documentation
  • โœ… Best practices enforcement
  • โœ… Minimal dependencies

Installation

For MCP Server Usage (Recommended)

Using uvx (no installation required):

The easiest way to use this as an MCP server - just configure in Claude Desktop:

{
  "mcpServers": {
    "mcp-server-generator": {
      "command": "uvx",
      "args": ["hitoshura25-mcp-server-generator"]
    }
  }
}

Prerequisites: Install uv:

# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

For CLI Usage (Alternative)

Using pipx (isolated installation):

pipx install hitoshura25-mcp-server-generator

Using pip:

pip install hitoshura25-mcp-server-generator

From Source (Development)

git clone https://github.com/hitoshura25/mcp-server-generator.git
cd mcp-server-generator
pip install -e .

Quick Start

Interactive Mode (Recommended)

The easiest way to get started:

hitoshura25-mcp-server-generator-cli --interactive

This will guide you through:

  1. Project naming
  2. Author information
  3. Tool definitions
  4. Configuration options

Command-Line Mode

For automation or when you have a tool definition file:

hitoshura25-mcp-server-generator-cli \
  --project-name my-mcp-tool \
  --description "Does something useful" \
  --author "Your Name" \
  --email "you@example.com" \
  --tools-file tools.json

MCP Server Mode (For AI Agents)

Configure mcp-server-generator as an MCP server in Claude Desktop to let Claude generate MCP servers for you:

Using uvx (recommended):

{
  "mcpServers": {
    "mcp-server-generator": {
      "command": "uvx",
      "args": ["hitoshura25-mcp-server-generator"]
    }
  }
}

Using pipx/pip installation:

{
  "mcpServers": {
    "mcp-server-generator": {
      "command": "hitoshura25-mcp-server-generator"
    }
  }
}

For detailed MCP configuration, see MCP-USAGE.md

Package Prefix

To avoid namespace conflicts on PyPI, mcp-server-generator supports prefixing package names. This is highly recommended for unique package names.

Prefix Modes

AUTO (Recommended)

  • Automatically detects your GitHub username from git config
  • Priority: github.user โ†’ remote URL โ†’ user.name (sanitized)
  • Example: my-tool โ†’ username-my-tool

Custom Prefix

  • Use your own prefix (organization name, brand, etc.)
  • Example: --prefix acme โ†’ acme-my-tool

NONE

  • No prefix applied (only if you have a truly unique name)
  • Example: unique-server-name โ†’ unique-server-name

Usage Examples

Interactive Mode:

hitoshura25-mcp-server-generator-cli --interactive
# You'll be prompted: "Prefix (default: AUTO): "
# - Press Enter for AUTO detection
# - Type "NONE" for no prefix
# - Type "acme" for custom prefix

Command-Line:

# AUTO mode (default)
hitoshura25-mcp-server-generator-cli --project-name calculator --prefix AUTO ...

# Custom prefix
hitoshura25-mcp-server-generator-cli --project-name calculator --prefix acme ...

# No prefix
hitoshura25-mcp-server-generator-cli --project-name unique-calculator --prefix NONE ...

MCP Server Mode:

{
  "project_name": "calculator",
  "prefix": "AUTO",
  ...
}

Generated Names

With prefix username and project my-tool:

  • PyPI Package: username-my-tool (install with pip install username-my-tool)
  • Python Import: username_my_tool (use in code as import username_my_tool)
  • CLI Command: username-my-tool (run as username-my-tool --help)
  • MCP Command: mcp-username-my-tool (use in config)

For detailed MCP configuration, see MCP-USAGE.md

What Gets Generated

A complete, production-ready MCP server project:

my-mcp-tool/
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ MCP-USAGE.md
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ setup.py
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ MANIFEST.in
โ”œโ”€โ”€ my_mcp_tool/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ server.py          # MCP server implementation
โ”‚   โ”œโ”€โ”€ cli.py             # CLI interface
โ”‚   โ”œโ”€โ”€ generator.py       # Business logic (TODO stubs)
โ”‚   โ””โ”€โ”€ tests/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ test_server.py  # MCP protocol tests
โ”‚       โ””โ”€โ”€ test_generator.py  # Core logic tests
โ””โ”€โ”€ .github/
    โ””โ”€โ”€ workflows/
        โ””โ”€โ”€ pypi-publish.yml  # PyPI publishing workflow

Generated Features

  • โœ… Working MCP server with proper JSON-RPC over stdio
  • โœ… CLI interface with argparse
  • โœ… Complete test suite (MCP protocol + business logic)
  • โœ… GitHub Actions workflow for PyPI publishing
  • โœ… Comprehensive documentation (README, MCP-USAGE)
  • โœ… Proper Python packaging (setup.py, pyproject.toml)
  • โœ… TODO stubs for easy implementation

Tool Definition Format

Create a tools.json file to define your MCP server's tools:

{
  "tools": [
    {
      "name": "my_function",
      "description": "Does something useful",
      "parameters": [
        {
          "name": "input_text",
          "type": "string",
          "description": "Text to process",
          "required": true
        },
        {
          "name": "max_length",
          "type": "number",
          "description": "Maximum length",
          "required": false
        }
      ]
    }
  ]
}

Supported Types

  • string / str
  • number / int / integer / float
  • boolean / bool
  • array / list
  • object / dict

For complete examples, see EXAMPLES.md

Documentation

Testing

The project includes a comprehensive test suite:

# Run all tests
pytest

# Run with coverage report
pytest --cov=hitoshura25_mcp_server_generator --cov-report=term-missing

# Run specific test file
pytest hitoshura25_mcp_server_generator/tests/test_server.py -v

Test Statistics:

  • 27+ comprehensive tests covering all functionality
  • All async MCP protocol tests passing
  • Template validation tests passing

Requirements

  • Python โ‰ฅ3.8
  • Jinja2 โ‰ฅ3.0
  • hitoshura25-pypi-workflow-generator โ‰ฅ0.3.1

Development

See CONTRIBUTING.md for detailed development instructions.

Quick setup:

# Clone the repository
git clone https://github.com/hitoshura25/mcp-server-generator.git
cd mcp-server-generator

# Create virtual environment
python3 -m venv venv
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Install in development mode
pip install -e .

# Run tests
pytest

Architecture

mcp-server-generator follows a dual-mode architecture pattern:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚     mcp-server-generator            โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”‚
โ”‚  โ”‚ MCP Mode โ”‚      โ”‚ CLI Mode โ”‚     โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜     โ”‚
โ”‚       โ”‚                 โ”‚           โ”‚
โ”‚       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜           โ”‚
โ”‚                โ”‚                    โ”‚
โ”‚         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”‚
โ”‚         โ”‚ generator.py โ”‚            โ”‚
โ”‚         โ”‚ (Core Logic) โ”‚            โ”‚
โ”‚         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚
โ”‚                                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Both modes use the same core generator logic, ensuring consistency.

License

Apache-2.0

Author

Vinayak Menon

Links

Acknowledgments

This project is based on patterns validated in pypi-workflow-generator, a production MCP server for generating GitHub Actions workflows.

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

hitoshura25_mcp_server_generator-0.4.0.tar.gz (99.6 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file hitoshura25_mcp_server_generator-0.4.0.tar.gz.

File metadata

File hashes

Hashes for hitoshura25_mcp_server_generator-0.4.0.tar.gz
Algorithm Hash digest
SHA256 78034c2ab169dda6d7329165c270b634ae0d2a573fd5d9a6b735438eaeab3f89
MD5 65e5e9e2a1e6f414e9ea8a5cb8986b25
BLAKE2b-256 ab4d37e0a542b30c57a5c17379fb0d0c70e0bbc5ce790d859ef10a06cb853661

See more details on using hashes here.

Provenance

The following attestation bundles were made for hitoshura25_mcp_server_generator-0.4.0.tar.gz:

Publisher: release.yml on hitoshura25/mcp-server-generator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hitoshura25_mcp_server_generator-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hitoshura25_mcp_server_generator-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2672bee407b0dbf38663fb5dffac8ee01ea8e02470dc0e9fc692a22f435c487a
MD5 feea673cc4dc469a908a34d45ee94a6f
BLAKE2b-256 348cbd6d7cf9dbe30ef541778d6ecf19bd1f5d15c21e77f643c921d6167b3d03

See more details on using hashes here.

Provenance

The following attestation bundles were made for hitoshura25_mcp_server_generator-0.4.0-py3-none-any.whl:

Publisher: release.yml on hitoshura25/mcp-server-generator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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