MCP Server Template (Python)
A minimal, well-structured starter template for building Model Context Protocol (MCP) servers using Python and the FastMCP framework. It includes boilerplate for tools, testing setup, and modern Python packaging to accelerate server development.
README
mcp-server-template
A minimal, well-structured starter template for building Model Context Protocol (MCP) servers in Python using FastMCP.
What is MCP?
The Model Context Protocol is an open standard that lets AI assistants (Claude, GPT, etc.) call external tools and access data sources through a unified interface. An MCP server exposes tools that AI models can discover and invoke — think of it as building an API specifically designed for LLM consumption.
What this template provides
- A working MCP server with example tools you can run immediately
- Clean project structure using modern Python packaging (
pyproject.toml) - Type hints, docstrings, and error handling patterns to follow
- Test setup showing how to verify your tools work
- Linting config with Ruff
Clone it, delete the example tools, add your own, and you have a production-ready MCP server.
Quick start
# Clone the template
git clone https://github.com/futhgar/mcp-server-template.git
cd mcp-server-template
# Create a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -e ".[dev]"
# Run the server
python -m src.server
The server starts in stdio mode by default, which is how MCP clients (like Claude Desktop) communicate with it. To test it interactively:
# If you have the MCP inspector installed
mcp dev src/server.py
Project structure
mcp-server-template/
├── src/
│ ├── __init__.py
│ └── server.py # MCP server definition and tools
├── tests/
│ └── test_server.py # Tool tests
├── pyproject.toml # Project config, dependencies
├── LICENSE
├── .gitignore
└── README.md
Adding your own tools
Open src/server.py and add a new function decorated with @mcp.tool():
@mcp.tool()
def my_tool(query: str, limit: int = 10) -> str:
"""Short description of what this tool does.
The docstring becomes the tool's description that the AI model sees,
so write it clearly — explain what the tool does, what the parameters
mean, and what it returns.
Args:
query: What to search for.
limit: Maximum number of results to return.
"""
# Your logic here
results = do_something(query, limit)
return format_results(results)
Key points:
- The function name becomes the tool name the model calls.
- The docstring becomes the tool description the model reads to decide when to use it.
- Type hints on parameters are required — they define the tool's input schema.
- Return a string (or something that serializes to string). The model reads the return value.
- Raise exceptions for errors — FastMCP handles them and reports them to the client.
Delete the example tools (system_info, find_files, word_frequency) once you understand the pattern.
How to test
# Run tests
pytest
# Run tests with output
pytest -v
# Lint
ruff check src/ tests/
The test file shows how to call your tool functions directly. Since MCP tools are regular Python functions under the hood, you can test them without spinning up a server.
Connecting to Claude Desktop
Add your server to Claude Desktop's config file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Linux: ~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"my-server": {
"command": "python",
"args": ["-m", "src.server"],
"cwd": "/path/to/mcp-server-template"
}
}
}
Restart Claude Desktop and your tools will appear in the tool picker.
Resources
- MCP Specification — The full protocol spec
- MCP Documentation — Guides and tutorials
- FastMCP — The Python framework this template uses
- MCP Server Examples — Official reference servers
License
MIT License. See LICENSE for details.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。