mcp-server-py-template

M12398s/mcp-server-py-template
Hosted
0 Stars 12 次浏览 FeiCoder 更新于 2026-08-23

MCP 服务配置

复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用

{
  "mcpServers": {
    "mcp-server-py": {
      "args": [
        "run",
        "mcp-server",
        "--transport",
        "stdio"
      ],
      "command": "uv"
    }
  }
}

可用工具 (4 个)

该服务在 MCP 协议中暴露的工具,AI 可按需调用

add 2 个参数 需填 2 项

Add two numbers together. Args: a: First number b: Second number Returns: The sum of a and b

必填参数:a、b

subtract 2 个参数 需填 2 项

Subtract the second number from the first. Args: a: Number to subtract from b: Number to subtract Returns: The result of a - b

必填参数:a、b

multiply 2 个参数 需填 2 项

Multiply two numbers together. Args: a: First number b: Second number Returns: The product of a and b

必填参数:a、b

divide 2 个参数 需填 2 项

Divide the first number by the second. Args: a: Numerator b: Denominator Returns: The result of a / b

必填参数:a、b

服务介绍

mcp-server-py-template

一个 Python MCP (Model Context Protocol) 服务器,通过 HTTP 提供当前时间功能。

功能

  • 通过 HTTP 实现 MCP 协议
  • 提供获取当前日期和时间的工具

安装

确保安装了 uv。如果没有,请从 https://github.com/astral-sh/uv 安装。

克隆仓库并安装依赖:

git clone https://github.com/FeiCoder/mcp-server-py-template.git
cd mcp-server-py-template
uv sync

使用

运行服务器:

uv run mcp-server

服务器将在 http://0.0.0.0:8000 上启动。

MCP 协议

此服务器实现 MCP 协议用于工具调用。它支持:

  • initialize:初始化连接
  • tools/list:列出可用工具
  • tools/call:调用工具

可用工具:

  • get_current_time:返回当前日期和时间(ISO 格式)

开发

在开发模式下运行:

uv run uvicorn mcp_server.main:app --reload

测试

运行测试脚本以验证服务器功能:

# 首先启动服务器(在新终端中)
uv run mcp-server

# 然后运行测试
uv run python test_mcp_server.py

测试脚本将验证:

  • 初始化连接
  • 列出可用工具
  • 调用 get_current_time 工具

相关 MCP 服务