Skip to main content
Glama

get-container-logs

Retrieve container logs to debug application issues by accessing log sources including insforge, postgREST, postgres, and function logs with configurable output limits.

Instructions

Get latest logs from a specific container/service. Use this to help debug problems with your app.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
apiKeyNoAPI key for authentication (optional if provided via --api_key)
limitNoNumber of logs to return (default: 20)
sourceYesLog source to retrieve

Implementation Reference

  • Full registration of the 'get-container-logs' tool using McpServer.tool(), including name, description, input schema, and the wrapped handler function.
    server.tool( 'get-container-logs', 'Get latest logs from a specific container/service. Use this to help debug problems with your app.', { apiKey: z .string() .optional() .describe('API key for authentication (optional if provided via --api_key)'), source: z.enum(['insforge.logs', 'postgREST.logs', 'postgres.logs', 'function.logs']).describe('Log source to retrieve'), limit: z.number().optional().default(20).describe('Number of logs to return (default: 20)'), }, withUsageTracking('get-container-logs', async ({ apiKey, source, limit }) => { try { const actualApiKey = getApiKey(apiKey); const queryParams = new URLSearchParams(); if (limit) queryParams.append('limit', limit.toString()); let response = await fetch(`${API_BASE_URL}/api/logs/${source}?${queryParams}`, { method: 'GET', headers: { 'x-api-key': actualApiKey, }, }); // Fallback to legacy endpoint if 404 if (response.status === 404) { response = await fetch(`${API_BASE_URL}/api/logs/analytics/${source}?${queryParams}`, { method: 'GET', headers: { 'x-api-key': actualApiKey, }, }); } const result = await handleApiResponse(response); return await addBackgroundContext({ content: [ { type: 'text', text: formatSuccessMessage(`Latest logs from ${source}`, result), }, ], }); } catch (error) { const errMsg = error instanceof Error ? error.message : 'Unknown error occurred'; return { content: [ { type: 'text', text: `Error retrieving container logs: ${errMsg}`, }, ], isError: true, }; } }) );
  • The core handler logic: fetches logs from /api/logs/{source} (with limit query param and legacy fallback), processes response with handleApiResponse, adds background context, and formats output using formatSuccessMessage. Uses getApiKey for authentication.
    withUsageTracking('get-container-logs', async ({ apiKey, source, limit }) => { try { const actualApiKey = getApiKey(apiKey); const queryParams = new URLSearchParams(); if (limit) queryParams.append('limit', limit.toString()); let response = await fetch(`${API_BASE_URL}/api/logs/${source}?${queryParams}`, { method: 'GET', headers: { 'x-api-key': actualApiKey, }, }); // Fallback to legacy endpoint if 404 if (response.status === 404) { response = await fetch(`${API_BASE_URL}/api/logs/analytics/${source}?${queryParams}`, { method: 'GET', headers: { 'x-api-key': actualApiKey, }, }); } const result = await handleApiResponse(response); return await addBackgroundContext({ content: [ { type: 'text', text: formatSuccessMessage(`Latest logs from ${source}`, result), }, ], }); } catch (error) { const errMsg = error instanceof Error ? error.message : 'Unknown error occurred'; return { content: [ { type: 'text', text: `Error retrieving container logs: ${errMsg}`, }, ], isError: true, }; } })
  • Zod schema for input parameters: optional apiKey (string), source (enum of log sources), optional limit (number, defaults to 20).
    apiKey: z .string() .optional() .describe('API key for authentication (optional if provided via --api_key)'), source: z.enum(['insforge.logs', 'postgREST.logs', 'postgres.logs', 'function.logs']).describe('Log source to retrieve'), limit: z.number().optional().default(20).describe('Number of logs to return (default: 20)'), },
  • Helper wrapper applied to the handler that tracks usage success/failure via trackToolUsage.
    function withUsageTracking<T extends unknown[], R>( toolName: string, handler: (...args: T) => Promise<R> ): (...args: T) => Promise<R> { return async (...args: T): Promise<R> => { try { const result = await handler(...args); await trackToolUsage(toolName, true); return result; } catch (error) { await trackToolUsage(toolName, false); throw error; } }; }
  • Helper function to retrieve the global API key for authentication requests.
    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