create-mcp-server

repository·main·Indexed 19 days ago

https://github.com/modelcontextprotocol/create-python-server

A scaffolding tool for quickly creating Model Context Protocol (MCP) server projects in Python. It provides an interactive CLI to automate project initialization using uv, generates a standardized project structure with the Model Context Protocol Python SDK, and offers optional automatic integration with the Claude Desktop app configuration.

Tokens
1.8K
Snippets
7
Records
10
Agent score
67%

What's inside create-mcp-server

  1. Overview of create-mcp-server features

    main

    The create-mcp-server tool provides several automated features for developers:

    • Simple CLI: An interactive command-line interface for project scaffolding.
    • Claude Desktop Integration: Automatically configures integration with the Claude Desktop app when it is detected on your system.
    • Fast Package Management: Leverages uvx for efficient project creation and dependency handling.
    • Standardized Structure: Sets up a basic, clean MCP server structure using the Model Context Protocol Python SDK.
    • Zero Configuration: Eliminates the need to manually manage project structures or complex dependency trees.
  2. Install and run create-mcp-server

    main

    You can use create-mcp-server to scaffold new Model Context Protocol (MCP) server projects. It is recommended to use uvx for a fast, reliable experience without manual dependency management. Alternatively, you can install it via pip.

    Prerequisite: You must have UV >= 0.4.10 installed on your machine.

    # Using uvx (recommended)
    uvx create-mcp-server
    
    # Or using pip
    pip install create-mcp-server
    create-mcp-server
  3. Create and start a new MCP server project

    main

    After running the creation command, the tool will walk you through a setup process. Once complete, a new directory is generated containing a standard Python project structure (including pyproject.toml and a src/ directory).

    To initialize the environment and run your newly created server, navigate to the project directory and use uv commands:

    # 1. Create the project (follow the interactive prompts)
    uvx create-mcp-server
    
    # 2. Enter the project directory
    cd my-server
    
    # 3. Sync dependencies and run the server
    uv sync --dev --all-extras
    uv run my-server
  4. Integrate an MCP server with Claude Desktop

    main

    The create-mcp-server tool can automatically update your claude_desktop_config.json to make your new server immediately available in the Claude Desktop app.

    When enabled, the tool adds an entry to the mcpServers section of your configuration file. The entry uses uv to run the server, ensuring the correct environment and dependencies are used.

    Configuration Format Added:

    "mcpServers": {
      "<project_name>": {
        "command": "uv",
        "args": ["--directory", "<absolute_project_path>", "run", "<project_name>"]
      }
    }

    Supported Platforms:

    • Windows: ~/AppData/Roaming/Claude/claude_desktop_config.json
    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  5. Configure Claude Desktop to use a development MCP server

    main

    To use a local, unpublished MCP server with Claude Desktop, add the server configuration to your claude_desktop_config.json file.

    Config File Locations:

    • MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%/Claude/claude_desktop_config.json

    Use the uv command with the --directory flag to point to your server's directory.

    "mcpServers": {
      "{{server_name}}": {
        "command": "uv",
        "args": [
          "--directory",
          "{{server_directory}}",
          "run",
          "{{server_name}}"
        ]
      }
    }
  6. Create a new MCP server project

    main

    Use the create-mcp-server CLI to scaffold a new Python-based Model Context Protocol (MCP) server. The tool automates project initialization using uv, adds the mcp dependency, copies boilerplate templates (including server.py and __init__.py), and optionally configures the server for use in Claude Desktop.

    Requirements:

    • uv must be installed (minimum version 0.4.10).

    CLI Options:

    • --path: The directory where the project will be created.
    • --name: The name of the project (must be a valid Python package name).
    • --version: The server version (must be valid semantic versioning, e.g., 1.0.0).
    • --description: A description of the server.
    • --claudeapp / --no-claudeapp: Whether to automatically add the server to your Claude Desktop configuration (defaults to True).

    Post-creation steps: After creation, navigate to the project directory and sync dependencies:

    cd <project_name>
    uv sync --dev --all-extras
    # Example: Create a server named 'my-mcp-server' in the current directory
    create-mcp-server --name my-mcp-server --description "A custom tool server"
  7. Build and publish an MCP server package

    main

    Follow these steps to prepare and distribute your MCP server package using uv:

    1. Sync dependencies: Update the lockfile and sync the environment.
    2. Build distributions: Create source and wheel distributions in the dist/ directory.
    3. Publish to PyPI: Upload the package to PyPI.

    PyPI Authentication Options:

    • Token: Use --token or the UV_PUBLISH_TOKEN environment variable.
    • Username/Password: Use --username/--password flags or UV_PUBLISH_USERNAME/UV_PUBLISH_PASSWORD environment variables.
    # 1. Sync dependencies
    uv sync
    
    # 2. Build package distributions
    uv build
    
    # 3. Publish to PyPI
    uv publish
  8. Debug an MCP server using the MCP Inspector

    main

    Because MCP servers communicate over stdio, it is recommended to use the MCP Inspector for debugging.

    You can launch the inspector using npx. If your project has a defined binary name, use the specific command structure below. Otherwise, replace <command-to-run-your-server> with your server's startup command.

    # If a binary name is defined:
    npx @modelcontextprotocol/inspector uv --directory {{server_directory}} run {{binary_name}}
    
    # General usage:
    npx @modelcontextprotocol/inspector <command-to-run-your-server>