create-bucket
Creates a new InfluxDB bucket under an organization, providing a destination for time-series data writes. Specify bucket name, organization ID, and optional retention period.
Instructions
Provision a new bucket under an organization so that subsequent write-data calls have a destination.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Friendly bucket name. Follow InfluxDB naming rules (alphanumeric, dashes, underscores). | |
| orgID | Yes | Organization ID (UUID) that will own the bucket. Retrieve it from the organizations resource or create-org output. | |
| retentionPeriodSeconds | No | Optional retention duration expressed in seconds. Omit for infinite retention. |
Implementation Reference
- src/handlers/createBucketTool.js:1-61 (handler)The main handler function `createBucket` that executes the create-bucket tool logic. It accepts name, orgID, and optional retentionPeriodSeconds, then makes a POST request to InfluxDB's /api/v2/buckets endpoint.
import fetch from "node-fetch"; import { INFLUXDB_TOKEN, INFLUXDB_URL } from "../config/env.js"; // Tool: Create Bucket export async function createBucket({ name, orgID, retentionPeriodSeconds }) { console.log(`=== CREATE-BUCKET TOOL CALLED ===`); console.log(`Creating bucket: ${name}, orgID: ${orgID}`); try { const bucketData = { name, orgID, retentionRules: retentionPeriodSeconds ? [ { type: "expire", everySeconds: retentionPeriodSeconds }, ] : undefined, }; console.log(`Creating bucket with data: ${JSON.stringify(bucketData)}`); // Use fetch directly instead of our wrapper const response = await fetch(`${INFLUXDB_URL}/api/v2/buckets`, { method: "POST", headers: { "Content-Type": "application/json", "Authorization": `Token ${INFLUXDB_TOKEN}`, }, body: JSON.stringify(bucketData), }); console.log(`Create bucket response status: ${response.status}`); if (!response.ok) { const errorText = await response.text(); throw new Error( `Failed to create bucket: ${response.status} ${errorText}`, ); } const bucketResponse = await response.json(); console.log(`=== CREATE-BUCKET TOOL COMPLETED SUCCESSFULLY ===`); return { content: [{ type: "text", text: `Bucket created successfully:\nID: ${bucketResponse.id}\nName: ${bucketResponse.name}\nOrganization ID: ${bucketResponse.orgID}`, }], }; } catch (error) { console.error(`=== CREATE-BUCKET TOOL ERROR: ${error.message} ===`); return { content: [{ type: "text", text: `Error creating bucket: ${error.message}`, }], isError: true, }; } } - src/index.js:120-142 (registration)Tool registration using server.tool() with name 'create-bucket', description, Zod schema for parameters (name: string, orgID: string, retentionPeriodSeconds: optional number), and the createBucket handler.
server.tool( "create-bucket", "Provision a new bucket under an organization so that subsequent write-data calls have a destination.", { name: z .string() .describe( "Friendly bucket name. Follow InfluxDB naming rules (alphanumeric, dashes, underscores).", ), orgID: z .string() .describe( "Organization ID (UUID) that will own the bucket. Retrieve it from the organizations resource or create-org output.", ), retentionPeriodSeconds: z .number() .optional() .describe( "Optional retention duration expressed in seconds. Omit for infinite retention.", ), }, createBucket, ); - src/index.js:25-25 (registration)Import of the createBucket handler from the handler file into the main server file.
import { createBucket } from "./handlers/createBucketTool.js"; - src/handlers/createBucketTool.js:2-2 (helper)Import of InfluxDB configuration constants (INFLUXDB_TOKEN, INFLUXDB_URL) used to authenticate and address the API endpoint.
import { INFLUXDB_TOKEN, INFLUXDB_URL } from "../config/env.js";