browser_fill
Fill any form input field on a webpage by specifying its CSS selector and the text to enter, enabling automated browser interactions.
Instructions
Fill a form input with text
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | CSS selector for input field | |
| value | Yes | Text to enter in the field |
Implementation Reference
- src/executor.ts:378-402 (handler)The handler function `handleBrowserFill` that executes the browser_fill tool logic. It waits for the selector element, fills the input with the provided value using Playwright's page.fill(), and returns success/error response.
async function handleBrowserFill(page: Page, args: any): Promise<{ toolResult: CallToolResult }> { try { await page.waitForSelector(args.selector); await page.fill(args.selector, args.value); return { toolResult: { content: [{ type: "text", text: `Filled ${args.selector} with: ${args.value}`, }], isError: false, }, }; } catch (error) { return { toolResult: { content: [{ type: "text", text: `Fill operation failed on ${args.selector}: ${(error as Error).message}`, }], isError: true, }, }; } } - src/tools.ts:84-95 (schema)The schema definition for browser_fill tool. Defines the name, description, and inputSchema with required properties 'selector' (CSS selector for input field) and 'value' (text to enter).
{ name: "browser_fill", description: "Fill a form input with text", inputSchema: { type: "object", properties: { selector: { type: "string", description: "CSS selector for input field" }, value: { type: "string", description: "Text to enter in the field" } }, required: ["selector", "value"] } }, - src/tools.ts:3-12 (registration)The BROWSER_TOOLS array listing 'browser_fill' as one of the available browser tools.
export const BROWSER_TOOLS = [ "browser_navigate", "browser_screenshot", "browser_click", "browser_fill", "browser_select", "browser_hover", "browser_evaluate", "browser_set_viewport" ]; - src/executor.ts:197-198 (registration)The switch case in executeToolCall that dispatches 'browser_fill' to handleBrowserFill handler.
case "browser_fill": return await handleBrowserFill(activePage!, args); - src/index.ts:64-83 (helper)The startServer function that calls registerTools and setupHandlers to register all tools including browser_fill on the MCP server.
async function startServer() { parseArgs(); const server = new Server( { name: "mcp-browser-agent", version: "0.1.0", }, { capabilities: { resources: {}, tools: {}, }, } ); const tools = registerTools(); setupHandlers(server, tools); const transport = new StdioServerTransport(); await server.connect(transport); }