Skip to main content
Glama

get-context-stats

Retrieve browser usage statistics to monitor development activity and track specific browser performance within the Vite MCP Server environment.

Instructions

Gets usage statistics for browsers

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contextIdNoSpecific browser ID (returns stats for all browsers if not specified)

Implementation Reference

  • Registers the 'get-context-stats' MCP tool, including input schema (optional contextId) and the handler function that calls ContextManager.getContextStats() to compute and return statistics.
      'get-context-stats',
      'Gets usage statistics for browsers',
      {
        contextId: z.string().optional().describe('Specific browser ID (returns stats for all browsers if not specified)')
      },
      async ({ contextId }) => {
        try {
          const stats = contextManager.getContextStats(contextId);
    
          // Include shared browser information
          const sharedBrowserInfo = contextManager.getSharedBrowserInfo();
          
          const result = {
            totalBrowsers: contextManager.getContextCount(),
            maxBrowsers: contextManager.getMaxContexts(),
            statistics: stats,
            sharedBrowser: sharedBrowserInfo ? {
              type: sharedBrowserInfo.type,
              createdAt: sharedBrowserInfo.createdAt,
              contextCount: sharedBrowserInfo.contextCount,
              cdpEndpoint: sharedBrowserInfo.cdpEndpoint
            } : null
          };
    
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(result, null, 2)
              }
            ]
          };
        } catch (error) {
          const errorMessage = error instanceof Error ? error.message : String(error);
          Logger.error('Failed to get browser stats:', error);
          return {
            content: [
              {
                type: 'text',
                text: `Failed to get browser stats: ${errorMessage}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • Core handler logic in ContextManager that computes ContextStats for specified or all contexts, calculating uptime and placeholders for other metrics.
    getContextStats(contextId?: string): ContextStats[] {
      const contexts = contextId 
        ? [this.contexts.get(contextId)].filter(Boolean) as ContextInstance[]
        : Array.from(this.contexts.values());
    
      return contexts.map(context => ({
        contextId: context.id,
        type: context.type,
        displayName: context.displayName,
        uptime: Date.now() - context.createdAt.getTime(),
        totalPages: 1, // TODO: Track actual page count
        totalScreenshots: 0, // TODO: Integrate with screenshot system
        totalLogs: 0, // TODO: Integrate with log system
        lastActivity: context.lastUsedAt
      }));
    }
  • Type definition for ContextStats returned by the tool's core logic.
    export interface ContextStats {
      contextId: string;
      type: BrowserType;
      displayName?: string;
      uptime: number; // milliseconds
      totalPages: number;
      totalScreenshots: number;
      totalLogs: number;
      lastActivity: Date;
    }
  • Zod input schema for the tool, allowing optional contextId parameter.
      contextId: z.string().optional().describe('Specific browser ID (returns stats for all browsers if not specified)')
    },
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states what the tool does but lacks critical details: it doesn't specify the format of the returned statistics, whether it's read-only or has side effects, or any performance considerations like rate limits. This leaves significant gaps in understanding the tool's behavior.

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 directly states the tool's purpose without any unnecessary words. It's front-loaded and efficiently communicates the core functionality, making it highly concise and well-structured.

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 lack of annotations and output schema, the description is incomplete. It doesn't explain what 'usage statistics' entail (e.g., metrics like page views, session duration), the return format, or how to interpret results. For a tool with no structured output documentation, this leaves the agent with insufficient context to use it effectively.

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

Parameters3/5

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

The input schema has 100% description coverage, with the parameter 'contextId' well-documented in the schema itself. The description adds no additional parameter information beyond what the schema provides, so it meets the baseline score of 3 for adequate but not enhanced parameter semantics.

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?

The description clearly states the verb ('Gets') and resource ('usage statistics for browsers'), making the purpose immediately understandable. It doesn't explicitly differentiate from sibling tools like 'get-context-info' or 'list-browsers', which might provide related information, so it doesn't reach the highest score for sibling differentiation.

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?

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'get-context-info' and 'list-browsers' available, there's no indication of how this tool differs in context or functionality, leaving the agent to guess based on tool names alone.

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/ESnark/blowback'

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