# MCP Server Template (Python) [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/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](#quick-start) - [Command Line Options](#command-line-options) - [Creating Your Own Tools and Prompts](#creating-your-own-tools-and-prompts) - [Project Structure](#project-structure) - [Deployment Options](#deployment-options) - [Development Guide](#development-guide) - [Need Help?](#need-help) ## ๐Ÿš€ Quick Start ### Prerequisites - Python 3.10 or newer ### Setup in 3 Easy Steps #### 1๏ธโƒฃ Install the package ```bash # 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 ```bash # 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: ```bash # 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: ```python @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: ```python @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 ```bash # 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 ```bash # 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? - ๐Ÿ“š MCP Documentation: [modelcontextprotocol.io](https://modelcontextprotocol.io) - ๐Ÿ› File an issue: [GitHub Issues](https://github.com/nisarg38/mcp-server-template-python/issues) - ๐Ÿ’ฌ Community: Join our Discord community (link coming soon) --- Made with โค๏ธ for the AI developer community