Skip to main content
Glama
idoru

InfluxDB MCP Server

by idoru

write-data

Write newline-delimited line protocol records into an InfluxDB bucket for time-series data ingestion with optional timestamp precision.

Instructions

Stream newline-delimited line protocol records into a bucket. Use this after composing measurements so the LLM can insert real telemetry, optionally controlling timestamp precision.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
orgYesHuman-readable organization name that owns the destination bucket (the same value returned by the orgs resource).
bucketYesBucket name to receive the points. Make sure it already exists or call create-bucket first.
dataYesPayload containing one or more line protocol lines (measurements, tags, fields, timestamps) separated by newlines.
precisionNoOptional timestamp precision. Provide it only when the line protocol omits unit suffix context; defaults to nanoseconds.

Implementation Reference

  • The handler function for the 'write-data' tool. Accepts org, bucket, data, and precision parameters. Makes a POST request to the InfluxDB /api/v2/write endpoint with the line protocol data as the body.
    export async function writeData({ org, bucket, data, precision }) {
      // Add extremely clear logging
      console.log(`=== WRITE-DATA TOOL CALLED ===`);
      console.log(
        `Writing to org: ${org}, bucket: ${bucket}, data length: ${data.length}`,
      );
    
      try {
        // Simplified approach focusing on core functionality
        let endpoint = `/api/v2/write?org=${encodeURIComponent(org)}&bucket=${encodeURIComponent(bucket)
          }`;
        if (precision) {
          endpoint += `&precision=${precision}`;
        }
    
        console.log(`Write URL: ${INFLUXDB_URL}${endpoint}`);
    
        // Use fetch directly instead of our wrapper to eliminate any potential issues
        const response = await fetch(`${INFLUXDB_URL}${endpoint}`, {
          method: "POST",
          headers: {
            "Content-Type": "text/plain; charset=utf-8",
            "Authorization": `Token ${INFLUXDB_TOKEN}`,
          },
          body: data,
        });
    
        console.log(`Write response status: ${response.status}`);
    
        if (!response.ok) {
          const errorText = await response.text();
          throw new Error(
            `Failed to write data: ${response.status} ${errorText}`,
          );
        }
    
        console.log(`=== WRITE-DATA TOOL COMPLETED SUCCESSFULLY ===`);
        return {
          content: [{
            type: "text",
            text: "Data written successfully",
          }],
        };
      } catch (error) {
        console.error(`=== WRITE-DATA TOOL ERROR: ${error.message} ===`);
        return {
          content: [{
            type: "text",
            text: `Error writing data: ${error.message}`,
          }],
          isError: true,
        };
      }
    }
  • Zod schema definitions for the 'write-data' tool parameters: org (string), bucket (string), data (string), and precision (optional enum: ns, us, ms, s).
    {
      org: z
        .string()
        .describe(
          "Human-readable organization name that owns the destination bucket (the same value returned by the orgs resource).",
        ),
      bucket: z
        .string()
        .describe(
          "Bucket name to receive the points. Make sure it already exists or call create-bucket first.",
        ),
      data: z
        .string()
        .describe(
          "Payload containing one or more line protocol lines (measurements, tags, fields, timestamps) separated by newlines.",
        ),
      precision: z
        .enum(["ns", "us", "ms", "s"])
        .optional()
        .describe(
          "Optional timestamp precision. Provide it only when the line protocol omits unit suffix context; defaults to nanoseconds.",
        ),
    },
  • src/index.js:74-102 (registration)
    Registration of the 'write-data' tool with the MCP server using server.tool(), including its description, schema, and mapping to the writeData handler.
    // Register tools
    server.tool(
      "write-data",
      "Stream newline-delimited line protocol records into a bucket. Use this after composing measurements so the LLM can insert real telemetry, optionally controlling timestamp precision.",
      {
        org: z
          .string()
          .describe(
            "Human-readable organization name that owns the destination bucket (the same value returned by the orgs resource).",
          ),
        bucket: z
          .string()
          .describe(
            "Bucket name to receive the points. Make sure it already exists or call create-bucket first.",
          ),
        data: z
          .string()
          .describe(
            "Payload containing one or more line protocol lines (measurements, tags, fields, timestamps) separated by newlines.",
          ),
        precision: z
          .enum(["ns", "us", "ms", "s"])
          .optional()
          .describe(
            "Optional timestamp precision. Provide it only when the line protocol omits unit suffix context; defaults to nanoseconds.",
          ),
      },
      writeData,
    );
  • Imports: 'fetch' from node-fetch for HTTP calls, and INFLUXDB_TOKEN/INFLUXDB_URL from the environment config.
    import fetch from "node-fetch";
    import { INFLUXDB_TOKEN, INFLUXDB_URL } from "../config/env.js";
Behavior2/5

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

With no annotations provided, the description carries full responsibility for behavioral disclosure. It only mentions streaming and insertion, but does not explain whether the operation is append-only or destructive, what happens to existing data, required permissions, rate limits, or error conditions. For a write tool, these omissions are significant.

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

Conciseness5/5

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

The description consists of two concise sentences. It immediately states the core action and then adds the use case and optional control. No redundant or unnecessary words.

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

Completeness2/5

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

Given the lack of annotations and output schema, the description should cover more contextual details. It does not describe the return value (e.g., success indicator, count of points written), error handling, or prerequisites like bucket existence (though hinted in schema). The tool's complexity is moderate, but the description omits essential information for an agent to use it correctly.

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?

All four parameters have descriptions in the input schema (100% coverage). The tool description adds minimal new meaning beyond the schema, only noting that precision is optional and controls timestamp precision. The schema already provides adequate descriptions for org, bucket, data, and precision. 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?

The description clearly states the action: streaming line protocol records into a bucket. It specifies the format (newline-delimited) and the use case (after composing measurements for telemetry insertion). It distinguishes well from sibling tools like create-bucket (bucket creation) and query-data (reading data).

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: 'Use this after composing measurements so the LLM can insert real telemetry'. This implies the tool is for writing data after preparation. It does not explicitly state when not to use it or mention alternatives, but the sibling tools are clearly different in purpose. The schema parameter description for 'bucket' hints at a prerequisite (bucket must exist), but the main description lacks explicit exclusions.

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