playwright_patch
Update specific parts of web content by sending HTTP PATCH requests through browser automation, enabling targeted modifications to web resources.
Instructions
Perform an HTTP PATCH request
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | URL to perform PUT operation | |
| value | Yes | Data to PATCH in the body |
Implementation Reference
- src/tools/api/requests.ts:121-150 (handler)The execute method of PatchRequestTool performs the PATCH HTTP request. It validates JSON input if applicable, sends the request via Playwright's APIRequestContext.patch, retrieves the response text, and formats a success response with status and truncated body.
async execute(args: any, context: ToolContext): Promise<ToolResponse> { return this.safeExecute(context, async (apiContext) => { // Check if the value is valid JSON if it starts with { or [ if (args.value && typeof args.value === 'string' && (args.value.startsWith('{') || args.value.startsWith('['))) { try { JSON.parse(args.value); } catch (error) { return createErrorResponse(`Failed to parse request body: ${(error as Error).message}`); } } const response = await apiContext.patch(args.url, { data: args.value }); let responseText; try { responseText = await response.text(); } catch (error) { responseText = "Unable to get response text"; } return createSuccessResponse([ `PATCH request to ${args.url}`, `Status: ${response.status()} ${response.statusText()}`, `Response: ${responseText.substring(0, 1000)}${responseText.length > 1000 ? '...' : ''}` ]); }); } - src/tools.ts:285-295 (schema)Tool schema definition including name, description, and input schema requiring 'url' and 'value' parameters.
name: "playwright_patch", description: "Perform an HTTP PATCH request", inputSchema: { type: "object", properties: { url: { type: "string", description: "URL to perform PUT operation" }, value: { type: "string", description: "Data to PATCH in the body" }, }, required: ["url", "value"], }, }, - src/toolHandler.ts:533-534 (registration)Dispatch/registration in handleToolCall switch statement that routes 'playwright_patch' tool calls to the PatchRequestTool handler.
case "playwright_patch": return await patchRequestTool.execute(args, context); - src/toolHandler.ts:336-340 (registration)Instantiation of PatchRequestTool instance during tool initialization in initializeTools function.
if (!getRequestTool) getRequestTool = new GetRequestTool(server); if (!postRequestTool) postRequestTool = new PostRequestTool(server); if (!putRequestTool) putRequestTool = new PutRequestTool(server); if (!patchRequestTool) patchRequestTool = new PatchRequestTool(server); if (!deleteRequestTool) deleteRequestTool = new DeleteRequestTool(server); - src/tools/api/base.ts:50-62 (helper)The safeExecute helper method in ApiToolBase used by PatchRequestTool to ensure API context is available and handle execution errors.
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}`); } }