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
| Name | Required | Description | Default |
|---|---|---|---|
| contextId | No | Specific browser ID (returns stats for all browsers if not specified) |
Implementation Reference
- src/tools/browser-manager-tools.ts:288-334 (registration)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 }; } } );
- src/managers/context-manager.ts:330-345 (handler)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 })); }
- src/types/browser.ts:80-89 (schema)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)') },