fill_form
Automate form completion by filling multiple fields in sequence, including login forms, search inputs, and registration pages. Supports pressing Enter after each field and clicking submit buttons for authentication flows.
Instructions
Fill out one or multiple form fields in sequence, perfect for login forms, registration, search inputs, or any text entry. Supports pressing Enter after each field and clicking a submit button. Commonly used for authentication flows before accessing chat interfaces. Each field can be filled independently with optional Enter key press.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fields | Yes | Array of form field objects to fill in sequence. Each field requires a CSS selector and value. Example: [{selector: 'input[name="email"]', value: 'user@example.com'}, {selector: 'input[type="password"]', value: 'mypassword'}] | |
| sessionId | Yes | Session ID obtained from initialize_session | |
| submitButton | No | Optional CSS selector for submit button to click after all fields are filled (e.g., 'button[type="submit"]', '#login-button') |
Implementation Reference
- src/tools/interaction.js:68-100 (handler)The core handler function that executes the fill_form tool. It iterates over the fields array, fills each input using Playwright's page.fill and page.waitForSelector, optionally presses Enter, and clicks a submit button if provided. Returns success status and page info.export async function fillForm(sessionId, fields, submitButton = null) { const session = getSession(sessionId); const { page } = session; try { for (const field of fields) { const { selector, value, pressEnter = false } = field; await page.waitForSelector(selector, { timeout: 5000 }); await page.fill(selector, value); if (pressEnter) { await page.press(selector, "Enter"); await page.waitForTimeout(1000); } } if (submitButton) { await page.click(submitButton); await page.waitForTimeout(2000); } return { success: true, sessionId, currentUrl: page.url(), title: await page.title(), message: `Filled ${fields.length} field(s) successfully`, }; } catch (error) { throw new Error(`Failed to fill form: ${error.message}`); } }
- src/index.js:156-200 (schema)The input schema definition for the fill_form tool, including parameters sessionId, fields (array of selector/value/pressEnter), and optional submitButton. Defines types, descriptions, and required fields for MCP tool validation.{ name: "fill_form", description: "Fill out one or multiple form fields in sequence, perfect for login forms, registration, search inputs, or any text entry. Supports pressing Enter after each field and clicking a submit button. Commonly used for authentication flows before accessing chat interfaces. Each field can be filled independently with optional Enter key press.", inputSchema: { type: "object", properties: { sessionId: { type: "string", description: "Session ID obtained from initialize_session", }, fields: { type: "array", description: "Array of form field objects to fill in sequence. Each field requires a CSS selector and value. Example: [{selector: 'input[name=\"email\"]', value: 'user@example.com'}, {selector: 'input[type=\"password\"]', value: 'mypassword'}]", items: { type: "object", properties: { selector: { type: "string", description: "CSS selector for the input field (e.g., 'input[name=\"username\"]', '#email', '.search-box')", }, value: { type: "string", description: "Text value to enter into the field", }, pressEnter: { type: "boolean", description: "Press Enter key after filling this field to submit or trigger search (default: false)", }, }, required: ["selector", "value"], }, }, submitButton: { type: "string", description: "Optional CSS selector for submit button to click after all fields are filled (e.g., 'button[type=\"submit\"]', '#login-button')", }, }, required: ["sessionId", "fields"], }, },
- src/index.js:459-475 (registration)The dispatch logic in the CallToolRequestSchema handler that validates parameters and calls the fillForm handler function for the fill_form tool.case "fill_form": { const { sessionId, fields, submitButton } = args; if (!sessionId) { throw new McpError( ErrorCode.InvalidParams, "sessionId parameter is required" ); } if (!fields || !Array.isArray(fields)) { throw new McpError( ErrorCode.InvalidParams, "fields parameter must be an array" ); } result = await fillForm(sessionId, fields, submitButton); break; }
- src/tools/reverseEngineer.js:16-16 (helper)Re-export of the fillForm function from interaction.js, allowing centralized imports in index.js.export { clickElement, fillForm, waitForElement } from "./interaction.js";