playwright_post
Send HTTP POST requests with data payloads and authorization headers for browser automation tasks using the MCP Playwright server.
Instructions
Perform an HTTP POST request
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"url": "<url>",
"value": "<value>"
},
"name": "playwright_post"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | URL to perform POST operation | |
| value | Yes | Data to post in the body | |
| token | No | Bearer token for authorization | |
| headers | No | Additional headers to include in the request |
Implementation Reference
- src/tools/api/requests.ts:34-72 (handler)PostRequestTool class with execute method implementing the HTTP POST request logic using Playwright's request context, handling JSON parsing, headers including auth token, and response formatting.
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: string; 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:285-301 (schema)Input schema definition for the playwright_post tool, defining required url and value, 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:628-629 (registration)Dispatch in handleToolCall switch statement that calls the postRequestTool handler for 'playwright_post'.
case "playwright_post": return await postRequestTool.execute(args, context); - src/toolHandler.ts:408-408 (registration)Instantiation of PostRequestTool instance in initializeTools function.
if (!postRequestTool) postRequestTool = new PostRequestTool(server); - src/tools/api/requests.ts:7-29 (helper)Example of ApiToolBase extension (GetRequestTool), showing the base class provides safeExecute for API tools.
export class GetRequestTool extends ApiToolBase { /** * Execute the GET request tool */ async execute(args: any, context: ToolContext): Promise<ToolResponse> { return this.safeExecute(context, async (apiContext) => { const response = await apiContext.get(args.url); let responseText: string; try { responseText = await response.text(); } catch (_error) { responseText = "Unable to get response text"; } return createSuccessResponse([ `GET request to ${args.url}`, `Status: ${response.status()} ${response.statusText()}`, `Response: ${responseText.substring(0, 1000)}${responseText.length > 1000 ? "..." : ""}`, ]); }); } }