Skip to main content
Glama

authenticate-with-credentials

Authenticate to the PI API by providing a username and password as a last resort authentication method, using the format 'username password'.

Instructions

Authenticate with the PI API using username and password (last resort option)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
credentialsYesUsername and password as 'username password'

Implementation Reference

  • build/index.js:459-461 (registration)
    The register call for the 'authenticate-with-credentials' tool via server.tool().
    server.tool("authenticate-with-credentials", "Authenticate with the PI API using username and password (last resort option)", {
        credentials: z.string().describe("Username and password as 'username password'")
    }, async ({ credentials }) => {
  • Input schema for the tool: expects a 'credentials' string (username and password as 'username password').
    credentials: z.string().describe("Username and password as 'username password'")
  • The handler function that parses credentials, performs basic auth against /tokens endpoint, stores the token, and returns success/error.
    }, async ({ credentials }) => {
        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."
                        }]
                };
            }
            // Parse credentials - simple space separation
            const parts = credentials.trim().split(/\s+/);
            if (parts.length < 2) {
                return {
                    isError: true,
                    content: [{
                            type: "text",
                            text: "Invalid credentials format. Please provide as 'username password'"
                        }]
                };
            }
            // First part is username, rest is considered password (in case password has spaces)
            const username = parts[0];
            const password = parts.slice(1).join(' ');
            if (!username || !password) {
                return {
                    isError: true,
                    content: [{
                            type: "text",
                            text: "Both username and password are required. Please provide as 'username password'"
                        }]
                };
            }
            // Authenticate with the credentials
            const credentialsBase64 = Buffer.from(`${username}:${password}`).toString("base64");
            const response = await fetch(`${API_BASE_URL}/tokens`, {
                method: "POST",
                headers: {
                    "Content-Type": "application/json",
                    "Authorization": `basic ${credentialsBase64}`
                }
            });
            if (!response.ok) {
                const errorText = await response.text();
                return {
                    isError: true,
                    content: [{ type: "text", text: `Authentication failed: ${response.status} - ${errorText}` }]
                };
            }
            const data = await response.json();
            if (data && typeof data === 'object' && 'token' in data && typeof data.token === 'string') {
                authToken = data.token;
                connectionVerified = true;
            }
            else {
                return {
                    isError: true,
                    content: [{ type: "text", text: "Authentication failed: Invalid response format" }]
                };
            }
            return {
                content: [{
                        type: "text",
                        text: "✅ Authentication successful. You can now use other tools and resources."
                    }]
            };
        }
        catch (error) {
            return {
                isError: true,
                content: [{ type: "text", text: `Error authenticating: ${getErrorMessage(error)}` }]
            };
        }
    });
Behavior2/5

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

No annotations are provided, so the description must fully disclose behavior. It mentions using username and password but does not explain side effects like session creation, security implications, or error states. 'Last resort' hints at reduced preference but lacks specificity.

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 redundant information. Every word earns its place.

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 tool performs authentication but does not describe the return value (e.g., token) or how the agent should use the resulting authenticated session. Essential context for an AI agent is missing.

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 description adds no extra meaning beyond what the schema already provides. It essentially restates the schema's description of the only parameter.

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 action (authenticate), the resource (PI API), and the method (username and password), and distinguishes it as a 'last resort option', which sets it apart from sibling authentication tools.

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

Usage Guidelines4/5

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

The phrase 'last resort option' explicitly guides when to use this tool (when other authentication methods fail or are unavailable), implying when not to use it. However, it does not name specific alternative tools.

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