Skip to main content
Glama
wxt2rr

Math Calculator MCP Server

by wxt2rr
README.md3.78 kB
# 数学运算 MCP 服务器 这是一个提供基本数学运算(加、减、乘、除)的 Model Context Protocol (MCP) 服务器。 该服务器支持两种运行模式: 1. **Stdio**:标准输入/输出(默认) 2. **HTTP**:支持 SSE 的 Streamable HTTP ## 前置要求 - Node.js (v18 或更高版本) - npm ## 安装 1. 克隆仓库 2. 安装依赖: ```bash npm install ``` 3. 构建项目: ```bash npx tsc ``` ## 使用方法 ### 1. Stdio 模式(默认) 当与通过子进程启动服务器的 MCP 客户端(如 Claude Desktop, Trae)集成时使用此模式。 ```bash node dist/index.js # 或者 node dist/index.js stdio ``` ### 2. HTTP 模式(Streamable HTTP & SSE) 此模式启动一个支持 Streamable HTTP 和 SSE (Server-Sent Events) 的 HTTP 服务器。 ```bash node dist/index.js http ``` 服务器将在 3000 端口启动(默认)。 - 端点:`http://localhost:3000/mcp` ## 部署 ### ⚠️ 关于 Vercel 部署的重要警告 虽然本项目已配置了 `vercel.json` 以支持部署,但 **强烈不推荐** 将此 MCP 服务器部署到 Vercel Serverless Functions。 **原因:** 1. **无状态问题**:MCP 协议依赖内存状态来关联 SSE 连接和 POST 请求。Vercel 的 Serverless 环境可能会将请求分发到不同的实例,导致“找不到会话”的错误。 2. **连接超时**:MCP 需要长连接 (SSE)。Vercel 函数有执行时间限制(通常 10-60 秒),超时后会强制断开连接。 **如果您执意尝试 Vercel:** 1. 本项目已包含 `vercel.json` 配置。 2. 在 Vercel 仪表盘中导入项目。 3. 确保 `Framework Preset` 设置为 `Other`。 4. Build Command: `npm run build` 5. Output Directory: `dist` (或者留空) --- ### ✅ 推荐部署方式:Docker / Render / Railway 推荐将服务器作为长运行的容器应用部署。 #### 使用 Docker 运行 1. 构建镜像: ```bash docker build -t mcp-math-server . ``` 2. 运行容器: ```bash docker run -p 3000:3000 mcp-math-server ``` #### 部署到 Render/Railway/Heroku 1. 将代码推送到 GitHub。 2. 在 Render/Railway 等平台上创建一个新的 "Web Service"。 3. 平台会自动检测 `package.json` 和 `Dockerfile`。 4. 确保启动命令为 `npm start`(默认已配置)。 ## 部署后如何请求接口 部署完成后(假设域名为 `https://your-app.vercel.app`),您的 MCP Endpoint 地址将是: `https://your-app.vercel.app/mcp` ### 1. 使用测试客户端 您可以使用本项目提供的测试客户端进行连接测试: ```bash # 格式:node dist/test-client.js http <YOUR_DEPLOYED_URL> node dist/test-client.js http https://your-app.vercel.app/mcp ``` ### 2. 集成到 Claude Desktop / Trae 如果您的客户端支持 SSE 连接,配置如下: ```json { "mcpServers": { "math-server": { "command": "node", "args": ["path/to/dist/index.js", "http"], "env": { "PORT": "3000" } } } } ``` *注意:目前大多数 MCP 客户端(如 Claude Desktop)主要支持 Stdio 模式,对 HTTP/SSE 的支持可能需要特定的配置或适配器。* ## 工具 (Tools) 服务器提供一个名为 `calculate` 的工具,包含以下参数: - `operation`:操作类型,可选 "add"(加), "subtract"(减), "multiply"(乘), "divide"(除) - `a`:第一个数字 - `b`:第二个数字 ## 测试 项目中包含一个测试客户端,用于验证两种模式。 测试 HTTP 模式(请先确保服务器已启动): ```bash # 终端 1:启动服务器 node dist/index.js http # 终端 2:运行客户端 node dist/test-client.js http ``` 测试 Stdio 模式: ```bash node dist/test-client.js stdio ```

Latest Blog Posts

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/wxt2rr/mcp-server-test'

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