Skip to main content
Glama

playwright_patch

Send HTTP PATCH requests to update partial data on web pages through browser automation, enabling targeted modifications without full page reloads.

Instructions

Perform an HTTP PATCH request

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL to perform PUT operation
valueYesData to PATCH in the body

Implementation Reference

  • The PatchRequestTool class provides the core handler logic for the "playwright_patch" tool. It performs an HTTP PATCH request to the specified URL with the provided data using Playwright's APIRequestContext, handles JSON validation, captures the response, and formats the output.
    export class PatchRequestTool extends ApiToolBase {
      /**
       * Execute the PATCH request tool
       */
      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: string;
          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 ? "..." : ""}`,
          ]);
        });
      }
    }
  • Defines the input schema and metadata for the "playwright_patch" tool as part of the tool definitions returned by createToolDefinitions().
    {
      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"],
      },
    },
  • Registers and dispatches the "playwright_patch" tool call to the PatchRequestTool instance in the main handleToolCall switch statement.
    case "playwright_patch":
      return await patchRequestTool.execute(args, context);
  • Instantiates the PatchRequestTool instance during tool initialization in initializeTools().
    if (!putRequestTool) putRequestTool = new PutRequestTool(server);
    if (!patchRequestTool) patchRequestTool = new PatchRequestTool(server);
    if (!deleteRequestTool) deleteRequestTool = new DeleteRequestTool(server);
  • Base class for API tools providing safeExecute method used by PatchRequestTool for error handling and API context validation.
    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}`);
        }
      }
    }
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 only states the HTTP method. It doesn't describe what the tool actually does (e.g., sends a PATCH request to a URL with data, returns a response), potential side effects, authentication needs, error handling, or rate limits. This is inadequate for a mutation tool with zero annotation coverage.

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 with zero waste. It's appropriately sized and front-loaded, though its brevity contributes to the lack of detail in other dimensions.

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 tool's complexity (HTTP mutation with 2 parameters), lack of annotations, and no output schema, the description is incomplete. It fails to explain what the tool does beyond the HTTP verb, what to expect in return, or behavioral traits, leaving significant gaps for agent understanding.

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%, with both parameters ('url' and 'value') clearly documented in the schema. The description adds no additional meaning beyond what the schema provides, such as format examples or constraints. Baseline 3 is appropriate since the schema does the heavy lifting.

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

Purpose2/5

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

The description 'Perform an HTTP PATCH request' is tautological with the tool name 'playwright_patch' and merely restates the HTTP method without specifying what resource or action it applies to. It doesn't distinguish from siblings like playwright_put or playwright_post beyond the HTTP method name.

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?

No guidance is provided on when to use this tool versus alternatives like playwright_put or playwright_post. The description lacks context about typical PATCH use cases (e.g., partial updates) or prerequisites, leaving the agent to infer usage from the HTTP method alone.

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/aakashH242/mcp-playwright'

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