Skip to main content
Glama

keep-session-alive

Verify and refresh authentication tokens to maintain continuous access to PI Dashboard resources without manual intervention.

Instructions

Verify and refresh the current authentication token (also used for token-based authentication)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tokenNoOptional: Provide a token to use for authentication

Implementation Reference

  • build/index.js:392-457 (registration)
    Full registration of the 'keep-session-alive' tool, including name, description, input schema, and inline handler function that verifies/sets auth token via /tokens/keepAlive API call.
    server.tool("keep-session-alive", "Verify and refresh the current authentication token (also used for token-based authentication)", {
        token: z.string().optional().describe("Optional: Provide a token to use for authentication")
    }, async ({ token }) => {
        try {
            if (!apiUrlSet) {
                return {
                    isError: true,
                    content: [{
                            type: "text",
                            text: "API URL not set. Please set the API URL first using the set-api-url tool."
                        }]
                };
            }
            // If a token is provided, use it instead of the current one
            const originalToken = authToken;
            if (token) {
                authToken = token;
                logInfo("Token provided via keep-session-alive tool");
            }
            if (!authToken) {
                return {
                    isError: true,
                    content: [{
                            type: "text",
                            text: "No token available. Please provide a token or authenticate with credentials."
                        }]
                };
            }
            try {
                // Try to keep the session alive
                await authenticatedRequest("/tokens/keepAlive", "POST");
                connectionVerified = true;
                // If we got here, the token is valid
                return {
                    content: [{
                            type: "text",
                            text: token
                                ? "✅ Token validated and set successfully. You are now authenticated."
                                : "✅ Session kept alive successfully. Your token is valid."
                        }]
                };
            }
            catch (error) {
                // If validation fails and we were using a provided token, restore the original
                if (token) {
                    authToken = originalToken;
                }
                connectionVerified = false;
                return {
                    isError: true,
                    content: [{
                            type: "text",
                            text: token
                                ? `❌ The provided token is invalid or expired: ${getErrorMessage(error)}\nPlease try with another token or use authenticate-with-credentials.`
                                : `❌ Your session token is invalid or expired: ${getErrorMessage(error)}\nPlease authenticate again.`
                        }]
                };
            }
        }
        catch (error) {
            return {
                isError: true,
                content: [{ type: "text", text: `Error keeping session alive: ${getErrorMessage(error)}` }]
            };
        }
    });
  • Handler function that optionally sets a new token, verifies it by POST to /tokens/keepAlive, updates global auth state, and returns success/error messages.
    }, async ({ token }) => {
        try {
            if (!apiUrlSet) {
                return {
                    isError: true,
                    content: [{
                            type: "text",
                            text: "API URL not set. Please set the API URL first using the set-api-url tool."
                        }]
                };
            }
            // If a token is provided, use it instead of the current one
            const originalToken = authToken;
            if (token) {
                authToken = token;
                logInfo("Token provided via keep-session-alive tool");
            }
            if (!authToken) {
                return {
                    isError: true,
                    content: [{
                            type: "text",
                            text: "No token available. Please provide a token or authenticate with credentials."
                        }]
                };
            }
            try {
                // Try to keep the session alive
                await authenticatedRequest("/tokens/keepAlive", "POST");
                connectionVerified = true;
                // If we got here, the token is valid
                return {
                    content: [{
                            type: "text",
                            text: token
                                ? "✅ Token validated and set successfully. You are now authenticated."
                                : "✅ Session kept alive successfully. Your token is valid."
                        }]
                };
            }
            catch (error) {
                // If validation fails and we were using a provided token, restore the original
                if (token) {
                    authToken = originalToken;
                }
                connectionVerified = false;
                return {
                    isError: true,
                    content: [{
                            type: "text",
                            text: token
                                ? `❌ The provided token is invalid or expired: ${getErrorMessage(error)}\nPlease try with another token or use authenticate-with-credentials.`
                                : `❌ Your session token is invalid or expired: ${getErrorMessage(error)}\nPlease authenticate again.`
                        }]
                };
            }
        }
        catch (error) {
            return {
                isError: true,
                content: [{ type: "text", text: `Error keeping session alive: ${getErrorMessage(error)}` }]
            };
        }
    });
  • Zod input schema defining optional 'token' parameter as string.
    token: z.string().optional().describe("Optional: Provide a token to use for authentication")
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 behavioral disclosure. It mentions 'verify and refresh' but doesn't specify what happens on success/failure, whether it extends session duration, or if it's idempotent. For an authentication-related tool, this is a significant gap in transparency about its effects and constraints.

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, efficient sentence that front-loads the core purpose. However, the parenthetical 'also used for token-based authentication' is slightly redundant with the main clause and could be integrated more smoothly, preventing a perfect score.

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 the complexity of authentication tools and lack of annotations or output schema, the description is incomplete. It doesn't explain return values, error conditions, or how it interacts with other auth tools. For a tool managing session state, more detail on behavior and integration 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?

Schema description coverage is 100%, so the schema already documents the single optional 'token' parameter. The description adds minimal value by implying the token is for authentication, but doesn't clarify semantics like default behavior (e.g., using a cached token if not provided) or format requirements. Baseline 3 is appropriate given high schema coverage.

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 tool's purpose: 'Verify and refresh the current authentication token' and mentions 'token-based authentication'. It uses specific verbs (verify, refresh) and identifies the resource (authentication token). However, it doesn't explicitly differentiate from sibling tools like 'authenticate' or 'check-connection', which prevents a score of 5.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, timing (e.g., before token expiration), or contrast with sibling tools like 'authenticate' for initial authentication or 'check-connection' for status checks. This lack of context leaves usage unclear.

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