一个简单的MCP Server示例,提供向不同人打招呼的工具
Project description
Say Hi MCP Server
这是一个简单的 MCP (Model Context Protocol) Server 示例,提供了几个向不同人打招呼的工具。这个项目旨在展示如何创建和部署一个基本的 MCP Server。
特性
- 🚀 基于 FastMCP 的简单实现
- 👋 提供多个打招呼工具
- 🛠️ 包含错误处理示例
- 📦 完整的 Python 包结构
- 🔧 易于扩展和自定义
- ✅ 使用 Pydantic 进行参数验证和类型安全
- 📝 详细的工具参数描述和示例
安装
使用 uvx(推荐)
uvx 是运行 Python 包的现代方式,无需全局安装,避免依赖冲突:
# 直接运行,无需安装
uvx say-hi-mcp
# 或者使用完整的 PyPI 包名
uvx --from say-hi-mcp say-hi-mcp
从 PyPI 安装
pip install say-hi-mcp
从源码安装
git clone https://github.com/yourusername/say-hi-mcp.git
cd say-hi-mcp
pip install -e .
使用方法
使用 uvx 运行(推荐)
uvx say-hi-mcp
作为命令行工具运行
如果已通过 pip 安装:
say-hi-mcp
作为 Python 模块运行
python -m say_hi_mcp.server
在代码中使用
from say_hi_mcp import SayHiMCPServer
# 创建服务器实例
server = SayHiMCPServer()
# 运行服务器
server.run()
可用工具
该 MCP Server 提供以下工具,所有工具都使用 Pydantic 进行参数验证:
1. hi_alice - 向Alice打招呼
- 参数:
my_name(string, 必需)- 描述: 你的名字,用于介绍自己
- 限制: 长度1-50字符
- 示例: "张三", "李四", "John", "Alice"
- 功能: 与热情开朗的Alice进行友好互动
2. hi_bob - 向Bob打招呼
- 参数:
my_name(string, 必需)- 描述: 你的名字,用于介绍自己
- 限制: 长度1-50字符
- 功能: 与实用主义者Bob进行简洁友好的交流
3. hi_charlie - 向Charlie打招呼(测试工具)
- 参数:
my_name(string, 必需)- 描述: 你的名字,用于介绍自己
- 限制: 长度1-50字符
- 功能: ⚠️ 专门用于测试错误处理,总是抛出异常
4. hi_all - 获取完整打招呼指导
- 参数:
my_name(string, 必需)- 描述: 你的名字,用于介绍自己
- 限制: 长度1-50字符
- 功能: 返回详细的工具使用指南和步骤说明
配置 Claude Desktop
使用 uvx(推荐)
使用 uvx 可以避免全局安装依赖,保持环境整洁:
{
"mcpServers": {
"say-hi": {
"command": "uvx",
"args": ["say-hi-mcp"]
}
}
}
uvx 的优势:
- ✅ 无需预先安装包
- ✅ 自动管理依赖和虚拟环境
- ✅ 避免依赖冲突
- ✅ 始终使用最新版本(除非指定版本)
使用已安装的包
如果你已经通过 pip 安装了包:
{
"mcpServers": {
"say-hi": {
"command": "say-hi-mcp"
}
}
}
使用 Python 直接运行
{
"mcpServers": {
"say-hi": {
"command": "python",
"args": [
"-m", "say_hi_mcp.server"
]
}
}
}
指定特定版本(uvx)
如果需要使用特定版本:
{
"mcpServers": {
"say-hi": {
"command": "uvx",
"args": ["--from", "say-hi-mcp==0.1.0", "say-hi-mcp"]
}
}
}
开发
设置开发环境
# 克隆仓库
git clone https://github.com/yourusername/say-hi-mcp.git
cd say-hi-mcp
# 安装开发依赖
pip install -e ".[dev]"
运行测试
pytest
代码格式化
black say_hi_mcp/
isort say_hi_mcp/
类型检查
mypy say_hi_mcp/
贡献
欢迎贡献!请先 fork 这个仓库,然后创建一个新的分支来进行你的修改。
- Fork 这个项目
- 创建你的特性分支 (
git checkout -b feature/AmazingFeature) - 提交你的修改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 打开一个 Pull Request
许可证
这个项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。
相关链接
更新日志
查看 CHANGELOG.md 了解版本历史和更新内容。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file say_hi_mcp-0.1.23.tar.gz.
File metadata
- Download URL: say_hi_mcp-0.1.23.tar.gz
- Upload date:
- Size: 16.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d459edd963e45ac939c72b1c451c381bf8e19ad402d59e36e485b888d74504e8
|
|
| MD5 |
74c8b73d5bd3b50b84475239df3bba83
|
|
| BLAKE2b-256 |
37a01fbf032864ecdcfb1d531f84588c8d9ab3297202e27bbe7853ed98fb499e
|
File details
Details for the file say_hi_mcp-0.1.23-py3-none-any.whl.
File metadata
- Download URL: say_hi_mcp-0.1.23-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad435fa779c1798ee7d4f90880d26d1900e9fa2139c0d98075f62965db7ef765
|
|
| MD5 |
69006097dc980d1690fc9ba021b6d5c2
|
|
| BLAKE2b-256 |
916e5314d816058ba9ec08efb468da598bb527e2b852afdc04da3b0cf09da737
|