UNPKG

@downzoo/mcp-server

Version:

AI协作档案分析器 - MCP服务器,基于 Model Context Protocol 的 AI 协作档案分析服务器,专门用于分析 Bug 修复相关的聊天内容

120 lines 3.62 kB
import fs from "fs/promises"; import path from "path"; import os from "os"; // 默认配置 const DEFAULT_AI_CONFIG = { provider: "deepseek", apiKey: process.env.DEEPSEEK_API_KEY, baseUrl: "https://api.deepseek.com/v1/chat/completions", model: "deepseek-chat", temperature: 0.7, maxTokens: 2000, }; const DEFAULT_ANALYSIS_CONFIG = { enableTechStack: true, enableBusiness: true, enableTags: true, enableAIThoughts: true, enableProblems: true, enableSummary: true, }; // 配置文件路径 const getConfigPath = () => { return path.join(os.homedir(), ".mcp", "ai-collaboration-analyzer.json"); }; // 加载配置 export const loadConfig = async () => { return { ai: DEFAULT_AI_CONFIG, analysis: DEFAULT_ANALYSIS_CONFIG, }; }; // 保存配置 export const saveConfig = async (config) => { try { const configPath = getConfigPath(); const configDir = path.dirname(configPath); // 确保配置目录存在 await fs.mkdir(configDir, { recursive: true }); // 保存配置 await fs.writeFile(configPath, JSON.stringify(config, null, 2), "utf-8"); console.log("配置已保存到:", configPath); } catch (error) { console.error("保存配置失败:", error); throw error; } }; // 获取AI提供商配置 export const getAIConfig = async () => { const config = await loadConfig(); return config.ai; }; // 获取分析配置 export const getAnalysisConfig = async () => { const config = await loadConfig(); return config.analysis; }; // 更新AI配置 export const updateAIConfig = async (aiConfig) => { const config = await loadConfig(); config.ai = { ...config.ai, ...aiConfig }; await saveConfig(config); }; // 重置配置为默认值 export const resetConfig = async () => { const config = { ai: DEFAULT_AI_CONFIG, analysis: DEFAULT_ANALYSIS_CONFIG, }; await saveConfig(config); }; // 验证配置 export const validateConfig = (config) => { const errors = []; // 验证AI配置 if (!config.ai.apiKey) { errors.push("AI API Key 不能为空"); } if (!config.ai.provider) { errors.push("AI 提供商不能为空"); } if (config.ai.temperature !== undefined && (config.ai.temperature < 0 || config.ai.temperature > 2)) { errors.push("Temperature 必须在 0-2 之间"); } if (config.ai.maxTokens !== undefined && config.ai.maxTokens < 1) { errors.push("Max Tokens 必须大于 0"); } return errors; }; // 获取配置示例 export const getConfigExample = () => { return { ai: { provider: "deepseek", apiKey: "your-api-key-here", baseUrl: "https://api.deepseek.com/v1/chat/completions", model: "deepseek-chat", temperature: 0.7, maxTokens: 2000, }, analysis: { enableTechStack: true, enableBusiness: true, enableTags: true, enableAIThoughts: true, enableProblems: true, enableSummary: true, customPrompts: { techStack: "自定义技术栈分析提示词", business: "自定义业务分析提示词", tags: "自定义标签分析提示词", aiThoughts: "自定义AI思考分析提示词", problems: "自定义问题分类提示词", summary: "自定义总结分析提示词", }, }, }; }; //# sourceMappingURL=config.js.map