Skip to main content
Glama

get-chart

Retrieve a specific chart from PI Dashboard by providing its unique ID.

Instructions

Get a chart by ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesChart ID

Implementation Reference

  • build/index.js:795-813 (registration)
    Tool registration for 'get-chart' using server.tool() with the MCP SDK. Registers the tool with name 'get-chart' and description 'Get a chart by ID', expecting a single 'id' parameter of type number.
    server.tool("get-chart", "Get a chart by ID", {
        id: z.number().describe("Chart ID")
    }, async ({ id }) => {
        try {
            const chart = await authenticatedRequest(`/charts/${id}`);
            return {
                content: [{
                        type: "text",
                        text: `Chart details:\n${JSON.stringify(chart, null, 2)}`
                    }]
            };
        }
        catch (error) {
            return {
                isError: true,
                content: [{ type: "text", text: `Error fetching chart: ${getErrorMessage(error)}` }]
            };
        }
    });
  • Input schema for the 'get-chart' tool: id (z.number()) representing the Chart ID.
    id: z.number().describe("Chart ID")
  • Handler function for the 'get-chart' tool. Calls authenticatedRequest('/charts/{id}') to fetch chart details by ID, then returns the chart data as formatted JSON. On error, returns an isError response.
    }, async ({ id }) => {
        try {
            const chart = await authenticatedRequest(`/charts/${id}`);
            return {
                content: [{
                        type: "text",
                        text: `Chart details:\n${JSON.stringify(chart, null, 2)}`
                    }]
            };
        }
        catch (error) {
            return {
                isError: true,
                content: [{ type: "text", text: `Error fetching chart: ${getErrorMessage(error)}` }]
            };
        }
    });
  • Helper function 'authenticatedRequest' used by the get-chart handler to make authenticated API requests with Bearer token auth, query params, and JSON/binary response handling.
    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;
        }
    }
  • Helper function 'getErrorMessage' used for consistent error message extraction across error handlers.
    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 are provided, so the description carries full transparency burden. It only states the action without disclosing behavioral traits such as authentication requirements, read-only status, side effects, or error conditions. Simple retrieval is implied but not confirmed.

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 is a single concise sentence, front-loaded with the verb and resource. Every word is necessary, and there is no superfluous information.

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

Completeness4/5

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

For a simple retrieval operation with a single parameter, the description is mostly complete. However, the lack of an output schema means the description should hint at the return value (e.g., 'returns the chart object') for full completeness.

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% (one parameter 'id' described as 'Chart ID'). The description adds no additional meaning beyond what the schema provides, so 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 'Get a chart by ID' clearly states the verb ('Get'), resource ('chart'), and scope ('by ID'). It distinguishes from sibling tools like 'list-charts' (list) and 'delete-chart' (delete), making the purpose unambiguous.

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

Usage Guidelines3/5

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

The description implies usage when you have a specific chart ID, but provides no explicit guidance on when to use this tool over alternatives like 'get-category' or 'list-charts'. No exclusions or prerequisites are mentioned.

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