回声服务

一个基于fastmcp框架实现的简单回声服务,提供消息回传和大写转换功能。

  • by wzliu888
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 wzliu888/hackathon_mcp_demo

使用说明

Echo MCP 服务

使用fastmcp框架实现的一个简单回声服务。

安装

  1. 克隆此仓库:
git clone https://github.com/your-username/hackathon_mcp_demo.git
cd hackathon_mcp_demo
  1. 安装所需的依赖项:
pip install -r requirements.txt

使用方法

  1. 启动Echo MCP服务:
python echo_mcp.py
  1. 该服务将在以下地点提供:

    • 回声终端: http://localhost:8000/echo
    • 大写回显终端: http://localhost:8000/echo/uppercase
  2. 向服务发送请求:

from fastmcp import MCPClient

# Create an MCP client
client = MCPClient("http://localhost:8000")

# Send a message to the echo endpoint
response = client.call("/echo", {"message": "Hello, MCP!"})
print(response)  # {"message": "Hello, MCP!"}

# Send a message to the uppercase echo endpoint
response = client.call("/echo/uppercase", {"message": "Hello, MCP!"})
print(response)  # {"message": "HELLO, MCP!"}

API 端点

/echo(回显命令,用于在命令行界面显示输入的命令)

返回发送的确切相同消息。

/echo/uppercase 翻译为中文是:“回显/大写”

返回一个所有字符串值都已转换为大写的消息。

示例

使用curl的示例

# Echo endpoint
curl -X POST http://localhost:8000/echo \
  -H "Content-Type: application/json" \
  -d '{"message": "Hello, MCP!"}'

# Uppercase echo endpoint
curl -X POST http://localhost:8000/echo/uppercase \
  -H "Content-Type: application/json" \
  -d '{"message": "Hello, MCP!"}'