Prometheus MCP Server - Direct Prometheus integration for AI agents via Model Context Protocol
This MCP server enables AI agents to query Prometheus metrics data through natural language, providing tools to execute PromQL queries, explore metric...
25PrometheusUsername: os.Getenv("PROMETHEUS_USERNAME"),
26PrometheusPassword: os.Getenv("PROMETHEUS_PASSWORD"),// Exploitable if attacker has local access to the server process (e.g., via compromised LLM or container escape).
24PrometheusURL: os.Getenv("PROMETHEUS_URL"),// Exploitable if attacker can control environment variables (e.g., via compromised LLM with env access or container escape).
15query, ok := params.Arguments["query"].(string)
16if !ok || query == "" {
17 return mcp.CallToolResult{}, fmt.Errorf("query parameter is required")
18}// Exploitable by any user of the MCP server, especially if exposed to untrusted prompts.
165matchParam, ok := params.Arguments["match"]
166if !ok {
167 return mcp.CallToolResult{}, fmt.Errorf("match parameter is required")
168}
169var match []string
170switch v := matchParam.(type) {
171case []interface{}:
172 for _, item := range v {
173 if str, ok := item.(string); ok {
174 match = append(match, str)
175 }
176 }
177case []string:
178 match = v
179case string:
180 match = []string{v}
181default:
182 return mcp.CallToolResult{}, fmt.Errorf("match parameter must be a string or array of strings")
183}// Exploitable by any user of the MCP server.
63step := "15s"
64if stepStr, ok := params.Arguments["step"].(string); ok && stepStr != "" {
65 step = stepStr
66}// Exploitable by any user of the MCP server.
53if startStr, ok := params.Arguments["start_time"].(string); ok && startStr != "" {
54 startTime = ParseTime(startStr, startTime)
55}
56if endStr, ok := params.Arguments["end_time"].(string); ok && endStr != "" {
57 endTime = ParseTime(endStr, endTime)
58}// Exploitable by any user of the MCP server.
155async sendMCPRequest(method, params = null) {
156 const request = {
157 jsonrpc: '2.0',
158 method: method,
159 id: this.requestId++
160 };
161 if (params) {
162 request.params = params;
163 }
164 const response = await fetch(`${this.mcpServerUrl}/mcp`, {
165 method: 'POST',
166 headers: {
167 'Content-Type': 'application/json',
168 'Mcp-Session-Id': this.sessionId || ''
169 },
170 body: JSON.stringify(request)
171 });
172 if (!response.ok) {
173 throw new Error(`HTTP ${response.status}: ${response.statusText}`);
174 }
175 const data = await response.json();
176 if (data.error) {
177 throw new Error(data.error.message || 'Unknown error');
178 }
179 return data.result;
180}// Network-exposed MCP server allows anyone to access the web UI and execute queries.
86w.Header().Set("Access-Control-Allow-Origin", "*")
87w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
88w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Mcp-Session-Id")// Network-exposed MCP server allows cross-origin requests from any website.
282upgrader := websocket.Upgrader{
283 CheckOrigin: func(r *http.Request) bool {
284 return true // Allow all origins for now
285 },
286}// Network-exposed MCP server allows cross-origin WebSocket connections.