使用说明
🚀 MCP服务器模板
生产就绪的Python MCP(模型上下文协议)服务器模板
无需配置即可部署到Smithery和其他MCP平台!
✨ 特性
- 🎯 零配置部署 -为Smithery和其他MCP平台做好准备
- 🐍 现代Python -使用Python 3.11+和FastMCP构建
- 🐳 Docker就绪 -容器化,便于部署
- 🔧 模板结构 -MCP工具的完美起点
- 📝 证据充分的 -清晰的例子和最佳实践
- ⚡ 快速设置 -让您的MCP服务器在几分钟内运行
🎯 快速开始
1.使用此模板
点击 “使用此模板” 此存储库顶部的按钮,用于创建自己的MCP服务器。
2.克隆和设置
git clone https://github.com/yourusername/your-mcp-server.git
cd your-mcp-server
pip install -r requirements.txt
3.本地运行
python server.py
4.测试你的工具
# Your MCP server is now running and ready to accept connections!
📦 包含什么
mcp-template/
├── 🐍 app.py # Your tool implementations
├── 🚀 server.py # MCP server configuration
├── 📋 requirements.txt # Python dependencies
├── 🐳 Dockerfile # Container configuration
├── ⚙️ smithery.yaml # Smithery deployment config
└── 📖 README.md # This beautiful documentation
🛠️ 自定义您的工具
添加新工具
- 实现您的工具逻辑 在……里面
app.py:
def myAwesomeTool(param: str) -> str:
"""Your amazing tool implementation."""
# Add your logic here
return f"Processed: {param}"
- 在MCP服务器中注册 在……里面
server.py:
@mcp.tool()
async def my_awesome_tool(param: str) -> str:
"""
Description of what your tool does.
"""
result = myAwesomeTool(param)
return result
工具结构示例
该模板包括一个虚拟工具来帮助您开始:
@mcp.tool()
async def dummy_tool(param: str) -> str:
"""
A sample tool that processes input parameters.
"""
awesome_response = dummyTool(param)
return awesome_response
🚀 部署
Smithery部署
此模板是 Smithery准备就绪 smithery.yaml 配置已设置:
- 将您的自定义代码推送到GitHub
- 将您的存储库连接到Smithery
- 一键部署! 🎉
Docker部署
# Build the container
docker build -t my-mcp-server .
# Run the container
docker run -p 8000:8000 my-mcp-server
手动部署
部署到支持Python应用程序的任何平台:
pip install -r requirements.txt
python server.py
🔧 配置
环境变量
自定义您的MCP服务器行为:
export MCP_SERVER_NAME="my-awesome-mcp"
export LOG_LEVEL="INFO"
依赖项
将所需的包添加到 requirements.txt:
requests>=2.28.0
mcp
your-additional-package>=1.0.0
📚 例子
HTTP API工具
def fetchData(url: str) -> dict:
"""Fetch data from an API endpoint."""
response = requests.get(url)
return response.json()
@mcp.tool()
async def fetch_api_data(url: str) -> str:
"""Fetch and return data from a URL."""
data = fetchData(url)
return json.dumps(data, indent=2)
文件处理工具
def processFile(content: str) -> str:
"""Process file content."""
# Your processing logic
return content.upper()
@mcp.tool()
async def process_text(text: str) -> str:
"""Process and transform text content."""
return processFile(text)
🤝 贡献
发现错误或有功能请求?
- 🍴 分叉存储库
- 🌱 创建要素分支
- 💻 进行更改
- 🧪 彻底测试
- 📝 提交拉取请求
📄 许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
🌟 表示支持
如果这个模板帮助你构建了一些很棒的东西,请考虑:
- ⭐ 引导此存储库 -这让我很开心! 😊
- 🐦 分享它 与其他开发人员
- 🛠️ 贡献 改善社区
由以下材料制成❤️ 靠近 Alperen Koçyiğit
构建人工智能工具集成的未来,一次一台MCP服务器 🚀
