使用说明
Hello World MCP服务器
使用FastMCP构建的简单“Hello World”MCP(模型上下文协议)服务器。此服务器通过几个示例工具演示了基本的MCP功能。
快速开始
在GitHub上使用uvx(推荐)
您可以使用以下命令直接从GitHub运行此MCP服务器 uvx:
uvx --from git+https://github.com/macsymwang/hello-mcp-server.git hello-mcp-server
MCP客户端配置
将此添加到MCP客户端配置中:
{
"mcpServers": {
"hello-world": {
"command": "uvx",
"args": ["--from", "git+https://github.com/macsymwang/hello-mcp-server.git", "hello-mcp-server"]
}
}
}
特性
- 你好:用个性化信息问候某人
- get_server_info:获取有关MCP服务器的信息
- echo消息:回显您发送的任何消息
- count_words:分析文本并统计单词/字符
安装
在GitHub上使用uvx(推荐)
您可以使用以下命令直接从GitHub运行此MCP服务器 uvx:
uvx --from git+https://github.com/macsymwang/hello-mcp-server.git hello-mcp-server
使用PyPI中的uvx(如果已发布)
uvx hello-mcp-server
本地安装
- 克隆或下载此存储库
- 安装软件包:
pip install .
- 运行服务器:
hello-mcp-server
开发安装
对于开发,请在可编辑模式下安装:
pip install -e .
用法
注册为Stdio协议
此MCP服务器旨在与 stdio传输协议,这是MCP服务器与客户端通信的标准方式。服务器从stdin读取JSON-RPC消息,并将响应写入stdout。
MCP客户端配置
克劳德桌面
将此配置添加到您的Claude Desktop配置文件中(通常位于 ~/.config/claude/claude_desktop_config.json 在Linux/Mac或 %APPDATA%\Claude\claude_desktop_config.json 在Windows上):
{
"mcpServers": {
"hello-world": {
"command": "uvx",
"args": ["--from", "git+https://github.com/macsymwang/hello-mcp-server.git", "hello-mcp-server"]
}
}
}
光标IDE
将此添加到您的Cursor MCP配置中:
{
"mcpServers": {
"hello-world": {
"command": "uvx",
"args": ["--from", "git+https://github.com/macsymwang/hello-mcp-server.git", "hello-mcp-server"],
"transport": {
"type": "stdio"
}
}
}
}
通用MCP客户端
对于其他MCP客户端,请使用以下配置:
{
"mcpServers": {
"hello-world": {
"command": "uvx",
"args": ["--from", "git+https://github.com/macsymwang/hello-mcp-server.git", "hello-mcp-server"],
"env": {},
"transport": {
"type": "stdio"
}
}
}
}
手动运行服务器
也可以手动启动服务器进行测试:
-
使用uvx (推荐):
uvx hello-mcp-server -
使用已安装的命令:
hello-mcp-server -
使用Python模块:
python -m hello_mcp_server.server -
直接执行:
python hello_mcp_server/server.py
手动运行时,服务器将在stdin上等待JSON-RPC消息。您可以通过发送MCP协议消息来测试它,但它通常是通过MCP客户端使用的。
可用工具
你好
用个性化信息问候某人。
参数:
name(可选):要问候的人的姓名(默认:“World”)
例子:
{
"name": "Alice"
}
get_server_info
返回有关MCP服务器的信息。
参数: 无
echo消息
回应提供的信息。
参数:
message(必填):要回显的消息
count_words
分析文本并提供单词/字符统计数据。
参数:
text(必填):要分析的文本
配置
标准协议
此MCP服务器使用 stdio传输协议,这意味着:
- 输入:服务器从标准输入(stdin)读取JSON-RPC消息
- 输出:服务器将JSON-RPC响应写入标准输出(stdout)
- 日志记录:错误消息和日志将写入标准错误(stderr)
这是MCP服务器的标准协议,可确保与所有MCP客户端的兼容性。
传输配置
启动时,服务器会自动配置自己进行stdio传输。传输层不需要额外的配置。
有关高级FastMCP配置选项,请参阅FastMCP文档。
需求
- Python 3.8+
- fastmcp>=0.1.0
项目结构
hello-mcp-server/
├── hello_mcp_server/
│ ├── __init__.py
│ └── server.py
├── pyproject.toml
└── README.md
发展
为该项目做出贡献:
- 分叉存储库
- 创建要素分支
- 进行更改
- 如果适用,添加测试
- 提交拉取请求
许可证
这个项目是开源的。请检查许可证文件以了解详细信息。
支持
有关问题和疑问,请在项目存储库上打开问题。
