Skip to main content
Glama
us-all

airflow-mcp-server

by us-all

airflow-get-task-logs

Retrieve the last N kilobytes of an Airflow task instance log for a given try number, enabling quick inspection of recent logs without loading the entire file.

Instructions

Fetch the tail (last N kB) of an Airflow task instance log for a specific try_number

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dagIdYes
dagRunIdYes
taskIdYes
tryNumberNo
tailKbNoReturn only the last N kilobytes of log

Implementation Reference

  • Handler function that fetches Airflow task instance logs via the REST API, trims to tailKb, and returns the content along with metadata.
    export async function airflowGetTaskLogs(args: z.infer<typeof airflowGetTaskLogsSchema>): Promise<unknown> {
      const path = `/dags/${encodeURIComponent(args.dagId)}/dagRuns/${encodeURIComponent(args.dagRunId)}/taskInstances/${encodeURIComponent(args.taskId)}/logs/${args.tryNumber}?full_content=true`;
      const data = await airflowFetch<{ content?: string; continuation_token?: unknown }>(path);
      let content = data.content ?? "";
      const limit = args.tailKb * 1024;
      let truncated = false;
      if (content.length > limit) {
        truncated = true;
        content = content.slice(content.length - limit);
      }
      return {
        dagId: args.dagId,
        dagRunId: args.dagRunId,
        taskId: args.taskId,
        tryNumber: args.tryNumber,
        truncated,
        content,
      };
    }
  • Zod schema defining the input parameters for the tool: dagId, dagRunId, taskId, tryNumber (default 1), and tailKb (1-64, default 16).
    export const airflowGetTaskLogsSchema = z.object({
      dagId: z.string(),
      dagRunId: z.string(),
      taskId: z.string(),
      tryNumber: z.coerce.number().int().min(1).default(1),
      tailKb: z.coerce.number().int().min(1).max(64).default(16).describe("Return only the last N kilobytes of log"),
    });
  • src/index.ts:49-49 (registration)
    Registration of the tool with the MCP server, wiring the schema and handler together.
    tool("airflow-get-task-logs", "Fetch the tail (last N kB) of an Airflow task instance log for a specific try_number", airflowGetTaskLogsSchema.shape, wrapToolHandler(airflowGetTaskLogs));
  • HTTP client helper used by airflowGetTaskLogs to make authenticated requests to the Airflow REST API v2.
    export async function airflowFetch<T = unknown>(
      path: string,
      init: RequestInit & { method?: string; body?: string } = {},
    ): Promise<T> {
      if (!config.apiBase) {
        throw new Error("AIRFLOW_API_URL is not configured");
      }
      const token = await getValidToken();
      const url = `${config.apiBase}/api/v2${path.startsWith("/") ? "" : "/"}${path}`;
      const headers = new Headers(init.headers);
      headers.set("Authorization", `Bearer ${token}`);
      if (init.body && !headers.has("Content-Type")) headers.set("Content-Type", "application/json");
      headers.set("Accept", "application/json");
      const res = await fetch(url, { ...init, headers });
      const text = await res.text();
      let body: unknown;
      try { body = text ? JSON.parse(text) : null; } catch { body = text; }
      if (!res.ok) {
        if (res.status === 401) {
          // Token may have rotated — invalidate cache and let caller retry one
          tokenCache = null;
        }
        throw new AirflowApiError(
          res.status,
          body,
          `Airflow API ${init.method ?? "GET"} ${path} failed: ${res.status} ${res.statusText}`,
        );
      }
      return body as T;
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description must disclose behavior. It indicates a read-only operation ('Fetch') and implies truncated output ('tail... last N kB'). However, it does not mention authorization needs, error handling, or what occurs if logs are empty or beyond the requested size. Adequate but not thorough.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence that imparts necessary information without any filler. It front-loads the action and resource, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 5 parameters (3 required) and no output schema, the description is too sparse. It omits essential context about parameter roles, behavior for missing logs, and usage scenarios relative to sibling tools. The minimal description inadequately guides an agent in complex scenarios.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Only one of five parameters ('tailKb') has a description in the schema, resulting in 20% schema description coverage. The description itself adds no further parameter explanations, leaving key parameters like 'dagId', 'dagRunId', 'taskId', and 'tryNumber' undocumented.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Fetch the tail'), identifies the resource ('Airflow task instance log'), and specifies scope ('last N kB', 'specific try_number'). It effectively distinguishes this tool from siblings like 'airflow-clear-task' or 'airflow-get-task-instances' by focusing on log retrieval.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. There is no indication of prerequisites, when not to use it, or how it compares to sibling tools. The description simply states what it does without contextual advice.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/us-all/airflow-mcp-server'

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