Skip to main content
Glama
devskido

Playwright MCP Server

by devskido

playwright_assert_response

Validate a previously initiated HTTP response by matching its identifier and optional body content, ensuring accuracy in automated web interactions.

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 execution logic for the playwright_assert_response tool. It retrieves the stored response promise, awaits the response, optionally validates the body contains a specific value, and returns success or error 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); } }); } }
  • Input schema definition for the playwright_assert_response tool, specifying parameters id (required) and optional value.
    { 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 registration in the main handleToolCall switch statement, routing calls to the AssertResponseTool.execute method.
    return await expectResponseTool.execute(args, context); case "playwright_assert_response": return await assertResponseTool.execute(args, context);
  • Instantiation of the global AssertResponseTool instance during tool initialization.
    if (!assertResponseTool) assertResponseTool = new AssertResponseTool(server);
  • Shared Map storing response promises keyed by id, used by both expect and assert tools.
    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); } }); } }

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/devskido/customed-playwright'

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