playwright_post
Send an HTTP POST request with specified data, URL, and headers using Playwright. This tool enables browser automation for tasks like submitting forms or interacting with APIs in a web environment.
Instructions
Perform an HTTP POST request
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| headers | No | Additional headers to include in the request | |
| token | No | Bearer token for authorization | |
| url | Yes | URL to perform POST operation | |
| value | Yes | Data to post in the body |
Implementation Reference
- src/tools/api/requests.ts:34-73 (handler)The PostRequestTool class provides the core handler logic for executing the 'playwright_post' tool. It performs an HTTP POST request using Playwright's API request context, handles JSON validation, sets headers including optional bearer token, retrieves the response, and formats the output.
export class PostRequestTool extends ApiToolBase { /** * Execute the POST 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.post(args.url, { data: typeof args.value === 'string' ? JSON.parse(args.value) : args.value, headers: { 'Content-Type': 'application/json', ...(args.token ? { 'Authorization': `Bearer ${args.token}` } : {}), ...(args.headers || {}) } }); let responseText; try { responseText = await response.text(); } catch (error) { responseText = "Unable to get response text"; } return createSuccessResponse([ `POST request to ${args.url}`, `Status: ${response.status()} ${response.statusText()}`, `Response: ${responseText.substring(0, 1000)}${responseText.length > 1000 ? '...' : ''}` ]); }); } } - src/tools.ts:254-271 (schema)The input schema definition for the 'playwright_post' tool, specifying parameters like url, value (body), optional token, and headers.
{ name: "playwright_post", description: "Perform an HTTP POST request", inputSchema: { type: "object", properties: { url: { type: "string", description: "URL to perform POST operation" }, value: { type: "string", description: "Data to post in the body" }, token: { type: "string", description: "Bearer token for authorization" }, headers: { type: "object", description: "Additional headers to include in the request", additionalProperties: { type: "string" } } }, required: ["url", "value"], }, }, - src/toolHandler.ts:336-340 (registration)Instantiation of the PostRequestTool instance in the initializeTools function, which creates the handler object used for execution.
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/toolHandler.ts:527-528 (registration)Dispatch/registration in the main handleToolCall switch statement, routing 'playwright_post' calls to the postRequestTool.execute method.
case "playwright_post": return await postRequestTool.execute(args, context); - src/tools.ts:476-481 (helper)The API_TOOLS array categorizes 'playwright_post' as an API tool, which influences browser launching logic (no browser needed). Also listed in src/toolHandler.ts import and other places.
export const API_TOOLS = [ "playwright_get", "playwright_post", "playwright_put", "playwright_delete", "playwright_patch"