feishu-mcp
Version:
Model Context Protocol server for Feishu integration
68 lines (67 loc) • 2.09 kB
JavaScript
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { FeishuApiService } from '../services/feishuApiService.js';
import { Logger } from '../utils/logger.js';
import { registerFeishuTools } from './tools/feishuTools.js';
import { registerFeishuBlockTools } from './tools/feishuBlockTools.js';
import { registerFeishuFolderTools } from './tools/feishuFolderTools.js';
const serverInfo = {
name: "Feishu MCP Server",
version: "0.0.9",
};
const serverOptions = {
capabilities: { logging: {}, tools: {} },
};
/**
* 飞书MCP服务类
* 继承自McpServer,提供飞书工具注册和初始化功能
*/
export class FeishuMcp extends McpServer {
/**
* 构造函数
*/
constructor() {
super(serverInfo, serverOptions);
Object.defineProperty(this, "feishuService", {
enumerable: true,
configurable: true,
writable: true,
value: null
});
// 初始化飞书服务
this.initFeishuService();
// 注册所有工具
if (this.feishuService) {
this.registerAllTools();
}
else {
Logger.error('无法注册飞书工具: 飞书服务初始化失败');
throw new Error('飞书服务初始化失败');
}
}
/**
* 初始化飞书API服务
*/
initFeishuService() {
try {
// 使用单例模式获取飞书服务实例
this.feishuService = FeishuApiService.getInstance();
Logger.info('飞书服务初始化成功');
}
catch (error) {
Logger.error('飞书服务初始化失败:', error);
this.feishuService = null;
}
}
/**
* 注册所有飞书MCP工具
*/
registerAllTools() {
if (!this.feishuService) {
return;
}
// 注册所有工具
registerFeishuTools(this, this.feishuService);
registerFeishuBlockTools(this, this.feishuService);
registerFeishuFolderTools(this, this.feishuService);
}
}