Skip to main content
Glama

playwright_assert_response

Validate an expected HTTP response by checking its body content. Use this tool to confirm if the response matches the specified data, ensuring accurate results in browser automation workflows.

Instructions

Wait for and validate a previously initiated HTTP response wait operation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesIdentifier of the HTTP response initially expected using `Playwright_expect_response`.
valueNoData to expect in the body of the HTTP response. If provided, the assertion will fail if this value is not found in the response body.

Implementation Reference

  • The AssertResponseTool class implements the core logic of the tool. Its execute method retrieves a previously stored response promise (from expect_response), awaits the response, parses the JSON body, checks if an optional 'value' is present in the body, and returns a success or error response with details.
    export class AssertResponseTool extends BrowserToolBase {
      /**
       * Execute the assert response tool
       */
      async execute(args: AssertResponseArgs, context: ToolContext): Promise<ToolResponse> {
        return this.safeExecute(context, async () => {
          if (!args.id) {
            return createErrorResponse("Missing required parameter: id must be provided");
          }
    
          const responsePromise = responsePromises.get(args.id);
          if (!responsePromise) {
            return createErrorResponse(`No response wait operation found with ID: ${args.id}`);
          }
    
          try {
            const response = await responsePromise;
            const body = await response.json();
    
            if (args.value) {
              const bodyStr = JSON.stringify(body);
              if (!bodyStr.includes(args.value)) {
                const messages = [
                  `Response body does not contain expected value: ${args.value}`,
                  `Actual body: ${bodyStr}`
                ];
                return createErrorResponse(messages.join('\n'));
              }
            }
    
            const messages = [
              `Response assertion for ID ${args.id} successful`,
              `URL: ${response.url()}`,
              `Status: ${response.status()}`,
              `Body: ${JSON.stringify(body, null, 2)}`
            ];
            return createSuccessResponse(messages.join('\n'));
          } catch (error) {
            return createErrorResponse(`Failed to assert response: ${(error as Error).message}`);
          } finally {
            responsePromises.delete(args.id);
          }
        });
      }
    } 
  • JSON schema defining the input parameters for the tool: required 'id' string and optional 'value' string.
    {
      name: "playwright_assert_response",
      description: "Wait for and validate a previously initiated HTTP response wait operation.",
      inputSchema: {
        type: "object",
        properties: {
          id: { type: "string", description: "Identifier of the HTTP response initially expected using `Playwright_expect_response`." },
          value: { type: "string", description: "Data to expect in the body of the HTTP response. If provided, the assertion will fail if this value is not found in the response body." }
        },
        required: ["id"],
      },
    },
  • Dispatch case in the central handleToolCall switch statement that routes calls to this tool to the AssertResponseTool's execute method.
    case "playwright_assert_response":
      return await assertResponseTool.execute(args, context);
  • src/tools.ts:441-441 (registration)
    The tool name is listed in the BROWSER_TOOLS array, which determines that it requires a browser context during execution.
    "playwright_assert_response",
  • Shared Map storing response promises keyed by 'id', used by both expect_response and assert_response tools to coordinate.
    const responsePromises = new Map<string, Promise<Response>>();
    
    interface ExpectResponseArgs {
      id: string;
      url: string;
    }
    
    interface AssertResponseArgs {
      id: string;
      value?: string;
    }
    
    /**
     * Tool for setting up response wait operations
     */
    export class ExpectResponseTool extends BrowserToolBase {
      /**
       * Execute the expect response tool
       */
      async execute(args: ExpectResponseArgs, context: ToolContext): Promise<ToolResponse> {
        return this.safeExecute(context, async (page) => {
          if (!args.id || !args.url) {
            return createErrorResponse("Missing required parameters: id and url must be provided");
          }
    
          const responsePromise = page.waitForResponse(args.url);
          responsePromises.set(args.id, responsePromise);
    
          return createSuccessResponse(`Started waiting for response with ID ${args.id}`);
        });
      }
    }
    
    /**
     * Tool for asserting and validating responses
     */
    export class AssertResponseTool extends BrowserToolBase {
      /**
       * Execute the assert response tool
       */
      async execute(args: AssertResponseArgs, context: ToolContext): Promise<ToolResponse> {
        return this.safeExecute(context, async () => {
          if (!args.id) {
            return createErrorResponse("Missing required parameter: id must be provided");
          }
    
          const responsePromise = responsePromises.get(args.id);
          if (!responsePromise) {
            return createErrorResponse(`No response wait operation found with ID: ${args.id}`);
          }
    
          try {
            const response = await responsePromise;
            const body = await response.json();
    
            if (args.value) {
              const bodyStr = JSON.stringify(body);
              if (!bodyStr.includes(args.value)) {
                const messages = [
                  `Response body does not contain expected value: ${args.value}`,
                  `Actual body: ${bodyStr}`
                ];
                return createErrorResponse(messages.join('\n'));
              }
            }
    
            const messages = [
              `Response assertion for ID ${args.id} successful`,
              `URL: ${response.url()}`,
              `Status: ${response.status()}`,
              `Body: ${JSON.stringify(body, null, 2)}`
            ];
            return createSuccessResponse(messages.join('\n'));
          } catch (error) {
            return createErrorResponse(`Failed to assert response: ${(error as Error).message}`);
          } finally {
            responsePromises.delete(args.id);
          }
        });
      }
    } 
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. It mentions waiting and validation, but does not disclose behavioral traits such as timeout behavior, error handling, or what happens if validation fails. This leaves significant gaps in understanding the tool's 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, efficient sentence that front-loads the core purpose without unnecessary details. It earns its place by clearly stating the tool's function in a concise manner.

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

Completeness3/5

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

Given no annotations and no output schema, the description provides basic purpose but lacks details on behavior, error cases, or return values. It is minimally adequate for a tool with two parameters and high schema coverage, but could be more complete for validation operations.

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?

Schema description coverage is 100%, so the schema fully documents both parameters. The description does not add any additional meaning beyond what the schema provides, such as examples or context for parameter usage, resulting in a baseline score of 3.

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: 'Wait for and validate a previously initiated HTTP response wait operation.' It specifies the verb (wait for and validate) and resource (HTTP response wait operation), but does not explicitly distinguish it from sibling tools like 'playwright_expect_response' beyond mentioning it as the initiating tool.

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

Usage Guidelines3/5

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

The description implies usage by referencing 'previously initiated HTTP response wait operation' with 'playwright_expect_response,' suggesting it should be used after that tool. However, it does not provide explicit guidance on when to use this versus alternatives or any exclusions, leaving some context to inference.

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

Related 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/BhanuTJ93/MCP'

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