Skip to main content
Glama

export-chart

Export a chart by its ID to JSON or CSV, enabling data analysis or system integration.

Instructions

Export a chart in various formats

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesChart ID
formatYesExport format

Implementation Reference

  • The 'export-chart' tool handler: exports a chart in JSON or CSV format by making an authenticated request to /charts/{id}/{format}. Handles both binary (base64) and JSON/text responses.
    server.tool("export-chart", "Export a chart in various formats", {
        id: z.number().describe("Chart ID"),
        format: z.enum(["json", "csv"]).describe("Export format")
    }, async ({ id, format }) => {
        try {
            const result = await authenticatedRequest(`/charts/${id}/${format}`);
            if (result && typeof result === 'object' &&
                'contentType' in result && 'data' in result &&
                typeof result.data === 'string') {
                // This is a binary response
                return {
                    content: [{
                            type: "text",
                            text: `Chart exported successfully as ${format.toUpperCase()}.\nContent type: ${result.contentType}\nBase64 data: ${result.data.substring(0, 100)}...`
                        }]
                };
            }
            else {
                // This is a JSON or text response
                return {
                    content: [{
                            type: "text",
                            text: typeof result === 'string' ? result : JSON.stringify(result, null, 2)
                        }]
                };
            }
        }
        catch (error) {
            return {
                isError: true,
                content: [{ type: "text", text: `Error exporting chart: ${getErrorMessage(error)}` }]
            };
        }
    });
  • Input schema for export-chart: requires id (number) and format (enum: 'json' or 'csv').
        id: z.number().describe("Chart ID"),
        format: z.enum(["json", "csv"]).describe("Export format")
    }, async ({ id, format }) => {
  • build/index.js:835-835 (registration)
    Registration of the 'export-chart' tool via server.tool(...) with description 'Export a chart in various formats'.
    server.tool("export-chart", "Export a chart in various formats", {
  • The authenticatedRequest helper function that performs the actual HTTP request. For CSV content (text/csv), it returns a base64-encoded buffer wrapped in an object with contentType and data properties. For JSON, it returns parsed data.
    async function authenticatedRequest(endpoint, method = "GET", body = null, queryParams = {}) {
        if (!apiUrlSet) {
            throw new Error("API URL not set. Please set the API URL using the set-api-url tool.");
        }
        if (!authToken) {
            throw new Error("Not authenticated. Please authenticate first.");
        }
        // Build URL with query parameters
        let url = `${API_BASE_URL}${endpoint}`;
        // Add orgId if available
        if (orgId !== null) {
            queryParams.orgId = orgId.toString();
        }
        // Add query parameters if any
        if (Object.keys(queryParams).length > 0) {
            const queryString = Object.entries(queryParams)
                .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
                .join("&");
            url = `${url}?${queryString}`;
        }
        logInfo(`Making ${method} request to ${url}`);
        const headers = {
            "Authorization": `bearer ${authToken}`,
            "Content-Type": "application/json"
        };
        const options = {
            method,
            headers
        };
        if (body !== null && ["POST", "PUT"].includes(method)) {
            options.body = JSON.stringify(body);
            logInfo(`Request body: ${JSON.stringify(body)}`);
        }
        try {
            const response = await fetch(url, options);
            if (!response.ok) {
                const errorText = await response.text();
                logError(`API request failed with status ${response.status}: ${errorText}`);
                throw new Error(`API request failed with status ${response.status}: ${response.statusText}`);
            }
            // Check if the response is JSON or binary
            const contentType = response.headers.get("content-type") || "";
            if (contentType.includes("application/json")) {
                const jsonData = await response.json();
                logInfo(`Received JSON response: ${JSON.stringify(jsonData).substring(0, 200)}...`);
                return jsonData;
            }
            else if (contentType.includes("text/csv")) {
                // For binary/file responses, return a base64 encoded string
                const buffer = await response.arrayBuffer();
                const base64 = Buffer.from(buffer).toString("base64");
                logInfo(`Received binary response of type ${contentType}, length: ${base64.length}`);
                return {
                    contentType,
                    data: base64
                };
            }
            else {
                // Otherwise, return as text
                const text = await response.text();
                logInfo(`Received text response: ${text.substring(0, 200)}...`);
                return text;
            }
        }
        catch (error) {
            logError(`API request error: ${getErrorMessage(error)}`);
            throw error;
        }
    }
  • The getErrorMessage helper used to safely extract error messages in the catch block of the export-chart handler.
    const getErrorMessage = (error) => {
        if (error instanceof Error)
            return error.message;
        return String(error);
    };
Behavior2/5

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

No annotations provided, and the description does not disclose whether export is destructive, requires authentication, or what happens on error. The agent must infer safety from the name alone.

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, concise sentence. It avoids unnecessary words but may be too brief to provide full context.

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?

The description lacks information about the output format behavior, whether the export triggers a download or returns data inline, and any side effects. Without an output schema, more context is needed.

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?

Input schema covers 100% of parameters with descriptions, so the description adds no extra semantics. The description does not elaborate on parameter usage beyond the schema.

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

Purpose4/5

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

The description specifies the verb 'export' and resource 'chart', with 'various formats' indicating output options. It distinguishes from siblings like 'get-chart' or 'delete-chart', though it could be more precise about the available formats.

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

Usage Guidelines2/5

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

No guidance on when to use this tool versus alternatives like 'get-chart' or 'list-charts'. The description does not mention prerequisites or context for export.

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/mingzilla/pi-api-mcp-server'

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