create-org
Create organizations to isolate users or projects, enabling bucket and token generation.
Instructions
Create a brand-new organization to isolate users or projects before generating buckets and tokens.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Display name for the organization as it should appear in InfluxDB Cloud/OSS. | |
| description | No | Optional free-form description that helps humans understand why the org exists. |
Implementation Reference
- src/handlers/createOrgTool.js:1-35 (handler)The main handler function 'createOrg' that executes the create-org tool logic. It takes name and description, sends a POST to InfluxDB /api/v2/orgs, and returns the created organization details.
import { influxRequest } from "../utils/influxClient.js"; // Tool: Create Organization export async function createOrg({ name, description }) { try { const orgData = { name, description, }; const response = await influxRequest("/api/v2/orgs", { method: "POST", body: JSON.stringify(orgData), }); const org = await response.json(); return { content: [{ type: "text", text: `Organization created successfully:\nID: ${org.id}\nName: ${org.name}\nDescription: ${org.description || "N/A" }`, }], }; } catch (error) { return { content: [{ type: "text", text: `Error creating organization: ${error.message}`, }], isError: true, }; } } - src/index.js:143-160 (schema)Schema definition for the 'create-org' tool: accepts a required 'name' string and an optional 'description' string, defined using Zod.
server.tool( "create-org", "Create a brand-new organization to isolate users or projects before generating buckets and tokens.", { name: z .string() .describe( "Display name for the organization as it should appear in InfluxDB Cloud/OSS.", ), description: z .string() .optional() .describe( "Optional free-form description that helps humans understand why the org exists.", ), }, createOrg, ); - src/index.js:143-160 (registration)Registration of the 'create-org' tool with the MCP server using server.tool(), binding the schema and handler together.
server.tool( "create-org", "Create a brand-new organization to isolate users or projects before generating buckets and tokens.", { name: z .string() .describe( "Display name for the organization as it should appear in InfluxDB Cloud/OSS.", ), description: z .string() .optional() .describe( "Optional free-form description that helps humans understand why the org exists.", ), }, createOrg, ); - src/utils/influxClient.js:1-69 (helper)The 'influxRequest' helper utility used by the handler to make authenticated HTTP requests to the InfluxDB API with timeout and error handling.
import fetch from "node-fetch"; import { INFLUXDB_TOKEN, INFLUXDB_URL } from "../config/env.js"; // Helper function for InfluxDB API requests with timeout 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; } }