Skip to main content
Glama

get_session_snapshot

Get a real-time diagnostic snapshot of the current dev environment, including health diagnosis, running services, recent errors, git state, and environment info. Use this to orient yourself in the user's dev session.

Instructions

Returns a real-time diagnostic snapshot of the current dev environment. Includes health diagnosis, running services, recent errors, git state, and environment info. Call this first to orient yourself in the user's dev session.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cwdNo

Implementation Reference

  • Main handler function that collects and returns a full diagnostic snapshot of the dev environment: framework detection, runtimes, running services, recent errors, git state, and diagnosis.
    export async function getSessionSnapshot(cwd: string): Promise<SessionSnapshot> {
      const baseProject = path.basename(cwd);
      try {
        const frameworkPromise = detectFramework(cwd);
        const runtimesPromise = detectRuntimes(cwd);
        const servicesPromise = frameworkPromise.then((framework) =>
          getRunningServices(framework.expectedPorts)
        );
        const errorsPromise = frameworkPromise.then((framework) =>
          getRecentErrors(cwd, framework.logPaths, 50)
        );
    
        const [frameworkResult, runtimesResult, servicesResult, errorsResult] =
          await Promise.allSettled([
            frameworkPromise,
            runtimesPromise,
            servicesPromise,
            errorsPromise,
          ]);
    
        const framework =
          frameworkResult.status === "fulfilled"
            ? frameworkResult.value
            : { framework: "unknown", expectedPorts: [], logPaths: ["logs/"] };
    
        const runtimes =
          runtimesResult.status === "fulfilled"
            ? runtimesResult.value
            : { node: null, python: null, go: null, packageManager: "unknown" };
    
        const services =
          servicesResult.status === "fulfilled"
            ? servicesResult.value
            : { running: [], expected_but_missing: [] };
    
        const recentErrors = errorsResult.status === "fulfilled" ? errorsResult.value : [];
    
        let branch: string | null = null;
        let uncommittedFiles = 0;
        let lastCommit: string | null = null;
    
        try {
          const git = simpleGit(cwd);
          const [statusResult, logResult] = await Promise.all([
            git.status(),
            git.log({ maxCount: 1 }),
          ]);
    
          branch = statusResult.current || null;
          uncommittedFiles = statusResult.files.length;
          lastCommit = logResult.latest?.hash ?? null;
        } catch {
          branch = null;
          uncommittedFiles = 0;
          lastCommit = null;
        }
    
        const diagnosis = diagnose({
          running: services.running.map((service) => ({
            port: service.port,
            name: service.name,
          })),
          expected_but_missing: services.expected_but_missing,
          recentErrors: recentErrors.map((error) => ({
            level: error.level,
            message: error.message,
          })),
          framework: framework.framework,
        });
    
        const result: SessionSnapshot = {
          diagnosis,
          session: {
            project: baseProject,
            framework: framework.framework,
            branch,
            uncommitted_files: uncommittedFiles,
            last_commit: lastCommit,
          },
          services: {
            running: services.running.map((service) => ({
              port: service.port,
              name: service.name,
            })),
            expected_but_missing: services.expected_but_missing,
          },
          recent_errors: recentErrors.map((error) => ({
            time: error.time,
            level: error.level,
            message: error.message,
          })),
          env: {
            node: runtimes.node,
            python: runtimes.python,
            go: runtimes.go,
            package_manager: runtimes.packageManager,
          },
        };
        return result;
      } catch {
        const result: SessionSnapshot = {
          diagnosis: {
            health: "degraded",
            primary_issue: "Unable to determine environment state",
            secondary_signals: [],
            suggested_action: "Try running get_session_snapshot again",
            confidence: "low",
          },
          session: {
            project: path.basename(cwd),
            framework: "unknown",
            branch: null,
            uncommitted_files: 0,
            last_commit: null,
          },
          services: { running: [], expected_but_missing: [] },
          recent_errors: [],
          env: { node: null, python: null, go: null, package_manager: "unknown" },
        };
        return result;
      }
    }
  • Type definition for the SessionSnapshot return type, with nested interfaces for diagnosis, session, services, recent_errors, and env.
    export interface SessionSnapshot {
      diagnosis: {
        health: "healthy" | "degraded" | "broken";
        primary_issue: string | null;
        secondary_signals: string[];
        suggested_action: string | null;
        confidence: "high" | "medium" | "low";
      };
      session: {
        project: string;
        framework: string;
        branch: string | null;
        uncommitted_files: number;
        last_commit: string | null;
      };
      services: {
        running: Array<{ port: number; name: string }>;
        expected_but_missing: number[];
      };
      recent_errors: Array<{
        time: string;
        level: string;
        message: string;
      }>;
      env: {
        node: string | null;
        python: string | null;
        go: string | null;
        package_manager: string;
      };
    }
  • src/index.ts:28-72 (registration)
    Registration of the tool 'get_session_snapshot' with description and input schema (cwd string parameter).
      tools: [
        {
          name: "get_session_snapshot",
          description:
            "Returns a real-time diagnostic snapshot of the current dev environment. Includes health diagnosis, running services, recent errors, git state, and environment info. Call this first to orient yourself in the user's dev session.",
          inputSchema: {
            type: "object",
            properties: {
              cwd: {
                type: "string",
              },
            },
          },
        },
        {
          name: "get_recent_errors",
          description:
            "Returns recent ERROR and WARN log entries from the detected project's log files. Deduped, timestamped, secrets redacted. Defaults to last 50 lines.",
          inputSchema: {
            type: "object",
            properties: {
              cwd: {
                type: "string",
              },
              limit: {
                type: "number",
              },
            },
          },
        },
        {
          name: "get_running_services",
          description:
            "Lists processes running on common dev ports (3000, 4000, 5173, 8080 etc). Shows what is running and what is expected but missing.",
          inputSchema: {
            type: "object",
            properties: {
              cwd: {
                type: "string",
              },
            },
          },
        },
      ],
    };
  • The call handler in index.ts that dispatches to getSessionSnapshot when the tool is invoked, with error handling.
    if (toolName === "get_session_snapshot") {
      try {
        const args = request.params.arguments as { cwd?: string } | undefined;
        const cwd = args?.cwd ?? process.cwd();
        const result = await getSessionSnapshot(cwd);
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({
                error: `Failed to get session snapshot: ${String(error)}`,
              }),
            },
          ],
        };
      }
  • Diagnosis engine used by getSessionSnapshot to determine health status (healthy/degraded/broken) based on running services, port conflicts, and recent errors.
    export function diagnose(input: DiagnosisInput): DiagnosisResult {
      const running = input.running ?? [];
      const missing = input.expected_but_missing ?? [];
      const recentErrors = input.recentErrors ?? [];
    
      const hasAddrInUse = recentErrors.some((error) =>
        error.message.includes("EADDRINUSE")
      );
      const errorEntries = recentErrors.filter(
        (error) => error.level.toUpperCase() === "ERROR"
      );
      const hasErrorLevelEntries = errorEntries.length > 0;
    
      // Pattern 1 — Port conflict (broken)
      if (hasAddrInUse && missing.length > 0) {
        return {
          health: "broken",
          primary_issue: "Port conflict — dev server cannot start",
          secondary_signals: missing.map(
            (port) => `Port ${port} is already in use`
          ),
          suggested_action:
            "Kill the process using that port or change your dev server port",
          confidence: "high",
        };
      }
    
      // Pattern 2 — Dev server crashed (broken)
      if (missing.length > 0 && hasErrorLevelEntries && !hasAddrInUse) {
        return {
          health: "broken",
          primary_issue: "Dev server appears to have crashed",
          secondary_signals: errorEntries.slice(0, 3).map((error) => error.message),
          suggested_action: "Check the error logs and restart your dev server",
          confidence: "medium",
        };
      }
    
      // Pattern 3 — Silent failure (degraded)
      if (missing.length > 0 && recentErrors.length === 0) {
        return {
          health: "degraded",
          primary_issue: "Expected service not running — no recent logs found",
          secondary_signals: missing.map(
            (port) => `Port ${port} expected but nothing is listening`
          ),
          suggested_action: "Start your dev server",
          confidence: "low",
        };
      }
    
      // Pattern 4 — Errors but running (degraded)
      if (running.length > 0 && hasErrorLevelEntries) {
        return {
          health: "degraded",
          primary_issue: "Errors detected but services are still running",
          secondary_signals: errorEntries.slice(0, 3).map((error) => error.message),
          suggested_action:
            "Review the recent errors — the server is up but something is failing",
          confidence: "medium",
        };
      }
    
      // Pattern 5 — Healthy (healthy)
      if (running.length > 0 && recentErrors.length === 0 && missing.length === 0) {
        return {
          health: "healthy",
          primary_issue: null,
          secondary_signals: running.map(
            (service) => `Port ${service.port}: ${service.name}`
          ),
          suggested_action: null,
          confidence: "high",
        };
      }
    
      // Default fallback
      return {
        health: "degraded",
        primary_issue: "Unable to determine environment state",
        secondary_signals: [],
        suggested_action: "Try running get_session_snapshot again",
        confidence: "low",
      };
    }
Behavior4/5

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

No annotations provided, so description carries full burden. It states it returns a snapshot, implying read-only and non-destructive. However, it does not explicitly mention permissions or side effects, though 'snapshot' strongly suggests a safe operation.

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 sentences: first states action, second lists contents, third gives usage advice. No redundancy, every sentence adds value.

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?

Well-structured but lacks parameter documentation. With no output schema, the description lists return categories but omits format details. The missing parameter explanation is a notable gap for a tool with one parameter.

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

Parameters1/5

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

Input schema has one optional parameter 'cwd' with no description and 0% schema coverage. The tool description does not mention this parameter, leaving the agent without guidance on its purpose or usage.

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?

Description clearly states it returns a real-time diagnostic snapshot of the current dev environment, listing specific contents. It distinguishes from siblings get_recent_errors and get_running_services as a broader orientation tool.

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

Usage Guidelines5/5

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

Explicitly instructs to 'Call this first to orient yourself in the user's dev session,' providing clear guidance on when to use this tool versus alternatives.

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/tao-izm/devpulse-mcp'

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