Skip to main content
Glama

auth_login

Authenticate to an API, extract a JWT from the response, and store it locally for reuse in subsequent requests.

Instructions

Authenticate against an API, extract a JWT, and store it locally for reuse

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesThe URL to make the authentication request to
headersNoOptional headers to include in the auth request
bodyNoThe request body for authentication
requestTypeNoRequest type for the auth call
fieldFilesNoArray of field names that should be treated as files for form-data auth requests
jwtPathYesDot-notation path to the JWT in the response (e.g., token.access_token)
folderYesFolder where the token file will be stored
user_titleNoOptional label for the stored token (default: 'default')

Implementation Reference

  • The main handler logic for the auth_login tool. Performs a POST request to the auth URL, extracts the JWT token from the response using the dot-notation jwtPath, validates it, stores it in the specified folder's tokens.json under the user_title, and returns a success message.
    case "auth_login": { const url = String(args?.url || ''); const headers = args?.headers as Record<string, string> || {}; const body = args?.body; const requestType = args?.requestType as 'json' | 'form-data' || 'json'; const fieldFiles = args?.fieldFiles as string[] || []; const jwtPath = String(args?.jwtPath || ''); const folder = String(args?.folder || ''); const userTitle = String(args?.user_title || 'default'); if (!url) { throw new Error("URL is required for auth_login"); } if (!jwtPath) { throw new Error("jwtPath is required to extract the token"); } if (!folder) { throw new Error("folder is required to store the token"); } const result = await makeHttpRequest('POST', { url, headers, body, requestType, fieldFiles }); const token = extractValueByPath(result.data, jwtPath); if (!token || typeof token !== 'string') { throw new Error(`Could not find a token at path '${jwtPath}' in the response`); } saveToken(folder, userTitle, token); return { content: [{ type: "text", text: `Stored token for user '${userTitle}' at ${resolveTokenFilePath(folder)}` }] }; }
  • src/index.ts:235-282 (registration)
    Registration of the auth_login tool in the listTools handler, including its description and full input schema definition.
    { name: "auth_login", description: "Authenticate against an API, extract a JWT, and store it locally for reuse", inputSchema: { type: "object", properties: { url: { type: "string", description: "The URL to make the authentication request to" }, headers: { type: "object", description: "Optional headers to include in the auth request", additionalProperties: { type: "string" } }, body: { description: "The request body for authentication" }, requestType: { type: "string", enum: ["json", "form-data"], description: "Request type for the auth call" }, fieldFiles: { type: "array", items: { type: "string" }, description: "Array of field names that should be treated as files for form-data auth requests" }, jwtPath: { type: "string", description: "Dot-notation path to the JWT in the response (e.g., token.access_token)" }, folder: { type: "string", description: "Folder where the token file will be stored" }, user_title: { type: "string", description: "Optional label for the stored token (default: 'default')" } }, required: ["url", "jwtPath", "folder"] } },
  • Helper function called by the auth_login handler to persist the extracted JWT token to tokens.json in the specified folder, creating or updating the user entry.
    function saveToken(folder: string, userTitle: string, token: string) { const tokenFile = resolveTokenFilePath(folder); mkdirSync(folder, { recursive: true }); const tokens = loadStoredTokens(folder); const existingIndex = tokens.findIndex((entry) => entry.user_title_name === userTitle); if (existingIndex >= 0) { tokens[existingIndex].token = token; } else { tokens.push({ user_title_name: userTitle, token }); } writeFileSync(tokenFile, JSON.stringify(tokens, null, 2), 'utf-8'); }
  • Helper function used by the auth_login handler to extract the JWT token from the API response using dot-notation path (e.g., 'data.token.access_token').
    function extractValueByPath(obj: any, path: string): any { return path.split('.').reduce((current, key) => { if (current && typeof current === 'object' && key in current) { return current[key as keyof typeof current]; } return undefined; }, obj); }

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/vilasone455/api-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server