Skip to main content
Glama

get-anon-key

Generate a non-expiring JWT token for client-side applications requiring public access. Use with admin API key to enable secure, persistent authentication.

Instructions

Generate an anonymous JWT token that never expires. Requires admin API key. Use this for client-side applications that need public access.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
apiKeyNoAPI key for authentication (optional if provided via --api_key)

Implementation Reference

  • Handler function that generates an anonymous JWT token by POSTing to the backend /api/auth/tokens/anon endpoint using the global or provided API key. Handles response with handleApiResponse, formats with formatSuccessMessage, adds background context, and returns error response if failed.
    withUsageTracking('get-anon-key', async ({ apiKey }) => { try { const actualApiKey = getApiKey(apiKey); const response = await fetch(`${API_BASE_URL}/api/auth/tokens/anon`, { method: 'POST', headers: { 'x-api-key': actualApiKey, 'Content-Type': 'application/json', }, }); const result = await handleApiResponse(response); return await addBackgroundContext({ content: [ { type: 'text', text: formatSuccessMessage('Anonymous token generated', result), }, ], }); } catch (error) { const errMsg = error instanceof Error ? error.message : 'Unknown error occurred'; return { content: [ { type: 'text', text: `Error generating anonymous token: ${errMsg}`, }, ], isError: true, }; } })
  • Zod input schema defining optional 'apiKey' parameter for the tool.
    apiKey: z .string() .optional() .describe('API key for authentication (optional if provided via --api_key)'),
  • MCP server.tool registration for 'get-anon-key', including description, input schema, and handler wrapped by withUsageTracking for usage monitoring.
    server.tool( 'get-anon-key', 'Generate an anonymous JWT token that never expires. Requires admin API key. Use this for client-side applications that need public access.', { apiKey: z .string() .optional() .describe('API key for authentication (optional if provided via --api_key)'), }, withUsageTracking('get-anon-key', async ({ apiKey }) => { try { const actualApiKey = getApiKey(apiKey); const response = await fetch(`${API_BASE_URL}/api/auth/tokens/anon`, { method: 'POST', headers: { 'x-api-key': actualApiKey, 'Content-Type': 'application/json', }, }); const result = await handleApiResponse(response); return await addBackgroundContext({ content: [ { type: 'text', text: formatSuccessMessage('Anonymous token generated', result), }, ], }); } catch (error) { const errMsg = error instanceof Error ? error.message : 'Unknown error occurred'; return { content: [ { type: 'text', text: `Error generating anonymous token: ${errMsg}`, }, ], isError: true, }; } }) );
  • Helper function getApiKey that returns the global API_KEY from config/env, ignoring any passed parameter for consistency.
    const getApiKey = (_toolApiKey?: string): string => { if (!GLOBAL_API_KEY) { throw new Error('API key is required. Pass --api_key when starting the MCP server.'); } return GLOBAL_API_KEY; };

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/InsForge/insforge-mcp'

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