Cover image
Try Now
2025-03-25

3 years

Works with Finder

1

Github Watches

0

Github Forks

1

Github Stars

MCP Server Template (Python)

Python 3.10+ License: MIT

A ready-to-use template for building Model Context Protocol (MCP) servers in Python. This template helps you quickly create servers that can register and expose tools and prompts for AI models to use.

📚 Table of Contents

🚀 Quick Start

Prerequisites

  • Python 3.10 or newer

Setup in 3 Easy Steps

1️⃣ Install the package

# Clone the repository
git clone https://github.com/nisarg38/mcp-server-template-python.git my-mcp-server
cd my-mcp-server

# Install in development mode
pip install -e ".[dev]"

2️⃣ Run your server

# Run with Python
python -m src.main

# Or use the convenient CLI
mcp-server-template

3️⃣ Your server is now live!

Access your MCP server at:

  • 🌐 HTTP: http://localhost:8080
  • 💻 Or use the stdio transport: mcp-server-template --transport stdio

You'll see log output confirming the server is running successfully.

🎮 Command Line Options

Customize your server behavior with these command-line options:

# Change port (default: 8080)
mcp-server-template --port 9000

# Enable debug mode for more detailed logs
mcp-server-template --debug

# Use stdio transport instead of HTTP
mcp-server-template --transport stdio

# Set logging level (options: debug, info, warning, error)
mcp-server-template --log-level debug

🛠️ Creating Your Own Tools and Prompts

Add a Tool

Tools are functions that AI models can call. To add a new tool:

  1. Edit src/main.py
  2. Add a new function with the @mcp.tool() decorator:
@mcp.tool()
def your_tool_name(param1: str, param2: int) -> Dict[str, Any]:
    """
    Your tool description - this will be shown to the AI.
    
    Args:
        param1: Description of first parameter
        param2: Description of second parameter
        
    Returns:
        Dictionary with your results
    """
    # Your tool logic here
    return {"result": "your result"}

Add a Prompt

Prompts are templates that AI models can access:

@mcp.prompt()
def your_prompt_name(param: str) -> str:
    """Your prompt description."""
    return f"""
    Your formatted prompt with {param} inserted.
    Use this for structured prompt templates.
    """

📁 Project Structure

src/                      # Source code directory
├── main.py               # Server entry point with tools & prompts
├── config.py             # Configuration settings
├── utils/                # Utility functions
├── tools/                # Tools implementation
└── resources/            # Resource definitions
test/                     # Tests directory
pyproject.toml            # Package configuration
Dockerfile                # Docker support

🚢 Deployment Options

Docker Deployment

# Build the Docker image
docker build -t my-mcp-server .

# Run the container
docker run -p 8080:8080 my-mcp-server

Cloud Deployment

This template is designed to work well with various cloud platforms:

  • Deploy as a container on AWS, GCP, or Azure
  • Run on serverless platforms that support containerized applications
  • Works with Kubernetes for orchestration

🧪 Development Guide

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black src test
isort src test

# Run linting
flake8 src test

❓ Need Help?


Made with ❤️ for the AI developer community

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Bora Yalcin
  • Evaluator for marketplace product descriptions, checks for relevancy and keyword stuffing.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Lists Tailwind CSS classes in monospaced font

  • Beniyam Berhanu
  • Therapist adept at identifying core issues and offering practical advice with images.

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • huahuayu
  • 统一的API网关,用于将多个Etherscan样区块链Explorer API与对AI助手的模型上下文协议(MCP)支持。

  • deemkeen
  • 用电源组合控制您的MBOT2:MQTT+MCP+LLM

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

    Reviews

    2 (1)
    Avatar
    user_G4tzQ2mR
    2025-04-16

    The mcp-server-template by Nisarg38 is an incredibly efficient and well-structured Python template for setting up server applications. The comprehensive design and ease of use have significantly streamlined my development process. Highly recommend for anyone looking to build a robust server system! Check it out at https://github.com/Nisarg38/mcp-server-template-python.