Skip to main content

PyPI Downloads

MCP CodeGen

MCP CodeGen is a powerful code generation tool designed to create Model Context Protocol (MCP) server implementations from YAML specifications. This tool automates the process of creating structured MCP tools and server code, making it easier to maintain and scale MCP-based applications.

Overview

MCP CodeGen takes a YAML configuration file (mcp_cfg.yaml) that defines MCP tools and their specifications, and generates:

  • Individual tool implementation files
  • MCP server configuration
  • Required project structure

YAML Specification Format

The YAML configuration should follow this structure:

mcp_server:
  mcp_transport_mode: "sse" ##  it can be stdio, sse or streamable-http
  mcp_tools:
    - tool_name: <tool name>
      tool_description: <tool description>
      tool_args:
        - arg_variable: <argument variable name>
          arg_type: <data type>
          arg_description: <argument description>

Example Configuration

mcp_server:
  mcp_transport_mode: "sse"
  mcp_tools:
    - tool_name: add
      tool_description: "sum of two numbers"
      tool_args:
        - arg_variable: "num_a"
          arg_type: int
          arg_description: "first number"
        - arg_variable: "num_b"
          arg_type: int
          arg_description: "2nd number"

Generated Project Structure

The tool generates the following project structure:

project_root/
├── tools/                  # Directory containing tool implementations
│   └── <tool_name>_tool.py
├── mcp_server.py          # MCP server configuration
├── requirements.txt       # Project dependencies
└── mcp_cfg.yaml          # Tool configuration file

Generated Files

  1. Tool Implementation Files (tools/<tool_name>_tool.py):

    • Auto-generated tool modules with proper typing and documentation
    • Function signatures based on YAML specifications
    • Docstrings with descriptions and parameter documentation
  2. MCP Server (mcp_server.py):

    • FastMCP server configuration
    • Automatic tool registration
    • Proper imports of all tool modules

Usage

  1. Create your mcp_cfg.yaml file in the project root directory with your tool specifications following the format shown above

  2. Install the package:

    pip install pyyaml mcp-codegen
    
  3. Run the code generator in your project directory (where mcp_cfg.yaml is located):

    mcp-proj-build
    
  4. The tool will:

    • Validate your YAML configuration
    • Create the project structure
    • Generate tool implementation files
    • Create the MCP server configuration
  5. Implement the tool logic in the generated tool files

  6. Run your MCP server

Requirements

The project requires:

  • Python 3.9+
  • pyyaml
  • MCP

mcp-codegen will create requirements.txt with required dependencies.

Generated Code Examples

Tool Implementation Example

def add(num_a: int, num_b: int) -> Any:
    """
    sum of two numbers

    Parameters
    ----------
    num_a (int): first number
    num_b (int): second number

    Returns
    -------
    Any
        Result of the tool.
    """
    # TODO: implement tool logic
    raise NotImplementedError  # Replace with you custom logic

MCP Server Configuration Example

from tools import add_tool
from mcp.server.fastmcp import FastMCP

# Create an MCP server
mcp = FastMCP("Demo")

# Register tools
mcp.add_tool(add_tool.add)

Metadata

Release files for mcp-codegen 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-codegen 1.0.3
File Size Uploaded Provenance
mcp_codegen-1.0.3.tar.gz 44.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mcp-codegen 1.0.3
File Interpreter ABI Platform
mcp_codegen-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 94.8 kB

Release files / mcp_codegen-1.0.3.tar.gz

Download URL mcp_codegen-1.0.3.tar.gz
Size 44.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a0749ae324caf1a3752b9e6908ac4b12dc62f5c2a87c0e25677c02a94fab06cb
BLAKE2b-256 checksum
How to use checksums
c5a3a7712a36a3fc1d0431e1af0ec5e4f9d8fb2e468a49f34225720e3ea8b006
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release files / mcp_codegen-1.0.3-py3-none-any.whl

Download URL mcp_codegen-1.0.3-py3-none-any.whl
Size 49.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6db09e38b4bbd6d17113c46ea072a13693e5b3ac9e35afaf04113b3b38aac0d8
BLAKE2b-256 checksum
How to use checksums
8f1c58c53dc5ab9a04b7bd52a19eea43d3efe3717013a37419092ea970e75e3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Security for mcp-codegen 1.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page