Token导航 LogoToken导航TokenDH.com
Math Server Tejas logo
运维云端未说明官方级别未说明来源级核验

Math Server Tejas

MCP Server

一个基于HTTP传输的简单MCP服务器,提供基础数学运算功能,支持API密钥认证和跨域请求。

工具数

1

提示词数

0

GitHub Stars

0

资源数

0
数学运算API集成TypeScriptHTTP服务器API密钥

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

Tejasf12

提供方

Tejasf12

最后核验

2026/5/17 20:22

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

MCP数学服务器

一个简单的模型上下文协议(MCP)服务器,具有HTTP传输,提供基本的数学运算。该服务器演示如何使用Express.js、TypeScript和API密钥身份验证构建MCP服务器。

特性

  • ✅ HTTP传输(非stdio)
  • ✅ API通过Bearer令牌进行密钥认证
  • ✅ 单一数学工具: add_numbers
  • ✅ 具有正确类型定义的TypeScript
  • ✅ 为跨源请求启用CORS
  • ✅ 全面的错误处理
  • ✅ 请求/响应日志记录
  • ✅ 健康检查端点

先决条件

  • Node.js 18+和npm
  • 基本了解REST API和HTTP请求

快速开始

  1. 克隆存储库
   git clone 
   cd mcp-math-server
  1. 安装依赖项
   npm install
  1. 设置环境变量
   cp .env.example .env

编辑 .env 并设置您的API密钥:

   MCP_API_KEY=your-secret-api-key-here
   PORT=3000
  1. 构建项目
   npm run build
  1. 启动服务器
   npm start

服务器将在以下时间可用 http://localhost:3000

发展

对于在文件更改时自动重启的开发:

npm run dev

API终点

健康检查

GET /health

返回服务器状态(不需要身份验证)。

答复:

{
  "status": "healthy",
  "timestamp": "2024-01-01T00:00:00.000Z"
}

列出可用工具

GET /mcp/tools
Authorization: Bearer 

答复:

{
  "tools": [
    {
      "name": "add_numbers",
      "description": "Add two numbers together",
      "inputSchema": {
        "type": "object",
        "properties": {
          "a": {
            "type": "number",
            "description": "First number to add"
          },
          "b": {
            "type": "number",
            "description": "Second number to add"
          }
        },
        "required": ["a", "b"]
      }
    }
  ]
}

执行工具

POST /mcp/tools/call
Authorization: Bearer 
Content-Type: application/json

请求正文:

{
  "name": "add_numbers",
  "arguments": {
    "a": 5,
    "b": 3
  }
}

答复:

{
  "content": [
    {
      "type": "text",
      "text": "{\"result\": 8}"
    }
  ]
}

认证

所有MCP端点(除 /health)需要使用Bearer令牌进行身份验证:

Authorization: Bearer your-secret-api-key-here

如果身份验证失败,服务器将返回:

{
  "error": "Missing or invalid Authorization header"
}

可用工具

add_numbers

将两个数字相加并返回结果。

参数:

  • a (数字,必填):要添加的第一个数字
  • b (数字,必填):要添加的第二个数字

示例用法:

curl -X POST http://localhost:3000/mcp/tools/call \
  -H "Authorization: Bearer your-secret-api-key-here" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "add_numbers",
    "arguments": {
      "a": 10,
      "b": 20
    }
  }'

答复:

{
  "content": [
    {
      "type": "text",
      "text": "{\"result\": 30}"
    }
  ]
}

错误处理

服务器提供全面的错误处理:

  • 400错误请求:缺少必需的参数
  • 401未经授权:API密钥无效或丢失
  • 404未找到:未知端点
  • 500内部服务器错误:服务器错误

项目结构

mcp-math-server/
├── package.json          # Dependencies and scripts
├── tsconfig.json         # TypeScript configuration
├── .env.example          # Environment variables template
├── .gitignore            # Git ignore rules
├── README.md             # This file
├── src/
│   ├── index.ts          # Main server file
│   └── tools/
│       └── math.ts       # Math tools implementation
└── dist/                 # Compiled JavaScript (generated)

脚本

  • npm run build -将TypeScript编译为JavaScript
  • npm start -启动已编译的服务器
  • npm run dev -使用自动重新加载启动开发服务器
  • npm run clean -删除已编译的文件

安全说明

  • 在生产过程中始终使用随机生成的强API密钥
  • API密钥应保密,不得用于版本控制
  • 在生产环境中使用HTTPS
  • 考虑对生产使用实施限速

测试服务器

您可以使用curl、Postman或任何HTTP客户端测试服务器:

# Health check (no auth required)
curl http://localhost:3000/health

# List tools
curl -H "Authorization: Bearer your-secret-api-key-here" \
     http://localhost:3000/mcp/tools

# Call add_numbers tool
curl -X POST http://localhost:3000/mcp/tools/call \
     -H "Authorization: Bearer your-secret-api-key-here" \
     -H "Content-Type: application/json" \
     -d '{"name": "add_numbers", "arguments": {"a": 15, "b": 25}}'

扩展服务器

要添加新工具,请执行以下操作:

  1. 在中创建新的工具定义 src/tools/ 或添加到 math.ts
  2. 在中注册该工具 ListToolsRequestSchema 处理器
  3. 在中添加工具处理程序 CallToolRequestSchema 处理器
  4. 重建并重新启动服务器

许可证

MIT许可证-有关详细信息,请参阅许可证文件。

贡献

  1. 分叉存储库
  2. 创建要素分支
  3. 进行更改
  4. 如果适用,添加测试
  5. 提交拉取请求

支持

如果您遇到任何问题或有疑问,请在GitHub存储库中打开问题。

目录标签

目录标签

数学运算API集成TypeScriptHTTP服务器API密钥本地部署API密钥认证RESTAPI

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

token

工具数量(toolCount,工具数)

1

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明token部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP