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)", {

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