Skip to main content
Glama

authenticate-with-credentials

Authenticate with the PI API using username and password credentials when other authentication methods are unavailable.

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

  • Full implementation of the 'authenticate-with-credentials' tool, including inline handler that authenticates via basic auth to the /tokens endpoint using provided username and password, sets the global authToken on success.
    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 }) => {
        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)}` }]
            };
        }
    });
  • Input schema for the tool using Zod: expects a single string parameter 'credentials' formatted as 'username password'.
    credentials: z.string().describe("Username and password as 'username password'")
  • build/index.js:459-459 (registration)
    Registration of the tool on the MCP server with name, description, schema, and inline handler.
    server.tool("authenticate-with-credentials", "Authenticate with the PI API using username and password (last resort option)", {
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While it mentions authentication, it doesn't describe what happens after authentication (e.g., session creation, token storage), potential rate limits, error conditions, or security implications of using credentials. For a sensitive authentication tool with zero annotation coverage, this is a significant gap.

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 extremely concise with just one sentence that contains no wasted words. Every element (action, API, method, usage guidance) earns its place, making it front-loaded and efficient.

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?

For a sensitive authentication tool with no annotations and no output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., success/failure, session token), what happens after authentication, or any behavioral aspects beyond the basic purpose. The 'last resort' guidance is helpful but insufficient 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%, so the schema already documents the single parameter. The description adds no additional parameter information beyond what's in the schema. Baseline 3 is appropriate when the schema does all the parameter documentation work.

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 specific action ('Authenticate with the PI API') and resource ('using username and password'), distinguishing it from the sibling 'authenticate' tool by specifying the authentication method. It provides a complete verb+resource+method statement.

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

Usage Guidelines5/5

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

The description explicitly provides usage guidance with the phrase 'last resort option', indicating when to use this tool versus alternatives. This directly addresses the decision-making context for an AI agent selecting between authentication methods.

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