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
| Name | Required | Description | Default |
|---|---|---|---|
| apiKey | No | API key for authentication (optional if provided via --api_key) | |
| limit | No | Number of logs to return (default: 20) | |
| source | Yes | Log source to retrieve |
Implementation Reference
- src/shared/tools.ts:1037-1095 (registration)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, }; } }) );
- src/shared/tools.ts:1048-1094 (handler)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, }; } })
- src/shared/tools.ts:1041-1047 (schema)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)'), },
- src/shared/tools.ts:174-188 (helper)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; } }; }
- src/shared/tools.ts:192-197 (helper)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; };