关于 smithery-ai-cookbook-python-quickstart
这是一个使用 FastMCP 和 Python 构建的入门示例 MCP 服务,可与 Smithery 配合使用。它提供名为 count_character 的字符计数工具,适合初学者了解 MCP 服务的基本结构。
主要功能
- 01基于 FastMCP 的 Python 实现
- 02count_character 字符计数工具
- 03可通过 Smithery Playground 测试
- 04支持 uv、poetry 和 pip 安装
适用场景
- 01学习如何用 FastMCP 创建 MCP 服务
- 02在 Smithery Playground 中调试工具
- 03将简单服务部署到 Smithery
MCP 相关
该项目是一个 MCP 服务,向 MCP 客户端暴露 count_character 工具,用于统计文本中指定字符出现的次数。
配置
远程服务无需本地安装。选择你使用的客户端,复制配置或使用一键安装。
https://server.smithery.ai/@smithery-ai/cookbook-python-quickstart/mcpclaude mcp add --transport http ai-smithery-smithery-ai-cookbook-python-quickstart https://server.smithery.ai/@smithery-ai/cookbook-python-quickstart/mcp{"mcpServers":{"ai-smithery-smithery-ai-cookbook-python-quickstart":{"type":"http","url":"https://server.smithery.ai/@smithery-ai/cookbook-python-quickstart/mcp"}}}在 Cursor 中打开{"servers":{"ai-smithery-smithery-ai-cookbook-python-quickstart":{"type":"http","url":"https://server.smithery.ai/@smithery-ai/cookbook-python-quickstart/mcp"}}}在 VS Code 中打开{"mcpServers":{"ai-smithery-smithery-ai-cookbook-python-quickstart":{"type":"http","url":"https://server.smithery.ai/@smithery-ai/cookbook-python-quickstart/mcp"}}}{"mcpServers":{"ai-smithery-smithery-ai-cookbook-python-quickstart":{"serverUrl":"https://server.smithery.ai/@smithery-ai/cookbook-python-quickstart/mcp"}}}命令在终端中运行;JSON 粘贴到对应客户端的 MCP 配置后重启。需要授权的服务会在首次连接时提示登录。
https://server.smithery.ai/@smithery-ai/cookbook-python-quickstart/mcp需要授权工具
详细介绍
Character Counter MCP Server - Python 快速入门
这是一个使用 FastMCP 和 Python 创建 MCP 服务的简单示例,旨在与 Smithery 配合使用。
功能说明
此服务提供一个名为 count_character 的字符计数工具,用于统计指定字符在给定文本中出现的次数。你将使用 Smithery Playground 进行交互式开发和测试。
前提条件
- Python 3.12 或更高版本
- Python 包管理器(推荐使用 uv,也可使用 pip、poetry 等)
- Node.js 和 npx(可选,用于 Smithery Playground)
快速开始
-
克隆代码库:
git clone https://github.com/smithery-ai/smithery-cookbook.git cd smithery-cookbook/servers/python/quickstart -
安装依赖:
使用 uv(推荐):
uv sync使用 poetry:
poetry install使用 pip:
pip install -r requirements.txt -
运行服务:
有两种方式:
选项 A:仅运行服务
# With uv uv run smithery dev # or use the shorter script alias: uv run dev # With poetry poetry run smithery dev # or use the shorter script alias: poetry run dev # With pip (after installing dependencies) smithery dev这会在
http://localhost:8081启动 MCP 服务并使其持续运行。选项 B:运行服务并打开 Playground(推荐用于测试)
# With uv uv run smithery playground # or use the shorter script alias: uv run playground # With poetry poetry run smithery playground # or use the shorter script alias: poetry run playground # With pip (after installing dependencies) smithery playground这会启动 MCP 服务,并在浏览器中自动打开 Smithery Playground,你可以在其中:
- 与 MCP 服务实时交互
- 使用不同的文本和字符测试
count_character工具 - 查看完整的请求/响应流程
- 快速调试并迭代 MCP 工具
测试字符计数器
试着询问:“草莓(strawberry)里有几个 r?”
- 部署到 Smithery:
要部署 MCP 服务:
- 将代码推送到 GitHub(确保包含
smithery.yaml) - 在 https://smithery.ai/new 连接你的代码库
- 将代码推送到 GitHub(确保包含
你的服务将通过 HTTP 提供,并可供任何兼容 MCP 的客户端使用!
停止服务
在终端中按 Ctrl+C 停止服务。
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。