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)') },

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