get-context
Capture website context for generating accurate test cases by accessing DOM structure, page elements, and interaction data through browser automation.
Instructions
Get the website context which would be used to write the testcase
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mcp/index.ts:235-312 (handler)The main execution logic for the 'get-context' tool. Retrieves posthog event, fetches global state via getState(), processes messages sequentially by type (DOM/Text prefixed, Interaction JSON parsed and truncated, Image as-is), accumulates content up to 20k chars total, constructs response content array (text or image), splices processed messages from state, updates state via updateState(), appends note if remaining messages exist.async () => { posthogServer.capture({ distinctId: getUserId(), event: 'get_context', }); const state = getState(); if (state.messages.length === 0) { return { content: [ { type: "text", text: `No messages available` } ] }; } const content: any = []; let totalLength = 0; let messagesProcessed = 0; while (messagesProcessed < state.messages.length && totalLength < 20000) { const message = state.messages[messagesProcessed]; let currentContent = message.content if (message.type === 'DOM') { currentContent = `DOM: ${message.content}`; } else if (message.type === 'Text') { currentContent = `Text: ${message.content}`; } else if (message.type === 'Interaction') { const interaction = JSON.parse(message.content); delete interaction.eventId; delete interaction.dom; delete interaction.elementUUID; if (interaction.selectors) { interaction.selectors = interaction.selectors.slice(0, 10); } currentContent = JSON.stringify(interaction); } else if (message.type === 'Image') { currentContent = message.content; } totalLength += currentContent.length; const item: any = {} const isImage = message.type === 'Image'; if (isImage) { item.type = "image"; item.data = message.content; item.mimeType = "image/png"; } else { item.type = "text"; item.text = currentContent; } content.push(item); messagesProcessed++; } // Remove processed messages state.messages.splice(0, messagesProcessed); updateState(page, state); const remainingCount = state.messages.length; if (remainingCount > 0) { content.push({ type: "text", text: `Remaining ${remainingCount} messages, please fetch those in next requests.\n` }); } return { content }; } );
- src/mcp/index.ts:231-234 (registration)Registers the 'get-context' MCP tool via server.tool() with name, description 'Get the website context which would be used to write the testcase', and empty input schema {}.server.tool( "get-context", "Get the website context which would be used to write the testcase", {},
- src/mcp/state.ts:57-59 (helper)getState(): Returns structuredClone of globalState, which provides the messages array processed by the get-context handler.const getState = () => { return structuredClone(globalState); }
- src/mcp/state.ts:61-64 (helper)updateState(page, state): Updates the globalState with new state and syncs it to the React toolbox frame via page frame evaluation.const updateState = (page: Page, state: typeof globalState) => { globalState = structuredClone(state); syncToReact(page, state); }