Skip to main content
Glama

get-context

Extract website context for generating accurate test cases by accessing DOM elements and page structure 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 async handler function for the get-context tool. It fetches the current state, processes messages into formatted text or image content (prefixing DOM/Text, parsing and cleaning Interactions, base64 images), accumulates until 20k chars, splices processed from state, updates state, appends remaining note if any, returns content array.
    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' tool with McpServer using server.tool(name, description, inputSchema, handlerFn). Input schema is empty object (no params).
    server.tool(
      "get-context",
      "Get the website context which would be used to write the testcase",
      {},
      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
        };
      }
    );
  • Helper function to get a deep-cloned copy of the global state, which contains the messages array used by get-context handler.
    const getState = () => {
      return structuredClone(globalState);
    }
  • Helper function to update the global state with new state and sync it to the React toolbox iframe via page evaluation.
    const updateState = (page: Page, state: typeof globalState) => {
      globalState = structuredClone(state);
      syncToReact(page, state);
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'Get the website context' but doesn't explain what this entails operationally—e.g., whether it fetches live data, requires browser initialization, has side effects, or returns structured data. This lack of detail makes it hard for an agent to predict behavior beyond a basic read operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence with zero waste. It's front-loaded with the core action ('Get the website context') and purpose ('used to write the testcase'), making it easy to parse quickly. Every word contributes directly to understanding the tool's intent without redundancy or fluff.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity implied by sibling tools (e.g., browser-related operations) and the lack of annotations and output schema, the description is incomplete. It doesn't specify what 'website context' includes (e.g., HTML, cookies, session data) or how it relates to other tools like 'init-browser', leaving gaps in understanding the tool's role and output in the broader workflow.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has 0 parameters, and schema description coverage is 100%, so there are no parameters to document. The description doesn't need to add parameter semantics, and it appropriately doesn't mention any. A baseline of 4 is applied since no parameters exist, and the description doesn't introduce confusion about inputs.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states the tool 'Get[s] the website context which would be used to write the testcase', which provides a clear verb ('Get') and resource ('website context'). However, it's somewhat vague about what 'website context' specifically entails (e.g., DOM, metadata, state) and doesn't distinguish it from sibling tools like 'get-full-dom' or 'get-screenshot', leaving ambiguity about its unique function.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no explicit guidance on when to use this tool versus alternatives. It implies usage for testcase writing but doesn't specify contexts, prerequisites, or exclusions. For example, it doesn't clarify if this is for initial setup, during execution, or how it differs from 'get-full-dom' or 'get-screenshot' in the sibling list, leaving the agent to guess based on tool names alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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