mcpField
S
smithery-ai-cookbook-python-quickstart

smithery-ai-cookbook-python-quickstart

远程服务
github.com/smithery-ai开发工具2057 周前更新
代码仓库

关于 smithery-ai-cookbook-python-quickstart

这是一个使用 FastMCP 和 Python 构建的入门示例 MCP 服务,可与 Smithery 配合使用。它提供名为 count_character 的字符计数工具,适合初学者了解 MCP 服务的基本结构。

主要功能

  1. 01基于 FastMCP 的 Python 实现
  2. 02count_character 字符计数工具
  3. 03可通过 Smithery Playground 测试
  4. 04支持 uv、poetry 和 pip 安装

适用场景

  1. 01学习如何用 FastMCP 创建 MCP 服务
  2. 02在 Smithery Playground 中调试工具
  3. 03将简单服务部署到 Smithery

MCP 相关

该项目是一个 MCP 服务,向 MCP 客户端暴露 count_character 工具,用于统计文本中指定字符出现的次数。

配置

远程服务无需本地安装。选择你使用的客户端,复制配置或使用一键安装。

服务地址https://server.smithery.ai/@smithery-ai/cookbook-python-quickstart/mcp
一键复制安装命令
Claude CodeTerminal
Cursor.cursor/mcp.json
VS Code.vscode/mcp.json
Claude Desktopclaude_desktop_config.json
Windsurf~/.codeium/windsurf/mcp_config.json

命令在终端中运行;JSON 粘贴到对应客户端的 MCP 配置后重启。需要授权的服务会在首次连接时提示登录。

全部服务地址
Streamable HTTPhttps://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)

快速开始

  1. 克隆代码库:

    git clone https://github.com/smithery-ai/smithery-cookbook.git
    cd smithery-cookbook/servers/python/quickstart
    
  2. 安装依赖:

    使用 uv(推荐):

    uv sync
    

    使用 poetry:

    poetry install
    

    使用 pip:

    pip install -r requirements.txt
    
  3. 运行服务:

    有两种方式:

    选项 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?”

  1. 部署到 Smithery: 要部署 MCP 服务:

你的服务将通过 HTTP 提供,并可供任何兼容 MCP 的客户端使用!

停止服务

在终端中按 Ctrl+C 停止服务。

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。