MCP REST实用程序
用于构建模型上下文协议(MCP)服务器的共享REST API实用程序。
特性
- RestClient:具有自动重试、超时处理和错误管理功能的HTTP客户端
- RestToolFactory:创建和执行MCP工具的工厂模式
- 类型安全配置:REST工具定义的TypeScript接口
- 错误处理:跨所有服务器的统一错误处理
安装
来自GitHub
npm install git+https://github.com/munch-group/mcp-rest-utils.git来源
git clone https://github.com/munch-group/mcp-rest-utils.git
cd mcp-rest-utils
npm install
npm run build用法
import { RestClient, RestToolFactory } from "@mcp/rest-utils";
// Create a REST client
const client = new RestClient({
baseUrl: "https://api.example.com",
defaultHeaders: { "Content-Type": "application/json" },
timeout: 30000,
retries: 3,
});
// Define tools
const tools = [{
name: "get_data",
description: "Get data from API",
method: "GET",
endpoint: (args) => `/data/${args.id}`,
inputSchema: { /* ... */ },
}];
// Create tool factory and execute
const factory = new RestToolFactory(client);
const result = await factory.executeTool(tools[0], { id: "123" });建筑
npm run build许可证
国际学生委员会
