mcpField
T
TypeScript MCP Demo Server

TypeScript MCP Demo Server

本地服务
github.com/gedankrayze开发工具074 周前更新

关于 TypeScript MCP Demo Server

TypeScript MCP Demo Server 是使用 Bun 构建的 TypeScript MCP 服务示例,面向学习或原型开发者,提供问候和加法工具及 stdio 传输。

主要功能

  1. 01Bun 运行时
  2. 02stdio 传输
  3. 03具备类型安全的 TypeScript 实现
  4. 04示例 greet 和 add_numbers 工具
  5. 05使用 MCP Inspector 调试

适用场景

  1. 01学习 MCP 服务初始化
  2. 02原型开发 TypeScript 工具
  3. 03通过 MCP Inspector 测试服务能力

MCP 相关

该项目实现了基于 stdio 的 MCP 服务,并注册供客户端调用的工具。示例工具可问候指定用户并计算两个数之和。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

暂未收录安装方式

我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。

代码仓库

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

TypeScript MCP 演示服务

一个使用 TypeScript SDK 和 Bun 运行时实现的基础 Model Context Protocol(MCP)服务。

概述

本项目演示了如何使用 TypeScript 构建 MCP 服务,包含:

  • 使用 stdio 传输方式初始化服务
  • 注册和处理工具
  • TypeScript 类型安全
  • 使用 Bun 运行时实现快速执行

前提条件

  • Bun(最新版本)
  • Task(可选,用作任务运行器)

安装

# Clone the repository
git clone https://github.com/gedankrayze/ts-demo-mcp.git
cd ts-demo-mcp

# Install dependencies
bun install

项目结构

ts-demo-mcp/
├── src/
│   └── index.ts        # Main MCP server implementation
├── package.json        # Project dependencies and scripts
├── tsconfig.json       # TypeScript configuration
├── Taskfile.yaml       # Task runner configuration
└── README.md          # This file

可用工具

该服务实现了两个示例工具:

1. greet

用用户的名字向其问候。

输入架构:

{
  "name": "string"  // Required: The name of the person to greet
}

示例响应:

Hello, John! Welcome to the TypeScript MCP demo server.
2. add_numbers

将两个数字相加。

输入架构:

{
  "a": "number",  // Required: The first number
  "b": "number"   // Required: The second number
}

示例响应:

The sum of 5 and 3 is 8.

用法

使用 npm/bun 脚本
# Start the MCP server
bun start

# Run TypeScript type checking
bun typecheck
使用 Task 任务运行器
# Start the MCP server
task start

# Inspect server capabilities with MCP inspector
task inspect-server

# Send a raw initialization request
task inspect

与 Claude Desktop 集成

如需在 Claude Desktop 中使用此服务,请将以下内容添加到 Claude Desktop 配置中:

{
  "mcpServers": {
    "ts-demo-mcp": {
      "command": "bun",
      "args": ["run", "/path/to/ts-demo-mcp/src/index.ts"]
    }
  }
}

开发

添加新工具

如需向服务添加新工具:

  1. 在 ListToolsRequestSchema 处理程序中更新工具列表
  2. 在 CallToolRequestSchema 处理程序中添加工具实现

示例:

// In ListToolsRequestSchema handler
{
  name: "my_tool",
  description: "Description of what the tool does",
  inputSchema: {
    type: "object",
    properties: {
      param1: { type: "string", description: "Parameter description" }
    },
    required: ["param1"]
  }
}

// In CallToolRequestSchema handler
case "my_tool": {
  const param1 = request.params.arguments?.param1 as string;
  return {
    content: [{
      type: "text",
      text: `Tool output for ${param1}`
    }]
  };
}
类型检查

本项目使用启用了严格模式的 TypeScript。运行以下命令进行类型检查:

bun typecheck

MCP Inspector

本项目包含用于调试的 MCP inspector。使用它来探索服务功能:

task inspect-server

这将启动一个交互式 Web 界面,用于测试你的 MCP 服务。

许可证

本项目为公开项目,地址为 https://github.com/gedankrayze/ts-demo-mcp。

资源

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。