Skip to main content
Glama
devskido

Playwright MCP Server

by devskido

playwright_put

Execute an HTTP PUT request to send data to a specified URL, enabling updates or modifications to web resources within a browser automation environment.

Instructions

Perform an HTTP PUT request

Input Schema

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

Implementation Reference

  • The PutRequestTool class containing the execute method that performs the HTTP PUT request using Playwright's APIRequestContext.
    export class PutRequestTool extends ApiToolBase { /** * Execute the PUT 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.put(args.url, { data: args.value }); let responseText; try { responseText = await response.text(); } catch (error) { responseText = "Unable to get response text"; } return createSuccessResponse([ `PUT request to ${args.url}`, `Status: ${response.status()} ${response.statusText()}`, `Response: ${responseText.substring(0, 1000)}${responseText.length > 1000 ? '...' : ''}` ]); }); } }
  • Tool metadata including name, description, and input schema for validation.
    name: "playwright_put", description: "Perform an HTTP PUT request", inputSchema: { type: "object", properties: { url: { type: "string", description: "URL to perform PUT operation" }, value: { type: "string", description: "Data to PUT in the body" }, }, required: ["url", "value"], }, },
  • Switch statement in handleToolCall that dispatches playwright_put calls to putRequestTool.execute.
    // API tools case "playwright_get": return await getRequestTool.execute(args, context); case "playwright_post": return await postRequestTool.execute(args, context); case "playwright_put": return await putRequestTool.execute(args, context); case "playwright_patch": return await patchRequestTool.execute(args, context); case "playwright_delete": return await deleteRequestTool.execute(args, context);
  • Instantiation of PutRequestTool instance 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);
  • Base class for API tools providing safeExecute method used by PutRequestTool.
    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}`); } } }

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