vm_query
Evaluate PromQL expressions to retrieve current time series data using a specified timestamp with VictoriaMetrics-mcp-server.
Instructions
Query current value of a time series
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | PromQL expression to evaluate | |
| time | No | Evaluation timestamp in Unix seconds (optional) |
Implementation Reference
- src/index.js:352-355 (handler)Handler case in the callTool request handler that extracts arguments and delegates to vmDataQuery for executing the vm_query tool.case "vm_query": { const {query, start, end, step} = request.params.arguments; return await vmDataQuery(query, start, end, step); }
- src/index.js:82-99 (schema)Tool definition including name, description, and input schema for the vm_query tool.const VM_QUERY_TOOL = { name: "vm_query", description: "Query current value of a time series", inputSchema: { type: "object", properties: { query: { type: "string", description: "PromQL expression to evaluate", }, time: { type: "number", description: "Evaluation timestamp in Unix seconds (optional)", } }, required: ["query"], } };
- src/index.js:127-134 (registration)Registration of vm_query tool (VM_QUERY_TOOL) in the VM_TOOLS array, which is returned by the listTools handler.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:136-163 (helper)Helper function that performs the actual API call to VictoriaMetrics /api/v1/query endpoint with the PromQL query and returns the result or error.async function vmDataQuery(query, step) { let urlStr = VM_URL if (urlStr === "") { urlStr = VM_SELECT_URL } const url = new URL(urlStr + "/api/v1/query"); url.searchParams.append("query", query); 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 }; } }