get-context-info
Retrieve detailed information for a browser instance using its context ID. Inspect browser state, attributes, and properties to aid debugging or monitoring in real-time.
Instructions
Gets detailed information about a specific browser instance
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contextId | Yes | ID of the browser to inspect |
Implementation Reference
- src/tools/browser-manager-tools.ts:219-284 (registration)Registration of the 'get-context-info' tool via server.tool(), defining its schema (contextId: z.string()) and binding it to the handler function.
// Get browser info tool server.tool( 'get-context-info', 'Gets detailed information about a specific browser instance', { contextId: z.string().describe('ID of the browser to inspect') }, async ({ contextId }) => { try { const browser = contextManager.getContext(contextId); if (!browser) { return { content: [ { type: 'text', text: `Browser not found: ${contextId}` } ], isError: true }; } // Get shared browser info for CDP endpoint const sharedBrowserInfo = contextManager.getSharedBrowserInfo(); const browserInfo = { id: browser.id, type: browser.type, displayName: browser.displayName, metadata: browser.metadata, createdAt: browser.createdAt, lastUsedAt: browser.lastUsedAt, isActive: contextManager.hasContext(contextId), currentUrl: browser.page.url(), sharedBrowser: sharedBrowserInfo ? { type: sharedBrowserInfo.type, createdAt: sharedBrowserInfo.createdAt, contextCount: sharedBrowserInfo.contextCount, cdpEndpoint: sharedBrowserInfo.cdpEndpoint } : null }; return { content: [ { type: 'text', text: JSON.stringify(browserInfo, null, 2) } ] }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); Logger.error(`Failed to get browser info for ${contextId}:`, error); return { content: [ { type: 'text', text: `Failed to get browser info: ${errorMessage}` } ], isError: true }; } } ); - Handler function that retrieves browser context info using contextManager.getContext(), gets shared browser info, and returns a JSON response with id, type, displayName, metadata, timestamps, isActive, currentUrl, and shared browser details.
async ({ contextId }) => { try { const browser = contextManager.getContext(contextId); if (!browser) { return { content: [ { type: 'text', text: `Browser not found: ${contextId}` } ], isError: true }; } // Get shared browser info for CDP endpoint const sharedBrowserInfo = contextManager.getSharedBrowserInfo(); const browserInfo = { id: browser.id, type: browser.type, displayName: browser.displayName, metadata: browser.metadata, createdAt: browser.createdAt, lastUsedAt: browser.lastUsedAt, isActive: contextManager.hasContext(contextId), currentUrl: browser.page.url(), sharedBrowser: sharedBrowserInfo ? { type: sharedBrowserInfo.type, createdAt: sharedBrowserInfo.createdAt, contextCount: sharedBrowserInfo.contextCount, cdpEndpoint: sharedBrowserInfo.cdpEndpoint } : null }; return { content: [ { type: 'text', text: JSON.stringify(browserInfo, null, 2) } ] }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); Logger.error(`Failed to get browser info for ${contextId}:`, error); return { content: [ { type: 'text', text: `Failed to get browser info: ${errorMessage}` } ], isError: true }; } } - Input schema for the tool: requires a 'contextId' string parameter used to identify which browser context to inspect.
{ contextId: z.string().describe('ID of the browser to inspect') }, - ContextManager.getContext() method used by the handler to look up a context instance by ID, updating lastUsedAt timestamp and database on access.
getContext(contextId: string): ContextInstance | null { const contextInstance = this.contexts.get(contextId); if (contextInstance) { contextInstance.lastUsedAt = new Date(); // Update database timestamp const db = getScreenshotDB(); db.updateBrowserLastUsed(contextId); // TODO: rename to updateContextLastUsed } return contextInstance || null; } - ContextManager.getSharedBrowserInfo() method used by the handler to retrieve shared browser details (type, createdAt, contextCount, cdpEndpoint).
getSharedBrowserInfo(): SharedBrowserInstance | null { return this.sharedBrowser; }