Skip to main content
Glama

get_function_logs

Retrieve recent console logs and error stack traces from deployed functions to monitor execution and debug issues in your project.

Instructions

Get recent logs from a deployed function. Shows console.log/error output and error stack traces from CloudWatch.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYesThe project ID
nameYesFunction name to get logs for
tailNoNumber of log lines to return (default: 50, max: 200)

Implementation Reference

  • The main handler function that executes the tool logic. It validates the project, makes an API request to fetch function logs from CloudWatch, handles errors, and formats the logs into a readable markdown response with timestamps and log count.
    export async function handleGetFunctionLogs(args: {
      project_id: string;
      name: string;
      tail?: number;
    }): Promise<{ content: Array<{ type: "text"; text: string }>; isError?: boolean }> {
      const project = getProject(args.project_id);
      if (!project) return projectNotFound(args.project_id);
    
      const tail = args.tail || 50;
      const res = await apiRequest(
        `/admin/v1/projects/${args.project_id}/functions/${encodeURIComponent(args.name)}/logs?tail=${tail}`,
        {
          method: "GET",
          headers: {
            Authorization: `Bearer ${project.service_key}`,
          },
        },
      );
    
      if (!res.ok) return formatApiError(res, "fetching function logs");
    
      const body = res.body as { logs: Array<{ timestamp: string; message: string }> };
      const logs = body.logs || [];
    
      if (logs.length === 0) {
        return {
          content: [
            {
              type: "text",
              text: `## Function Logs: ${args.name}\n\n_No logs found. The function may not have been invoked yet._`,
            },
          ],
        };
      }
    
      const logLines = logs.map(
        (log) => `[${log.timestamp}] ${log.message}`,
      );
    
      const lines = [
        `## Function Logs: ${args.name}`,
        ``,
        `\`\`\``,
        ...logLines,
        `\`\`\``,
        ``,
        `_${logs.length} log entries_`,
      ];
    
      return { content: [{ type: "text", text: lines.join("\n") }] };
    }
  • Input schema definition using Zod. Defines three parameters: project_id (required string), name (required string for function name), and tail (optional number for log lines, default 50, max 200).
    export const getFunctionLogsSchema = {
      project_id: z.string().describe("The project ID"),
      name: z.string().describe("Function name to get logs for"),
      tail: z
        .number()
        .optional()
        .describe("Number of log lines to return (default: 50, max: 200)"),
    };
  • src/index.ts:153-158 (registration)
    Tool registration with the MCP server. Registers 'get_function_logs' with its schema and handler, including a description that explains it retrieves recent logs from a deployed function including console output and error traces from CloudWatch.
    server.tool(
      "get_function_logs",
      "Get recent logs from a deployed function. Shows console.log/error output and error stack traces from CloudWatch.",
      getFunctionLogsSchema,
      async (args) => handleGetFunctionLogs(args),
    );

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/kychee-com/run402'

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