Skip to main content
Glama
idoru

InfluxDB MCP Server

by idoru

query-data

Execute Flux queries against InfluxDB to inspect measurement schemas, run aggregations, or validate recently written data within an organization.

Instructions

Execute a Flux query inside an organization to inspect measurement schemas, run aggregations, or validate recently written data.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
orgYesOrganization whose buckets the query should target (exact name, not ID).
queryYesFlux query text. Multi-line strings are supported; results are returned as annotated CSV for easy parsing.

Implementation Reference

  • The handler function that executes the tool logic. It takes { org, query }, makes a POST request to InfluxDB's /api/v2/query endpoint with a Flux query, and returns the response text (annotated CSV) as content.
    export async function queryData({ org, query }) {
      try {
        const response = await influxRequest(
          `/api/v2/query?org=${encodeURIComponent(org)}`,
          {
            method: "POST",
            body: JSON.stringify({ query, type: "flux" }),
          },
        );
    
        const responseText = await response.text();
    
        return {
          content: [{
            type: "text",
            text: responseText,
          }],
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Error executing query: ${error.message}`,
          }],
          isError: true,
        };
      }
    }
  • src/index.js:103-119 (registration)
    Registration of the 'query-data' tool via server.tool(). Defines the tool name, description, input schema (org and query strings), and binds the queryData handler.
    server.tool(
      "query-data",
      "Execute a Flux query inside an organization to inspect measurement schemas, run aggregations, or validate recently written data.",
      {
        org: z
          .string()
          .describe(
            "Organization whose buckets the query should target (exact name, not ID).",
          ),
        query: z
          .string()
          .describe(
            "Flux query text. Multi-line strings are supported; results are returned as annotated CSV for easy parsing.",
          ),
      },
      queryData,
    );
  • The influxRequest helper used by queryData to make authenticated HTTP requests to the InfluxDB API with timeout and error handling.
    export async function influxRequest(endpoint, options = {}, timeoutMs = 5000) {
      const url = `${INFLUXDB_URL}${endpoint}`;
      const defaultOptions = {
        headers: {
          Authorization: `Token ${INFLUXDB_TOKEN}`,
          "Content-Type": "application/json",
        },
      };
    
      console.log(`Making request to: ${url}`);
    
      try {
        // Use AbortController for proper request cancellation
        const controller = new AbortController();
        const timeoutId = setTimeout(() => {
          controller.abort(`InfluxDB API request timed out after ${timeoutMs}ms`);
        }, timeoutMs);
    
        // Properly merge headers to avoid conflicts
        // This ensures custom headers (like Content-Type) aren't overridden
        const mergedHeaders = {
          ...defaultOptions.headers,
          ...options.headers || {},
        };
    
        // Add the abort signal to the request options
        const requestOptions = {
          ...defaultOptions,
          ...options,
          headers: mergedHeaders,
          signal: controller.signal,
        };
    
        console.log(`Request options: ${JSON.stringify({
          method: requestOptions.method,
          headers: Object.keys(requestOptions.headers),
        })
          }`);
    
        // Make the request
        const response = await fetch(url, requestOptions);
    
        // Clear the timeout since the request completed
        clearTimeout(timeoutId);
    
        console.log(`Response status: ${response.status}`);
    
        if (!response.ok) {
          const errorText = await Promise.race([
            response.text(),
            new Promise((_, reject) =>
              setTimeout(() => reject(new Error("Response text timeout")), 3000)
            ),
          ]);
          throw new Error(`InfluxDB API Error (${response.status}): ${errorText}`);
        }
    
        return response;
      } catch (error) {
        // Log the error with more details
        console.error(`Error in influxRequest to ${url}:`, error.message);
        // Rethrow to be handled by the caller
        throw error;
      }
    }
  • Input schema for the 'query-data' tool: 'org' (string) and 'query' (string) parameters, validated with Zod.
      org: z
        .string()
        .describe(
          "Organization whose buckets the query should target (exact name, not ID).",
        ),
      query: z
        .string()
        .describe(
          "Flux query text. Multi-line strings are supported; results are returned as annotated CSV for easy parsing.",
        ),
    },
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Since no annotations are provided, the description must convey behavior. It indicates a read operation (query) but does not mention permissions, rate limits, or output format (though schema mentions CSV). The description adds moderate behavioral context but lacks depth.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, reasonably concise sentence that conveys the core purpose. It could be slightly tighter, but no unnecessary words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple query tool with two parameters and no output schema, the description covers purpose and usage scenarios. It omits potential guidance on query performance, timeouts, or security, making it adequate but not comprehensive.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% with clear descriptions for both parameters. The description adds no new parameter-specific meaning beyond the use cases. Baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description clearly states the verb 'execute' and the resource 'Flux query inside an organization', with specific example use cases (inspect schemas, run aggregations, validate data). It effectively distinguishes from sibling tools that create or write.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides context by listing example scenarios (inspect schemas, run aggregations, validate data), which implies when to use. However, it does not explicitly contrast with siblings or state when not to use.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/idoru/influxdb-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server