Skip to main content
Glama

get-category

Retrieve category details by ID from the PI Dashboard to organize and manage data resources.

Instructions

Get a category by ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesCategory ID

Implementation Reference

  • The handler function for the get-category tool. It fetches the category by ID using the authenticatedRequest helper and returns formatted details or an error.
    }, async ({ id }) => {
        try {
            const category = await authenticatedRequest(`/categories/${id}`);
            return {
                content: [{
                        type: "text",
                        text: `Category details:\n${JSON.stringify(category, null, 2)}`
                    }]
            };
        }
        catch (error) {
            return {
                isError: true,
                content: [{ type: "text", text: `Error fetching category: ${getErrorMessage(error)}` }]
            };
        }
    });
  • Input schema using Zod, requiring a numeric 'id' for the category ID.
    id: z.number().describe("Category ID")
  • build/index.js:628-646 (registration)
    Registration of the 'get-category' tool on the MCP server, including description, schema, and handler function.
    server.tool("get-category", "Get a category by ID", {
        id: z.number().describe("Category ID")
    }, async ({ id }) => {
        try {
            const category = await authenticatedRequest(`/categories/${id}`);
            return {
                content: [{
                        type: "text",
                        text: `Category details:\n${JSON.stringify(category, null, 2)}`
                    }]
            };
        }
        catch (error) {
            return {
                isError: true,
                content: [{ type: "text", text: `Error fetching category: ${getErrorMessage(error)}` }]
            };
        }
    });
  • Core helper function for all authenticated API calls, used by the get-category handler to fetch /categories/{id}.
    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;
        }
    }
  • Utility function to safely extract error message strings, used in the handler's catch block.
    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 burden. It states it 'gets' a category, implying a read operation, but doesn't disclose behavioral traits like authentication needs, error handling, or response format. This leaves significant gaps for a tool with no annotation coverage.

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, efficient sentence with zero waste. It's appropriately sized and front-loaded, clearly stating the tool's purpose without unnecessary elaboration.

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 no annotations and no output schema, the description is incomplete. It lacks details on authentication, error cases, or return values, which are crucial for a read operation tool. This makes it inadequate for full contextual understanding.

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 description coverage is 100%, with the parameter 'id' documented as 'Category ID'. The description adds no additional meaning beyond this, such as ID format or examples. Baseline 3 is appropriate as the schema does the heavy lifting.

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 clearly states the verb ('Get') and resource ('a category'), specifying it retrieves by ID. It distinguishes from siblings like 'list-categories' (which retrieves multiple) and 'create-category' (which creates), but doesn't explicitly mention these distinctions in the description itself.

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 is provided on when to use this tool versus alternatives like 'list-categories' or 'list-category-objects'. The description implies usage when you have a specific category ID, but lacks explicit context or 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/mingzilla/pi-api-mcp-server'

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