Skip to main content
Glama

test_rule

Test Autoconsent rules on specific URLs to verify consent management platform functionality in a real browser environment.

Instructions

Tests the given Autoconsent rule on the given URL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL to navigate to
ruleYesAutoconsent rule (AutoConsentCMPRule)

Implementation Reference

  • The core handler function for the 'test_rule' tool. It sets up the page, injects the autoconsent script, navigates to the URL, handles messages from the content script, and returns test results including errors, CMP detection, popup findings, and opt-out results.
    export async function testRule(
      page: Page,
      url: string,
      rule: AutoConsentCMPRule,
      { viewportWidth = 1280, viewportHeight = 720 }: TestRuleSettings = {},
    ): Promise<TestRuleResults> {
      // Set viewport
      await page.setViewport({ width: viewportWidth, height: viewportHeight });
    
      // Reset browser data - clear cookies, cache, and storage
      await resetBrowserData(page);
    
      const messages: ContentScriptMessage[] = [];
    
      async function messageCallback(message: ContentScriptMessage) {
        messages.push(message);
    
        switch (message.type) {
          case "init": {
            await page.evaluate(
              `autoconsentReceiveMessage(${JSON.stringify({
                type: "initResp",
                rules: {
                  autoconsent: [rule],
                },
                config: {
                  enabled: true,
                  autoAction: "optOut",
                  disabledCmps: [],
                  enablePrehide: true,
                  detectRetries: 20,
                  enableCosmeticRules: true,
                },
              })})`,
            );
            break;
          }
          case "eval": {
            const result = await page.evaluate(message.code);
            await page.evaluate(
              `autoconsentReceiveMessage(${JSON.stringify({
                id: message.id,
                type: "evalResp",
                result: result,
              })})`,
            );
            break;
          }
        }
      }
    
      await page.exposeFunction("autoconsentSendMessage", messageCallback);
    
      await page.goto(url, {
        waitUntil: "domcontentloaded",
      });
    
      await injectAutoconsent(page);
      page.frames().forEach(injectAutoconsent);
      // page.on("framenavigated", injectAutoconsent);
    
      await new Promise((resolve) => setTimeout(resolve, 5000));
    
      const results = {
        errors: messages.filter((msg) => msg.type === "autoconsentError"),
        cmpDetectedMessage: messages.find((msg) => msg.type === "cmpDetected"),
        popupFoundMessage: messages.find((msg) => msg.type === "popupFound"),
        optOutResultMessage: messages.find((msg) => msg.type === "optOutResult"),
      };
    
      await page.removeExposedFunction("autoconsentSendMessage");
    
      return results;
    }
  • TypeScript type definitions for the input settings (TestRuleSettings) and output results (TestRuleResults) used by the testRule handler.
    type TestRuleSettings = {
      viewportWidth?: number;
      viewportHeight?: number;
    };
    
    type TestRuleResults = {
      errors: ErrorMessage[];
      cmpDetectedMessage?: DetectedMessage;
      popupFoundMessage?: FoundMessage;
      optOutResultMessage?: OptOutResultMessage;
    };
  • src/index.ts:128-142 (registration)
    Registration of the 'test_rule' tool in the TOOLS array, defining its name, description, and input schema for MCP tool listing.
    {
      name: "test_rule",
      description: "Tests the given Autoconsent rule on the given URL",
      inputSchema: {
        type: "object",
        properties: {
          url: { type: "string", description: "URL to navigate to" },
          rule: {
            type: "object",
            description: "Autoconsent rule (AutoConsentCMPRule)",
          },
        },
        required: ["url", "rule"],
      },
    },
  • MCP tool dispatcher case for 'test_rule' that calls the testRule function and formats the results into text output for the MCP response.
    case "test_rule":
      try {
        const rule = args.rule as AutoConsentCMPRule;
        const results = await testRule(page, args.url, rule);
    
        let output = `Test results for rule "${rule.name}" on ${args.url}:\n\n`;
    
        if (results.errors.length > 0) {
          output += `Errors:\n${results.errors.map((err) => JSON.stringify(err, null, 2)).join("\n")}\n\n`;
        }
    
        if (results.cmpDetectedMessage) {
          output += `CMP Detected: ${JSON.stringify(results.cmpDetectedMessage, null, 2)}\n\n`;
        }
    
        if (results.popupFoundMessage) {
          output += `Popup Found: ${JSON.stringify(results.popupFoundMessage, null, 2)}\n\n`;
        }
    
        if (results.optOutResultMessage) {
          output += `Opt-out Result: ${JSON.stringify(results.optOutResultMessage, null, 2)}\n\n`;
        }
    
        return {
          content: [
            {
              type: "text",
              text: output,
            },
          ],
          isError: false,
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Failed to test rule: ${(error as Error).message}`,
            },
          ],
          isError: true,
        };
      }
  • Helper function to inject the autoconsent Playwright script into the page or frame.
    async function injectAutoconsent(page: Page | Frame) {
      const autoconsentPath = path.resolve(
        __dirname,
        "../../node_modules/@duckduckgo/autoconsent/dist/autoconsent.playwright.js",
      );
      const autoconsentScript = fs.readFileSync(autoconsentPath, "utf8");
      await page.evaluate(autoconsentScript);
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure but offers minimal information. It mentions testing an Autoconsent rule on a URL but doesn't describe what happens during testing (e.g., whether it simulates user interaction, returns success/failure, or has side effects like navigation). This leaves significant gaps in understanding the tool's behavior.

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, efficient sentence that directly states the tool's function without any unnecessary words. It is front-loaded and appropriately sized for its purpose, making it easy to parse quickly.

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 of testing rules on URLs, the lack of annotations, and no output schema, the description is insufficient. It doesn't explain what the tool returns (e.g., test results, errors) or any behavioral details like error handling or performance implications. This leaves the agent with incomplete context for effective use.

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

Parameters3/5

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

The schema description coverage is 100%, so the schema already documents both parameters ('url' and 'rule') adequately. The description adds no additional meaning beyond what the schema provides, such as explaining what an 'Autoconsent rule' entails or how the URL is used. This meets the baseline for high schema coverage but doesn't enhance parameter understanding.

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

Purpose4/5

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

The description clearly states the tool's purpose with specific verbs ('Tests') and resources ('Autoconsent rule', 'URL'), making it easy to understand what the tool does. However, it doesn't differentiate this tool from its siblings (like 'evaluate' or 'click'), which prevents a perfect score.

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 guidance on when to use this tool versus alternatives like 'evaluate' or 'click', nor does it mention any prerequisites or contextual constraints. It simply states what the tool does without indicating appropriate usage scenarios.

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/noisysocks/autoconsent-mcp'

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