playwright_delete
Send HTTP DELETE requests to remove resources from web applications using browser automation. Specify the target URL to delete data or clear content programmatically.
Instructions
Perform an HTTP DELETE request
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | URL to perform DELETE operation |
Implementation Reference
- src/tools/api/requests.ts:153-175 (handler)DeleteRequestTool class implements the core logic for the 'playwright_delete' tool. It performs an HTTP DELETE request using Playwright's APIRequestContext.delete(), handles response text, and formats the success response with status and truncated body.export class DeleteRequestTool extends ApiToolBase { /** * Execute the DELETE request tool */ async execute(args: any, context: ToolContext): Promise<ToolResponse> { return this.safeExecute(context, async (apiContext) => { const response = await apiContext.delete(args.url); let responseText: string; try { responseText = await response.text(); } catch (_error) { responseText = "Unable to get response text"; } return createSuccessResponse([ `DELETE request to ${args.url}`, `Status: ${response.status()} ${response.statusText()}`, `Response: ${responseText.substring(0, 1000)}${responseText.length > 1000 ? "..." : ""}`, ]); }); } }
- src/tools.ts:326-336 (schema)Tool metadata definition including name, description, and input schema (requires 'url' string) for MCP protocol tool listing and validation.{ name: "playwright_delete", description: "Perform an HTTP DELETE request", inputSchema: { type: "object", properties: { url: { type: "string", description: "URL to perform DELETE operation" }, }, required: ["url"], }, },
- src/toolHandler.ts:637-638 (registration)Dispatch switch case in handleToolCall that routes 'playwright_delete' calls to the DeleteRequestTool instance's execute method.case "playwright_delete": return await deleteRequestTool.execute(args, context);
- src/toolHandler.ts:411-411 (registration)Instantiation of DeleteRequestTool instance during tool initialization in initializeTools function.if (!deleteRequestTool) deleteRequestTool = new DeleteRequestTool(server);
- src/tools/api/base.ts:1-64 (helper)ApiToolBase abstract class provides common API context validation, error handling, and safeExecute wrapper used by DeleteRequestTool.import type { APIRequestContext } from "playwright"; import { createErrorResponse, type ToolContext, type ToolHandler, type ToolResponse } from "../common/types.js"; /** * Base class for all API-based tools * Provides common functionality and error handling */ export abstract class ApiToolBase implements ToolHandler { protected server: any; constructor(server: any) { this.server = server; } /** * Main execution method that all tools must implement */ abstract execute(args: any, context: ToolContext): Promise<ToolResponse>; /** * Ensures an API context is available and returns it * @param context The tool context containing apiContext * @returns The apiContext or null if not available */ protected ensureApiContext(context: ToolContext): APIRequestContext | null { if (!context.apiContext) { return null; } return context.apiContext; } /** * Validates that an API context is available and returns an error response if not * @param context The tool context * @returns Either null if apiContext is available, or an error response */ protected validateApiContextAvailable(context: ToolContext): ToolResponse | null { if (!this.ensureApiContext(context)) { return createErrorResponse("API context not initialized"); } return null; } /** * Safely executes an API operation with proper error handling * @param context The tool context * @param operation The async operation to perform * @returns The tool response */ protected async safeExecute( context: ToolContext, operation: (apiContext: APIRequestContext) => Promise<ToolResponse>, ): Promise<ToolResponse> { const apiError = this.validateApiContextAvailable(context); if (apiError) return apiError; try { return await operation(context.apiContext!); } catch (error) { return createErrorResponse(`API operation failed: ${(error as Error).message}`); } } }