简单回显测试
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"simple_echo_server": {
"args": [
"-e",
"const http = require('http'); const port = process.env.PORT || 3000; const server = http.createServer((req, res) =\u003e { if (req.url === '/tool/execute' \u0026\u0026 req.method === 'POST') { let body = ''; req.on('data', chunk =\u003e body += chunk); req.on('end', () =\u003e { try { const { name, arguments: args } = JSON.parse(body); if (name === 'echo') { res.writeHead(200, { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' }); res.end(JSON.stringify({ content: [{ type: 'text', text: `回声: ${args.text || 'Hello, MCP!'}` }] })); } else { res.writeHead(400, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ error: 'Unknown tool' })); } } catch (e) { res.writeHead(500, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ error: 'Invalid JSON' })); } }); } else { res.writeHead(404, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ error: 'Not Found' })); } }).listen(port, () =\u003e console.log('MCP Echo Server running on port', port));"
],
"command": "node",
"env": {}
}
}
}
服务介绍
Simple Echo MCP Server
一个极简的 Model Context Protocol (MCP) 服务器示例,用于演示和测试目的。
功能
- echo: 一个简单的工具,接收一段文本并返回包含该文本的回应。
快速开始
本服务被配置为 仅本地可用。用户需要在本地环境中运行它。
前提条件
- 确保系统已安装 Node.js (版本 14 或更高)。
运行服务器
- 在 Claude Desktop App 或其他支持 MCP 的客户端中配置此服务器。
- 客户端的配置会自动使用提供的命令启动本服务器。
- 或者,您也可以手动运行等效的命令来启动服务器进行测试。
手动测试
您可以使用 curl 命令测试服务器是否工作:
curl -X POST http://localhost:3000/tool/execute \
-H "Content-Type: application/json" \
-d '{
"name": "echo",
"arguments": {
"text": "你好,世界!"
}
}'
如果成功,您将收到类似以下的响应:
{"content":[{"type":"text","text":"回声: 你好,世界!"}]}
协议兼容性
此服务器实现了 MCP 的 execute 端点 (/tool/execute)。
注意
这是一个非常基础的示例服务器,仅用于学习和测试。它不具备生产环境所需的错误处理、安全性和健壮性。