Skip to main content
Glama
carloshpdoc

memorydetective

Stream macOS unified logging for a bounded window

logStream

Collects parsed macOS log entries for a bounded duration (up to 60 seconds) to capture user flows without Console.app setup.

Instructions

[mg.log] Wrap log stream --style compact for a bounded duration (≤60 s — MCP requests should not block longer). Returns parsed entries collected during the window. Useful for capturing a specific user flow without setting up a full Console.app session.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
durationSecNoHow long to listen for log entries (max 60 seconds — MCP requests should not block longer). Default 10.
predicateNo
processNo
subsystemNo
levelNodefault
maxEntriesNo

Implementation Reference

  • Main handler function for the logStream tool. Runs `log stream --style compact` with optional predicate/process/subsystem/level filters for a bounded duration. On timeout (expected), falls back to logStreamWithTimer which spawns directly and collects output until the deadline.
    export async function logStream(input: LogStreamInput): Promise<LogShowResult> {
      const args = ["stream", "--style", "compact"];
      args.push(...levelArgs(input.level ?? "default"));
      const predicate = buildPredicate(input);
      if (predicate) args.push("--predicate", predicate);
    
      // `log stream` runs forever; we kill it after durationSec via the runner's
      // timeout, then parse whatever was collected.
      const ms = (input.durationSec ?? 10) * 1000;
      let result;
      try {
        result = await runCommand("log", args, { timeoutMs: ms });
      } catch (err) {
        // Timeout is expected — collect partial output via a fallback mode.
        // Our runCommand currently throws on timeout; we need a slightly different
        // approach: spawn directly and collect output until the deadline.
        return await logStreamWithTimer(args, ms, input.maxEntries ?? 500);
      }
      const max = input.maxEntries ?? 500;
      const entries = parseLogOutput(result.stdout, max);
      const byType: Record<string, number> = {};
      for (const e of entries) byType[e.type] = (byType[e.type] ?? 0) + 1;
      return {
        ok: true,
        command: `log ${args.join(" ")}`,
        totalParsed: entries.length,
        byType,
        entries,
        truncated: false,
      };
    }
  • Zod schema for logStream input: durationSec (max 60s), predicate, process, subsystem, level, maxEntries.
    export const logStreamSchema = z.object({
      durationSec: z
        .number()
        .int()
        .positive()
        .max(60)
        .default(10)
        .describe(
          "How long to listen for log entries (max 60 seconds — MCP requests should not block longer). Default 10.",
        ),
      predicate: z.string().optional(),
      process: z.string().optional(),
      subsystem: z.string().optional(),
      level: z.enum(["default", "info", "debug"]).default("default"),
      maxEntries: z.number().int().positive().default(500),
    });
  • src/index.ts:383-395 (registration)
    Registration of the 'logStream' tool on the MCP server with title, description, inputSchema, and handler callback.
    server.registerTool(
      "logStream",
      {
        title: "Stream macOS unified logging for a bounded window",
        description:
          "[mg.log] Wrap `log stream --style compact` for a bounded duration (≤60 s — MCP requests should not block longer). Returns parsed entries collected during the window. Useful for capturing a specific user flow without setting up a full Console.app session.",
        inputSchema: logStreamSchema.shape,
      },
      async (input) => {
        const result = await logStream(input);
        return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
      },
    );
  • Fallback helper used when log stream times out: spawns `log` directly, collects stdout for the specified duration, then kills the child and parses collected output.
    async function logStreamWithTimer(
      args: string[],
      ms: number,
      max: number,
    ): Promise<LogShowResult> {
      // Use spawn directly here so we can capture stdout up to the deadline
      // without throwing.
      const { spawn } = await import("node:child_process");
      return new Promise((resolve, reject) => {
        const child = spawn("log", args);
        let stdout = "";
        let stderr = "";
        child.stdout.on("data", (chunk: Buffer) => {
          stdout += chunk.toString("utf8");
        });
        child.stderr.on("data", (chunk: Buffer) => {
          stderr += chunk.toString("utf8");
        });
        child.on("error", reject);
        const timer = setTimeout(() => {
          child.kill("SIGTERM");
        }, ms);
        child.on("close", () => {
          clearTimeout(timer);
          const entries = parseLogOutput(stdout, max);
          const byType: Record<string, number> = {};
          for (const e of entries) byType[e.type] = (byType[e.type] ?? 0) + 1;
          const totalLines = stdout.split(/\r?\n/).filter((l) => l.trim()).length;
          resolve({
            ok: true,
            command: `log ${args.join(" ")}`,
            totalParsed: entries.length,
            byType,
            entries,
            truncated: totalLines > entries.length,
          });
        });
      });
    }
  • runCommand utility used by logStream to spawn the `log` process with timeout support.
    export function runCommand(
      cmd: string,
      args: string[],
      opts: RunCommandOptions = {},
    ): Promise<CommandResult> {
      return new Promise((resolve, reject) => {
        const child = spawn(cmd, args, { cwd: opts.cwd });
        let stdout = "";
        let stderr = "";
        let killedByTimeout = false;
        let timer: NodeJS.Timeout | undefined;
    
        if (opts.timeoutMs && opts.timeoutMs > 0) {
          timer = setTimeout(() => {
            killedByTimeout = true;
            child.kill("SIGTERM");
          }, opts.timeoutMs);
        }
Behavior3/5

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

No annotations provided, so description carries full burden. Discloses bounded duration and non-blocking nature, but lacks details on permissions, side effects, return format, or handling of parameters like maxEntries.

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?

Three concise, front-loaded sentences. No redundant information. Every sentence adds value.

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?

With 6 parameters, no output schema, and no annotations, the description should provide more detail on parameter behavior and return format. It gives a high-level purpose but leaves significant gaps for effective usage.

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 durationSec is described in schema (17% coverage); description does not explain predicate, process, subsystem, level, or maxEntries beyond implying they are log stream options. Fails to compensate for low schema coverage.

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

Purpose4/5

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

Clearly states it wraps `log stream --style compact` for a bounded duration and returns parsed entries. Distinguishes from broader Console.app but not explicitly from sibling tool 'logShow'.

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

Usage Guidelines4/5

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

Provides use case ('capturing a specific user flow') but does not mention when-not or compare to alternatives like logShow.

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/carloshpdoc/memorydetective'

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