关于 TypeScript MCP Demo Server
TypeScript MCP Demo Server 是使用 Bun 构建的 TypeScript MCP 服务示例,面向学习或原型开发者,提供问候和加法工具及 stdio 传输。
主要功能
- 01Bun 运行时
- 02stdio 传输
- 03具备类型安全的 TypeScript 实现
- 04示例 greet 和 add_numbers 工具
- 05使用 MCP Inspector 调试
适用场景
- 01学习 MCP 服务初始化
- 02原型开发 TypeScript 工具
- 03通过 MCP Inspector 测试服务能力
MCP 相关
该项目实现了基于 stdio 的 MCP 服务,并注册供客户端调用的工具。示例工具可问候指定用户并计算两个数之和。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
暂未收录安装方式
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
还没有获取到工具列表
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
TypeScript MCP 演示服务
一个使用 TypeScript SDK 和 Bun 运行时实现的基础 Model Context Protocol(MCP)服务。
概述
本项目演示了如何使用 TypeScript 构建 MCP 服务,包含:
- 使用 stdio 传输方式初始化服务
- 注册和处理工具
- TypeScript 类型安全
- 使用 Bun 运行时实现快速执行
前提条件
安装
# 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"]
}
}
}
开发
添加新工具
如需向服务添加新工具:
- 在
ListToolsRequestSchema处理程序中更新工具列表 - 在
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
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。