Skip to main content
Glama

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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 }; } );
  • 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", {},
  • getState(): Returns structuredClone of globalState, which provides the messages array processed by the get-context handler.
    const getState = () => { return structuredClone(globalState); }
  • 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); }

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/qabyai/playwright-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server