Skip to main content
Glama

MCP Tools

MCP工具

一个使用HTTP SSE(Server-Sent Events)连接的MCP(Model Context Protocol)服务器实现。

🚀 特性

  • ✅ 完整的MCP协议支持
  • 🔄 实时SSE连接
  • 🛠️ 内置实用工具(回显、时间、计算器、天气查询)
  • 🌐 RESTful API接口
  • 📊 健康检查端点
  • 🔧 易于扩展的架构
  • 🌤️ 支持真实天气API和模拟数据

📦 安装

# 克隆项目 git clone <your-repo-url> cd mcp-sse-server # 安装依赖 npm install

🏃‍♂️ 运行

启动服务器

# 生产模式 npm start # 开发模式(自动重启) npm run dev

服务器将在 http://localhost:3000 启动。

运行测试

npm test

📡 API端点

基础信息

  • GET / - 服务器信息
  • GET /health - 健康检查

MCP协议

  • POST /mcp - MCP消息处理
  • GET /sse - SSE连接端点

🛠️ 内置工具

1. echo - 回显工具

{ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "echo", "arguments": { "text": "你好世界" } } }

2. get_current_time - 获取当前时间

{ "jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": { "name": "get_current_time", "arguments": {} } }

3. calculate - 数学计算

{ "jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": { "name": "calculate", "arguments": { "expression": "2 + 3 * 4" } } }

4. get_weather - 天气查询

{ "jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": { "name": "get_weather", "arguments": { "city": "北京", "units": "metric" } } }

🔌 SSE连接

连接到SSE端点以接收实时消息:

const eventSource = new EventSource('http://localhost:3000/sse'); eventSource.onmessage = (event) => { const data = JSON.parse(event.data); console.log('收到消息:', data); };

📝 使用示例

Node.js客户端

import fetch from 'node-fetch'; // 调用MCP工具 const response = await fetch('http://localhost:3000/mcp', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name: 'echo', arguments: { text: '你好,MCP!' } } }), }); const result = await response.json(); console.log(result);

浏览器客户端

<!DOCTYPE html> <html> <head> <title>MCP SSE客户端</title> </head> <body> <div id="messages"></div> <script> // 建立SSE连接 const eventSource = new EventSource('http://localhost:3000/sse'); eventSource.onmessage = (event) => { const data = JSON.parse(event.data); document.getElementById('messages').innerHTML += '<p>' + JSON.stringify(data) + '</p>'; }; // 调用MCP工具 async function callTool() { const response = await fetch('http://localhost:3000/mcp', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name: 'get_current_time', arguments: {} } }), }); const result = await response.json(); console.log(result); } </script> </body> </html>

🔧 扩展开发

添加新工具

  1. src/server.js 的工具列表中添加新工具定义
  2. CallToolRequestSchema 处理器中添加对应的处理逻辑
// 添加到工具列表 { name: "my_new_tool", description: "我的新工具", inputSchema: { type: "object", properties: { param1: { type: "string", description: "参数1", }, }, required: ["param1"], }, } // 添加处理逻辑 case "my_new_tool": return { content: [ { type: "text", text: `处理结果: ${request.params.arguments.param1}`, }, ], };

⚙️ 配置

天气API配置

要使用真实的天气数据,请配置 config/weather.json

  1. 访问 OpenWeatherMap 申请免费API key
  2. 编辑 config/weather.json
    { "openweathermap": { "apiKey": "your_actual_api_key_here", "baseUrl": "https://api.openweathermap.org/data/2.5", "enabled": true } }

如果未配置真实API,系统将使用预设的模拟数据。

🌍 环境变量

  • PORT - 服务器端口(默认: 3000)

📄 许可证

MIT

🤝 贡献

欢迎提交Issue和Pull Request!

📞 支持

如有问题,请创建Issue或联系维护者。

-
security - not tested
F
license - not found
-
quality - not tested

An MCP (Model Context Protocol) server implementation using HTTP SSE (Server-Sent Events) connections with built-in utility tools including echo, time, calculator, and weather query functionality.

  1. 🚀 特性
    1. 📦 安装
      1. 🏃‍♂️ 运行
        1. 启动服务器
        2. 运行测试
      2. 📡 API端点
        1. 基础信息
        2. MCP协议
      3. 🛠️ 内置工具
        1. echo - 回显工具
        2. get_current_time - 获取当前时间
        3. calculate - 数学计算
        4. get_weather - 天气查询
      4. 🔌 SSE连接
        1. 📝 使用示例
          1. Node.js客户端
          2. 浏览器客户端
        2. 🔧 扩展开发
          1. 添加新工具
        3. ⚙️ 配置
          1. 天气API配置
        4. 🌍 环境变量
          1. 📄 许可证
            1. 🤝 贡献
              1. 📞 支持

                Related MCP Servers

                • -
                  security
                  F
                  license
                  -
                  quality
                  This SSE-based MCP server allows users to connect and interact with National Weather Service APIs to retrieve weather alerts and forecasts.
                  Last updated -
                  90
                  Python
                • -
                  security
                  -
                  license
                  -
                  quality
                  A Model Context Protocol (MCP) server that interacts with system APIs, allowing users to check connections, search employees, register breakfast, and update chemical information by shifts.
                  Last updated -
                  2
                • A
                  security
                  A
                  license
                  A
                  quality
                  Model Context Protocol (MCP) server that provides weather forecast, warnings, water level associated with flood, and earthquake reports from Malaysia Government's Open API.
                  Last updated -
                  4
                  Python
                  MIT License
                • A
                  security
                  F
                  license
                  A
                  quality
                  An implementation of the Model Context Protocol (MCP) server using Server-Sent Events (SSE) for real-time communication, providing tools for calculations and dynamic resource templates.
                  Last updated -
                  1
                  JavaScript

                View all related MCP servers

                MCP directory API

                We provide all the information about MCP servers via our MCP API.

                curl -X GET 'https://glama.ai/api/mcp/v1/servers/starzzzzzzzzzzzzzz/mcp-tools'

                If you have feedback or need assistance with the MCP directory API, please join our Discord server