get-container-logs
Retrieve container logs to debug application issues by fetching recent entries from specified sources like insforge.logs or postgres.logs.
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) | |
| source | Yes | Log source to retrieve | |
| limit | No | Number of logs to return (default: 20) |
Implementation Reference
- src/shared/tools.ts:1045-1091 (handler)The handler function wrapped in withUsageTracking that fetches logs from the primary API endpoint `/api/logs/{source}` with a fallback to the legacy `/api/logs/analytics/{source}` endpoint if 404. Formats the response and adds background context.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:1037-1044 (schema)Zod schema defining the input parameters: optional apiKey, required source (enum of log types), optional limit (default 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:1034-1092 (registration)The MCP server.tool registration that defines the tool name 'get-container-logs', description, input schema, and references the 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, }; } }) );