FAIM MCP服务器
](https://www.npmjs.com/package/@faim-group/mcp) 
模型上下文协议(MCP)服务器,将FAIM时间序列预测SDK与任何兼容MCP的AI助手集成在一起,实现了AI驱动的预测功能。
NPM包: @faim集团/mcp
概述
该MCP服务器目前公开了来自FAIM API的两个基础时间序列模型,用于零样本预测:
- 计时器2
- TiRex
主要特点
✅ 两个MCP工具:
list_models:返回可用的预测模型和功能forecast:执行点和概率时间序列预测
✅ 灵活的输入格式:
- 1D数组:单变量时间序列
- 三维阵列:批处理/序列/特征格式
✅ 概率预测:
- 点预测(单值预测)
- 分位数预测(置信区间)
- 样本预测(分布样本)
- 用于风险评估的自定义分位数
安装
先决条件
- Node.js 20+
- npm 10+
- FAIM API密钥:注册地址 https://faim.it.com/ 得到你的
FAIM_API_KEY
远程MCP服务器——适用于n8n等工作流自动化工具
MCP服务器是远程部署的。
要使用远程MCP服务器,请向以下端点发送请求:
https://mcp.faim.it.com
使用提供您的FAIM API密钥 承载身份验证.
本地MCP服务器
选项1:从npm安装(推荐)
配置您的客户端以直接与 npx:
{
"mcpServers": {
"faim": {
"command": "npx",
"args": ["-y", "@faim-group/mcp"],
"env": {
"FAIM_API_KEY": "your-api-key-here"
}
}
}
}无需安装- npx 将自动下载并运行最新版本。
或者,如果您希望先全局安装:
npm install -g @faim-group/mcp然后在config中:
{
"mcpServers": {
"faim": {
"command": "faim-mcp",
"env": {
"FAIM_API_KEY": "your-api-key-here"
}
}
}
}选项2:在本地克隆和构建
# Clone the repository
git clone
cd faim-mcp
# Install dependencies
npm install
# Build the project
npm run build
# Run tests
npm test
# Run type checker
npm run lint然后使用本地路径:
{
"mcpServers": {
"faim": {
"command": "node",
"args": ["/path/to/faim-mcp/dist/index.js"],
"env": {
"FAIM_API_KEY": "your-api-key-here"
}
}
}
}示例
n8n工作流-需求预测
需求预测的n8n工作流示例可在 examples/n8n/demand_forecasting.json此工作流程演示了如何将FAIM MCP服务器与n8n集成,以执行自动需求预测任务。
使用此示例:
- 打开n8n
- 从导入工作流
n8n_examples/demand_forecasting.json - 在MCP连接设置中配置您的FAIM API密钥
- 使用时间序列数据执行工作流
配置
环境变量
# Required: Your FAIM API key
export FAIM_API_KEY="your-api-key-here"
# Optional: Set to non-production for verbose logging
export NODE_ENV=developmentMCP兼容性
此服务器实现 模型上下文协议(MCP),一种将人工智能助手连接到外部工具和数据源的开放协议。它适用于任何实现MCP客户端的LLM和应用程序。
与任何LLM或系统一起使用
此服务器实现标准MCP协议,并与实现MCP客户端的任何应用程序一起工作:
- 直接MCP客户端实施
- 支持MCP的AI框架适配器
- 将MCP工具暴露给任何LLM的IDE扩展
- 在MCP和LLM的工具调用格式之间进行转换的自定义中间件
用法
启动服务器
# Build and start the server
npm run build
node dist/index.js服务器将:
- 从环境中读取API密钥
- 初始化FAIM客户端
- 在stdin上监听JSON-RPC请求
- 将响应发送到stdout
工具1:列出模型
返回可用的预测模型及其功能。
请求:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {}
}答复:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"tools": [
{
"name": "list_models",
"description": "...",
"inputSchema": { ... }
},
{
"name": "forecast",
"description": "...",
"inputSchema": { ... }
}
]
}
}工具2:预测
使用FAIM模型进行时间序列预测。
请求(点数预测):
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "forecast",
"arguments": {
"model": "chronos2",
"x": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"horizon": 10,
"output_type": "point"
}
}
}请求(带置信区间的分位数预测):
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "forecast",
"arguments": {
"model": "chronos2",
"x": [[[100, 50], [102, 51], [105, 52]]],
"horizon": 5,
"output_type": "quantiles",
"quantiles": [0.1, 0.5, 0.9]
}
}
}答复:
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"success": true,
"data": {
"model_name": "chronos2",
"model_version": "1.0",
"output_type": "point",
"forecast": {
"point": [[[11], [12], [13], ...]]
},
"metadata": {
"token_count": 150,
"duration_ms": 245
},
"shape_info": {
"input_shape": [1, 10, 1],
"output_shape": [1, 10, 1]
}
}
}
}项目结构
faim-mcp/
├── src/
│ ├── index.ts # MCP server entry point
│ ├── types.ts # TypeScript interfaces
│ ├── tools/
│ │ ├── list-models.ts # List models tool
│ │ └── forecast.ts # Forecasting tool
│ └── utils/
│ ├── client.ts # FAIM client singleton
│ ├── validation.ts # Input validation
│ └── errors.ts # Error transformation
├── tests/
│ ├── tools/
│ │ ├── list-models.test.ts
│ │ └── forecast.test.ts
│ └── utils/
│ ├── validation.test.ts
│ └── errors.test.ts
├── dist/ # Built output
│ ├── index.js # ESM bundle
│ ├── index.cjs # CommonJS bundle
│ ├── index.d.ts # Type declarations
│ └── *.map # Source maps
└── package.json, tsconfig.json, tsup.config.ts, vitest.config.ts测试
该项目包括以下方面的综合测试:
- 输入验证:有效/无效输入、边缘情况、边界值
- 错误处理:SDK错误、JavaScript错误、错误分类
- 工具功能:响应结构、模型可用性
- 类型安全:TypeScript编译,类型保护
运行测试:
npm test # Run all tests
npm run test:coverage # Run with coverage report
npm run test:ui # Run with UI dashboard调试
启用详细日志记录:
NODE_ENV=development node dist/index.js输出进入stderr(不干扰stdout JSON-RPC)。
构建和部署
为生产而建
npm run build输出:
dist/index.js-ESM模块dist/index.cjs-CommonJS模块dist/index.d.ts-类型声明- 用于调试的源映射
部署检查表
- \[\]设置
FAIM_API_KEY环境变量 - \[\]运行
npm run build - \[\]运行
npm test验证 - \[\]部署
dist/目录 - \[\]运行
node dist/index.js作为服务器进程
故障排除
“FAIM_API_KEY未设置”
export FAIM_API_KEY="your-key-here"
node dist/index.js“找不到模块”错误
npm install
npm run build服务器未响应
- 检查stdout/stderr是否正确连接
- 验证请求的JSON-RPC格式
- 检查日志中的错误消息
- 确保可访问FAIM API
许可证
麻省理工学院
