Skip to main content
Glama

check-connection

Validate the current API URL and authentication to ensure a successful connection to PI Dashboard resources.

Instructions

Check if the current API URL and authentication are valid

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The tool is defined with an empty schema object {} meaning no input parameters are required.
    server.tool("check-connection", "Check if the current API URL and authentication are valid", {}, async () => {
  • The main handler function for the check-connection tool. It checks if API URL and auth token are set, then calls verifyConnection() to validate the connection by making a lightweight API request to /tokens/keepAlive.
    server.tool("check-connection", "Check if the current API URL and authentication are valid", {}, async () => {
        try {
            if (!apiUrlSet || !API_BASE_URL) {
                return {
                    content: [{
                            type: "text",
                            text: "API URL not set. Please set the API URL using the set-api-url tool."
                        }]
                };
            }
            if (!authToken) {
                return {
                    content: [{
                            type: "text",
                            text: "Not authenticated. Please authenticate using the authenticate tool."
                        }]
                };
            }
            // Verify the connection
            const isConnected = await verifyConnection();
            if (isConnected) {
                return {
                    content: [{
                            type: "text",
                            text: `✅ Connection successful! The API URL and token are valid. You're ready to use the PI API.`
                        }]
                };
            }
            else {
                return {
                    isError: true,
                    content: [{
                            type: "text",
                            text: `❌ Connection failed. The token might be invalid or expired. Please try to authenticate again.`
                        }]
                };
            }
        }
        catch (error) {
            return {
                isError: true,
                content: [{ type: "text", text: `Connection check failed: ${getErrorMessage(error)}` }]
            };
        }
    });
  • The verifyConnection helper function that attempts a POST request to /tokens/keepAlive endpoint to verify the API connection is working. Returns true/false and sets connectionVerified flag.
    async function verifyConnection() {
        if (!apiUrlSet || !API_BASE_URL) {
            return false;
        }
        if (!authToken) {
            return false;
        }
        try {
            // Try a lightweight request to verify the connection
            await authenticatedRequest("/tokens/keepAlive", "POST");
            connectionVerified = true;
            return true;
        }
        catch (error) {
            logError(`Connection verification failed: ${getErrorMessage(error)}`);
            connectionVerified = false;
            return false;
        }
    }
  • build/index.js:263-263 (registration)
    Tool registered via server.tool('check-connection', ...) on the McpServer instance named 'PI API Server'.
    server.tool("check-connection", "Check if the current API URL and authentication are valid", {}, async () => {
  • The authenticatedRequest helper used internally by verifyConnection to make authenticated HTTP requests with the bearer token.
    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();
Behavior2/5

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

With no annotations provided, the description carries the full burden of disclosing behavior. It only states the purpose but does not mention side effects, return values, error conditions, or whether it makes network calls—critical for a tool that checks connection status.

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, front-loaded sentence with no extraneous words. Every word contributes to the purpose.

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 tool with no parameters and no output schema, the description covers the essential purpose. However, it could be enhanced by mentioning return type or potential errors to fully inform the agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has no parameters with 100% coverage, so the description need not add parameter details. It meaningfully explains what the tool does (checks URL and auth), providing context beyond the empty schema.

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 clearly states the verb 'check' and the specific resources being checked ('current API URL and authentication'), which differentiates it from sibling tools like authenticate (which sets credentials) or keep-session-alive (which maintains a session).

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 using this tool to verify connection validity, but it does not provide explicit guidance on when to use it versus alternatives like authenticate or keep-session-alive, nor does it specify prerequisites 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