Skip to main content

Python Package to provide assistance in generating MCP server project.

Project description

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+
  • click
  • pyyaml
  • MCP framework

These dependencies will be automatically installed when you install the package.

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

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)

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_codegen-1.0.1.tar.gz (44.8 kB view details)

Uploaded Source

Built Distribution

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

mcp_codegen-1.0.1-py3-none-any.whl (49.8 kB view details)

Uploaded Python 3

File details

Details for the file mcp_codegen-1.0.1.tar.gz.

File metadata

  • Download URL: mcp_codegen-1.0.1.tar.gz
  • Upload date:
  • Size: 44.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for mcp_codegen-1.0.1.tar.gz
Algorithm Hash digest
SHA256 523409787ebe028ef2670278f77b6a99e29e5bac6f82e86d79295f32cc557a6c
MD5 e4dc96c7c09f6adb2c6d3ddff0e86afd
BLAKE2b-256 b3475721d5c50c87408b3e37b0be703cf176a885af658718ada496588b51369f

See more details on using hashes here.

File details

Details for the file mcp_codegen-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: mcp_codegen-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 49.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for mcp_codegen-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0a6dba7b394a9b5d7194f14b6972264f6636f8b9a14c639b61dd3cc0401eecad
MD5 2a4c07560dd0a4e5994f8b4c1b56cece
BLAKE2b-256 a3dcfab557606975543790e5e50fc4f591e28dc9e81a496d0fb00c5ed91363ee

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