Skip to main content
Glama
beekamai
by beekamai

stream_latest

Retrieve the most recent stream frame from disk and return it as base64 for LLM context input. Use this to obtain pixel data only when necessary.

Instructions

Read the most recent frame of a stream from disk and return it as base64. Use sparingly - this is the path that actually puts pixels into the LLM context.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYes

Implementation Reference

  • The handler for the stream_latest tool. It extracts the 'id' argument, calls snapshotStream to get the last frame, reads the file from disk, encodes it as base64, and returns an image content item with metadata.
    case "stream_latest": {
      const id = strArg(args, "id");
      const snap = snapshotStream(id, { lastN: 1 });
      if (!snap) return text({ error: `Unknown stream id: ${id}` });
      const last = snap.frames.at(-1);
      if (!last) return text({ id, message: "no frames yet" });
      const buf = await readFile(last.filePath);
      const base64 = buf.toString("base64");
      return {
        content: [
          {
            type: "image",
            data: base64,
            mimeType: mimeFor(last.format),
          },
          { type: "text", text: JSON.stringify({ id, frame: last }, null, 2) },
        ],
      };
    }
  • Schema and registration for the stream_latest tool. Defines the 'id' (string, required) input parameter and the description that it reads the most recent stream frame from disk and returns it as base64.
    {
      name: "stream_latest",
      description:
        "Read the most recent frame of a stream from disk and return it as base64. Use sparingly - this is the path that actually puts pixels into the LLM context.",
      inputSchema: {
        type: "object",
        required: ["id"],
        properties: {
          id: { type: "string" },
        },
      },
  • src/index.ts:37-164 (registration)
    Tool registration in the ListToolsRequestSchema handler, which declares all tools including stream_latest.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        {
          name: "screenshot",
          description:
            "Capture a single screenshot of the desktop. Persists the file to disk and " +
            "optionally returns a base64 payload. Set cursorRadius>0 to crop a square " +
            "region around the mouse cursor instead of the full screen.",
          inputSchema: {
            type: "object",
            properties: {
              cursorRadius: {
                type: "integer",
                description: "If >0, crop a square of (2*radius)x(2*radius) px centered on the cursor. 0 = full screen.",
                default: 0,
              },
              format: { type: "string", enum: ["png", "jpeg", "webp"], default: "jpeg" },
              quality: { type: "integer", minimum: 1, maximum: 100, default: 82 },
              maxEdge: {
                type: "integer",
                description: "Resize the longest edge to this many pixels. 0 disables resizing. " +
                  "Default 2400 for full screen; with cursorRadius>0 the cursor crop is kept at native resolution unless overridden.",
              },
              display: {
                type: "integer",
                description: "Optional display index for multi-monitor setups (omit for primary).",
              },
              includeBase64: {
                type: "boolean",
                description: "If true, include the image bytes inline in the response. Default true.",
                default: true,
              },
            },
          },
        },
        {
          name: "cursor_info",
          description:
            "Return the current mouse cursor position, the foreground window title, and the " +
            "title of the window directly under the cursor (Windows only; other platforms " +
            "report position only when available).",
          inputSchema: { type: "object", properties: {} },
        },
        {
          name: "stream_start",
          description:
            "Start a periodic capture session. Saves frames to disk every intervalSeconds " +
            "for at most durationSeconds, keeping the last ringCapacity frames in memory. " +
            "Returns a session id used by stream_status / stream_latest / stream_stop. " +
            "Streams default to disk-only to keep LLM context lean - call stream_latest " +
            "with includeBase64=true when you actually want to look at a frame.",
          inputSchema: {
            type: "object",
            required: ["intervalSeconds", "durationSeconds"],
            properties: {
              intervalSeconds: {
                type: "number",
                minimum: 0.25,
                description: "Seconds between frames. Minimum 0.25.",
              },
              durationSeconds: {
                type: "number",
                minimum: 0.25,
                description: "Total duration of the stream in seconds.",
              },
              cursorRadius: { type: "integer", default: 0 },
              format: { type: "string", enum: ["png", "jpeg", "webp"], default: "jpeg" },
              quality: { type: "integer", minimum: 1, maximum: 100, default: 72 },
              maxEdge: {
                type: "integer",
                description: "Longest edge in px. Default 1920 for full-screen frames; cursor crops keep native resolution unless overridden.",
              },
              ringCapacity: {
                type: "integer",
                description: "Maximum number of recent frames kept in memory. Older frames are evicted (still on disk).",
                default: 60,
              },
            },
          },
        },
        {
          name: "stream_status",
          description: "Snapshot of a running or finished stream session - frame count, time remaining, last frames metadata.",
          inputSchema: {
            type: "object",
            required: ["id"],
            properties: {
              id: { type: "string" },
              lastN: { type: "integer", default: 8 },
            },
          },
        },
        {
          name: "stream_latest",
          description:
            "Read the most recent frame of a stream from disk and return it as base64. Use sparingly - this is the path that actually puts pixels into the LLM context.",
          inputSchema: {
            type: "object",
            required: ["id"],
            properties: {
              id: { type: "string" },
            },
          },
        },
        {
          name: "stream_stop",
          description: "Stop a running stream early. Frames already on disk remain.",
          inputSchema: {
            type: "object",
            required: ["id"],
            properties: { id: { type: "string" } },
          },
        },
        {
          name: "stream_list",
          description: "List active and completed stream sessions known to this process.",
          inputSchema: { type: "object", properties: {} },
        },
        {
          name: "stream_drop",
          description: "Forget a finished stream session (frees its in-memory ring; on-disk files are preserved).",
          inputSchema: {
            type: "object",
            required: ["id"],
            properties: { id: { type: "string" } },
          },
        },
      ],
  • The snapshotStream helper function used by stream_latest. It retrieves a stream session by ID, extracts the last N frames (here N=1), and returns their metadata without base64 payloads (since the handler reads from disk directly).
    export function snapshotStream(
      id: string,
      options: { withBase64?: boolean; lastN?: number } = {}
    ): (StreamSnapshot & { latestBase64?: string }) | null {
      const sess = sessions.get(id);
      if (!sess) return null;
      const lastN = options.lastN ?? Math.min(8, sess.frames.length);
      const slice = sess.frames.slice(-lastN);
      const summary: StreamSnapshot = {
        id: sess.id,
        startedAt: sess.startedAt,
        done: sess.done,
        remainingMs: Math.max(0, sess.stopAt - Date.now()),
        frameCount: sess.frames.length,
        capacity: sess.capacity,
        intervalMs: sess.intervalMs,
        error: sess.error,
        frames: slice.map(({ base64, ...rest }) => rest),
      };
      if (options.withBase64 && slice.length > 0) {
        /* Most recent frame only - re-reading from disk avoids holding base64 in
         * the session object itself. */
        return { ...summary, latestBase64: undefined };
      }
      return summary;
    }
  • The mimeFor helper function used to determine the MIME type for the image response based on the frame's format.
    function mimeFor(format: string): string {
      if (format === "png") return "image/png";
      if (format === "webp") return "image/webp";
      return "image/jpeg";
    }
Behavior3/5

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

With no annotations, the description carries the full burden. It discloses a read operation from disk and warns about cost (pixels into context). However, it does not mention error conditions (e.g., nonexistent stream), authentication requirements, or the specific behavior of returning the latest frame. Adequate but not comprehensive.

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?

Two sentences, front-loaded with the core action, followed by a succinct usage note. Every word adds value; no redundant or extraneous content.

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

Completeness3/5

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

Given the simplicity (1 param, no output schema), the description covers the basic purpose and a cost warning. However, it omits prerequisites (e.g., active stream), error handling, or relationship to sibling tools (e.g., stream_start). Leaves some context gaps for an AI agent.

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?

The single parameter 'id' has no description in the schema (0% coverage). The description only adds 'of a stream', implying the stream identifier but not clarifying the format or how to obtain it. This is minimal improvement over the bare schema.

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 ('Read the most recent frame'), the resource ('of a stream'), and the output format ('return it as base64'). This differentiates from sibling tools like 'stream_list' (list streams) and 'screenshot' (capture screen), establishing a distinct purpose.

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

Usage Guidelines3/5

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

The advice to 'Use sparingly' hints at cost or resource intensity but does not explicitly specify when to use this tool versus alternatives (e.g., screenshot, cursor_info). No direct comparison with siblings is provided, leaving usage context somewhat vague.

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/beekamai/mcp-screenshot'

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