vm_query_range
Execute PromQL queries to retrieve time series data within a specified time range. Provide start, end timestamps, and step width to analyze metrics efficiently using VictoriaMetrics-mcp-server.
Instructions
Query time series over a time range
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| end | No | End timestamp in Unix seconds | |
| query | Yes | PromQL expression | |
| start | No | Start timestamp in Unix seconds | |
| step | No | Query resolution step width |
Implementation Reference
- src/index.js:165-195 (handler)The core handler function that executes the vm_query_range tool by calling the VictoriaMetrics /api/v1/query_range endpoint with the provided query, start, end, and step parameters.async function vmDataRangeQuery(query, start, end, step) { let urlStr = VM_URL if (urlStr === "") { urlStr = VM_SELECT_URL } const url = new URL(urlStr + "/api/v1/query_range"); url.searchParams.append("query", query); url.searchParams.append("start", start ?? ""); url.searchParams.append("end", end ?? ""); url.searchParams.append("step", step ?? ""); const response = await fetch(url.toString()); const data = await response.json(); if (data.status === "success") { return { content: [{ type: "text", text: JSON.stringify(data.data), }], isError: false }; } else { return { content: [{ type: "text", text: "range query fail:" + await response.text(), }], isError: true }; } }
- src/index.js:348-351 (handler)Dispatch handler in the CallToolRequestSchema switch statement that extracts arguments and calls the vmDataRangeQuery function for vm_query_range.case "vm_query_range": { const {query, start, end, step} = request.params.arguments; return await vmDataRangeQuery(query, start, end, step); }
- src/index.js:55-80 (schema)Schema definition for the vm_query_range tool, specifying input parameters and validation.const VM_QUERY_RANGE_TOOL = { name: "vm_query_range", description: "Query time series over a time range", inputSchema: { type: "object", properties: { query: { type: "string", description: "PromQL expression", }, start: { type: "number", description: "Start timestamp in Unix seconds", }, end: { type: "number", description: "End timestamp in Unix seconds", }, step: { type: "string", description: "Query resolution step width", } }, required: ["query"], } };
- src/index.js:127-134 (registration)Registration of the vm_query_range tool (as VM_QUERY_RANGE_TOOL) in the array of available tools.const VM_TOOLS = [ VM_DATA_WRITE_TOOL, VM_QUERY_RANGE_TOOL, VM_QUERY_TOOL, VM_LABELS_TOOL, VM_LABEL_VALUES_TOOL, VM_PROMETHEUS_WRITE_TOOL ];
- src/index.js:338-340 (registration)Registration handler for ListToolsRequestSchema that exposes the tools list including vm_query_range.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: VM_TOOLS, }));