UNPKG

grafana-mcp-analyzer

Version:

让AI助手直接分析你的Grafana监控数据 - A Model Context Protocol server for Grafana data analysis

41 lines (30 loc) 2.77 kB
#!/usr/bin/env node import{StdioServerTransport as s}from"@modelcontextprotocol/sdk/server/stdio.js";import i from"fs";import o from"path";import{fileURLToPath as t}from"url";import{createMcpServer as c}from"./server/mcp-server.js";import{loadConfig as l,initializeCacheCleanup as p}from"./services/config-manager.js";import{initializeDataCleanup as m}from"./services/data-store.js";const f=t(import.meta.url),g=o.dirname(f),h=o.resolve(g,"../package.json"),a=JSON.parse(i.readFileSync(h,"utf-8"));function u(){const e=process.argv.slice(2),r=(process.env.LANG||process.env.LANGUAGE||process.env.LC_ALL||"en").toLowerCase().includes("zh");return e.includes("-v")||e.includes("--version")?(console.log(`grafana-mcp-analyzer v${a.version}`),!1):e.includes("-h")||e.includes("--help")||e.includes("-help")?(console.log(r?` grafana-mcp-analyzer v${a.version} \u7528\u6CD5: grafana-mcp-analyzer [\u9009\u9879] \u9009\u9879: -v, --version \u663E\u793A\u7248\u672C\u4FE1\u606F -h, --help \u663E\u793A\u5E2E\u52A9\u4FE1\u606F \u73AF\u5883\u53D8\u91CF: CONFIG_PATH \u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84\uFF08\u672C\u5730\u8DEF\u5F84\u6216HTTPS URL\uFF09 CONFIG_MAX_AGE \u8FDC\u7A0B\u914D\u7F6E\u7F13\u5B58\u65F6\u95F4\uFF08\u79D2\uFF0C\u9ED8\u8BA4300\uFF09 DATA_EXPIRY_HOURS \u6570\u636E\u8FC7\u671F\u65F6\u95F4\uFF08\u5C0F\u65F6\uFF0C\u9ED8\u8BA424\uFF09 \u793A\u4F8B: CONFIG_PATH=/Users/username/grafana-config.js grafana-mcp-analyzer \u66F4\u591A\u4FE1\u606F\u8BF7\u8BBF\u95EE: https://github.com/SailingCoder/grafana-mcp-analyzer `:` grafana-mcp-analyzer v${a.version} Usage: grafana-mcp-analyzer [options] Options: -v, --version Show version information -h, --help Show help information Environment Variables: CONFIG_PATH Configuration file path (local path or HTTPS URL) CONFIG_MAX_AGE Remote config cache time in seconds (default: 300) DATA_EXPIRY_HOURS Data expiration time in hours (default: 24) Example: CONFIG_PATH=/Users/username/grafana-config.js grafana-mcp-analyzer For more information, visit: https://github.com/SailingCoder/grafana-mcp-analyzer `),!1):!0}async function v(){if(u())try{p(),await m();const e=await l(process.env.CONFIG_PATH),n=c(a,e),r=new s;await n.connect(r),console.error("\u2705 Grafana\u67E5\u8BE2\u5206\u6790MCP\u670D\u52A1\u5668\u5DF2\u542F\u52A8"),console.error(`\u{1F4CA} \u670D\u52A1\u5668\u4FE1\u606F: grafana-mcp-analyzer v${a.version}`),console.error(`\u{1F527} \u914D\u7F6E\u72B6\u6001: ${Object.keys(e.queries||{}).length} \u4E2A\u67E5\u8BE2`)}catch(e){console.error("\u274C \u670D\u52A1\u5668\u542F\u52A8\u5931\u8D25:",e),process.exit(1)}}v().catch(e=>{console.error("\u274C \u672A\u5904\u7406\u7684\u9519\u8BEF:",e),process.exit(1)});