Skip to main content
Glama

实用工具 MCP 服务器

一个功能齐全的模型上下文协议 (MCP) 服务器,提供实用工具、资源和提示词。使用 TypeScript 和现代 MCP SDK 构建。

📁 项目结构

项目结构旨在实现可扩展性和可读性:

.
├── index.ts              # Entry point: Initializes server and registers modules
├── src/
│   ├── tools.ts          # Tool handlers (Arithmetic, Randomness, Sampling)
│   ├── prompts.ts        # Prompt templates (Math Tutoring)
│   └── resources.ts      # Resource definitions (System Status)
├── tests/
│   └── utility.test.ts   # Comprehensive unit tests
├── package.json          # Dependencies and scripts
├── tsconfig.json         # TypeScript configuration
└── jest.config.js        # Testing configuration

Related MCP server: MCP Server TypeScript

🚀 功能

1. 工具

  • random_number:在指定范围内生成一个随机整数。

  • calculator:执行基本算术运算(add 加、subtract 减、multiply 乘、divide 除)。

  • suggest_arithmetic_task:演示 LLM 采样,通过请求客户端/LLM 生成一个创造性的数学问题。

2. 资源

  • system_status (utility://system/status):提供服务器健康状况和功能数量的实时状态更新。

3. 提示词

  • math_tutor:一个引导 LLM 扮演数学老师角色的模板,可选择专注于特定主题。


📡 调用 API (Postman / JSON-RPC)

模型上下文协议使用 JSON-RPC 2.0。虽然此服务器目前通过 stdio(标准输入/输出)运行,但如果您通过 HTTP/SSE 网桥公开它或使用调试器,则可以使用这些消息格式与它进行交互。

🛠 工具

列出工具

请求:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/list"
}

调用 calculator

请求:

{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "tools/call",
  "params": {
    "name": "calculator",
    "arguments": {
      "operation": "multiply",
      "a": 5,
      "b": 10
    }
  }
}

📖 资源

列出资源

请求:

{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "resources/list"
}

读取 system_status

请求:

{
  "jsonrpc": "2.0",
  "id": 4,
  "method": "resources/read",
  "params": {
    "uri": "utility://system/status"
  }
}

📝 提示词

列出提示词

请求:

{
  "jsonrpc": "2.0",
  "id": 5,
  "method": "prompts/list"
}

获取 math_tutor 提示词

请求:

{
  "jsonrpc": "2.0",
  "id": 6,
  "method": "prompts/get",
  "params": {
    "name": "math_tutor",
    "arguments": {
      "topic": "algebra"
    }
  }
}

🛠 开发

设置

npm install

运行服务器

npm start

运行测试

npm test

🤖 使用自定义客户端

我们包含了一个内置的客户端示例,以便您了解如何以编程方式进行连接:

npm run client

此脚本将:

  1. 将服务器作为子进程启动。

  2. 通过 Stdio 连接。

  3. 自动演示列出工具、调用计算器和读取资源。

🔍 使用 MCP Inspector 进行测试

要以可视化方式与服务器交互:

npx @modelcontextprotocol/inspector npx tsx index.ts

[!IMPORTANT] 此服务器使用 Stdio 传输。它通过 stdin 和 stdout 进行通信。若要使 Postman 通过 HTTP 工作,需要在服务器配置中添加 SSE(服务器发送事件)传输层。

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    A TypeScript MCP server implementation using Express.js that provides basic tools like echo, time retrieval, and calculator functionality. Features session management, RESTful API endpoints, and Server-Sent Events for streamable communication.
    -
  • -
    license
    Not graded
    quality
    Not graded
    maintenance
    A production-ready TypeScript MCP server providing basic tools (add, echo, timestamp), resources (server info, greetings, data access), and prompt templates (analyze, code-review, summarize). Serves as a foundation for building custom MCP servers with extensible architecture.
    284 npm
    -
  • A
    license
    Not graded
    quality
    D
    maintenance
    A lightweight TypeScript-based MCP server that demonstrates how to build custom MCP tools by implementing a simple addition calculator. Serves as a starting point for building MCP-compatible tools.
    2,859 npm
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    A calculator-focused MCP server with TypeScript and Zod validation, providing tools, resources, and prompts for basic arithmetic operations.
    -