get-context
Extracts website context for generating accurate Playwright test cases by analyzing web page structure and elements.
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-311 (handler)The handler function that implements the 'get-context' tool logic. It retrieves the current state, processes messages (DOM, Text, Interaction, Image), formats them into content blocks (text or image), limits to 20k characters, updates the state by removing processed messages, and returns the content with note on remaining if any.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 with name, description, and empty input schema (no parameters). The handler is provided inline.server.tool( "get-context", "Get the website context which would be used to write the testcase", {},