import type { Tool } from "@modelcontextprotocol/sdk/types.js";
export function createToolDefinitions() {
return [
{
name: "playwright_navigate",
description: "Navigate to a URL",
inputSchema: {
type: "object",
properties: {
url: { type: "string", description: "URL to navigate to the website specified" },
browserType: { type: "string", description: "Browser type to use (chromium, firefox, webkit). Defaults to chromium", enum: ["chromium", "firefox", "webkit"] },
width: { type: "number", description: "Viewport width in pixels (default: 1280)" },
height: { type: "number", description: "Viewport height in pixels (default: 720)" },
timeout: { type: "number", description: "Navigation timeout in milliseconds" },
waitUntil: { type: "string", description: "Navigation wait condition" },
headless: { type: "boolean", description: "Run browser in headless mode (default: false)" },
proxy: {
type: "object",
description: "Proxy settings for the browser",
properties: {
server: { type: "string", description: "Proxy server address (e.g., 'http://proxy.example.com:8080')" },
username: { type: "string", description: "Optional username for proxy authentication" },
password: { type: "string", description: "Optional password for proxy authentication" },
bypass: { type: "string", description: "Optional comma-separated domains to bypass proxy, for example '.com, chromium.org, .domain.com'" }
},
required: ["server"]
},
headers: {
type: "object",
description: "Custom HTTP headers to send with the request",
additionalProperties: { type: "string" }
}
},
required: ["url"],
},
},
{
name: "playwright_screenshot",
description: "Take a screenshot of the current page or a specific element",
inputSchema: {
type: "object",
properties: {
name: { type: "string", description: "Name for the screenshot" },
selector: { type: "string", description: "CSS selector for element to screenshot" },
width: { type: "number", description: "Width in pixels (default: 800)" },
height: { type: "number", description: "Height in pixels (default: 600)" },
storeBase64: { type: "boolean", description: "Store screenshot in base64 format (default: true)" },
fullPage: { type: "boolean", description: "Store screenshot of the entire page (default: false)" },
savePng: { type: "boolean", description: "Save screenshot as PNG file (default: false)" },
downloadsDir: { type: "string", description: "Custom downloads directory path (default: user's Downloads folder)" },
},
required: ["name"],
},
},
{
name: "playwright_click",
description: "Click an element on the page. Supports both CSS selector and coordinate-based clicking for vision-based agents.",
inputSchema: {
type: "object",
properties: {
selector: { type: "string", description: "CSS selector for the element to click" },
coordinate: {
type: "array",
items: { type: "number" },
description: "Screen coordinates [x, y] for mouse click (alternative to selector)"
},
button: {
type: "string",
enum: ["left", "right", "middle"],
description: "Mouse button to use (default: left)"
},
},
required: [],
},
},
{
name: "playwright_iframe_click",
description: "Click an element in an iframe on the page",
inputSchema: {
type: "object",
properties: {
iframeSelector: { type: "string", description: "CSS selector for the iframe containing the element to click" },
selector: { type: "string", description: "CSS selector for the element to click" },
},
required: ["iframeSelector", "selector"],
},
},
{
name: "playwright_iframe_fill",
description: "Fill an element in an iframe on the page",
inputSchema: {
type: "object",
properties: {
iframeSelector: { type: "string", description: "CSS selector for the iframe containing the element to fill" },
selector: { type: "string", description: "CSS selector for the element to fill" },
value: { type: "string", description: "Value to fill" },
},
required: ["iframeSelector", "selector", "value"],
},
},
{
name: "playwright_fill_by_index",
description: "Fill an input field by its annotation index number. Use playwright_annotate or playwright_get_annotated_elements first to get element indices.",
inputSchema: {
type: "object",
properties: {
index: { type: "number", description: "The annotation index number of the input element to fill" },
value: { type: "string", description: "Value to fill" },
},
required: ["index", "value"],
},
},
{
name: "playwright_select",
description: "Select an element on the page with Select tag",
inputSchema: {
type: "object",
properties: {
selector: { type: "string", description: "CSS selector for element to select" },
value: { type: "string", description: "Value to select" },
},
required: ["selector", "value"],
},
},
{
name: "playwright_hover",
description: "Hover an element on the page",
inputSchema: {
type: "object",
properties: {
selector: { type: "string", description: "CSS selector for element to hover" },
},
required: ["selector"],
},
},
{
name: "playwright_evaluate",
description: "Execute JavaScript in the browser console",
inputSchema: {
type: "object",
properties: {
script: { type: "string", description: "JavaScript code to execute" },
},
required: ["script"],
},
},
{
name: "playwright_console_logs",
description: "Retrieve console logs from the browser with filtering options",
inputSchema: {
type: "object",
properties: {
type: {
type: "string",
description: "Type of logs to retrieve (all, error, warning, log, info, debug, exception)",
enum: ["all", "error", "warning", "log", "info", "debug", "exception"]
},
search: {
type: "string",
description: "Text to search for in logs (handles text with square brackets)"
},
limit: {
type: "number",
description: "Maximum number of logs to return"
},
clear: {
type: "boolean",
description: "Whether to clear logs after retrieval (default: false)"
}
},
required: [],
},
},
{
name: "playwright_close",
description: "Close the browser and release all resources",
inputSchema: {
type: "object",
properties: {},
required: [],
},
},
{
name: "playwright_expect_response",
description: "Ask Playwright to start waiting for a HTTP response. This tool initiates the wait operation but does not wait for its completion.",
inputSchema: {
type: "object",
properties: {
id: { type: "string", description: "Unique & arbitrary identifier to be used for retrieving this response later with `Playwright_assert_response`." },
url: { type: "string", description: "URL pattern to match in the response." }
},
required: ["id", "url"],
},
},
{
name: "playwright_custom_user_agent",
description: "Set a custom User Agent for the browser",
inputSchema: {
type: "object",
properties: {
userAgent: { type: "string", description: "Custom User Agent for the Playwright browser instance" }
},
required: ["userAgent"],
},
},
{
name: "playwright_get_visible_text",
description: "Get the visible text content of the current page",
inputSchema: {
type: "object",
properties: {},
required: [],
},
},
{
name: "playwright_get_visible_html",
description: "Get the HTML content of the current page. By default, all <script> tags are removed from the output unless removeScripts is explicitly set to false.",
inputSchema: {
type: "object",
properties: {
selector: { type: "string", description: "CSS selector to limit the HTML to a specific container" },
removeScripts: { type: "boolean", description: "Remove all script tags from the HTML (default: true)" },
removeComments: { type: "boolean", description: "Remove all HTML comments (default: false)" },
removeStyles: { type: "boolean", description: "Remove all style tags from the HTML (default: false)" },
removeMeta: { type: "boolean", description: "Remove all meta tags from the HTML (default: false)" },
cleanHtml: { type: "boolean", description: "Perform comprehensive HTML cleaning (default: false)" },
minify: { type: "boolean", description: "Minify the HTML output (default: false)" },
maxLength: { type: "number", description: "Maximum number of characters to return (default: 20000)" }
},
required: [],
},
},
{
name: "playwright_go_back",
description: "Navigate back in browser history",
inputSchema: {
type: "object",
properties: {},
required: [],
},
},
{
name: "playwright_go_forward",
description: "Navigate forward in browser history",
inputSchema: {
type: "object",
properties: {},
required: [],
},
},
{
name: "playwright_drag",
description: "Drag an element to a target location",
inputSchema: {
type: "object",
properties: {
sourceSelector: { type: "string", description: "CSS selector for the element to drag" },
targetSelector: { type: "string", description: "CSS selector for the target location" }
},
required: ["sourceSelector", "targetSelector"],
},
},
{
name: "playwright_press_key",
description: "Press a keyboard key",
inputSchema: {
type: "object",
properties: {
key: { type: "string", description: "Key to press (e.g. 'Enter', 'ArrowDown', 'a')" },
selector: { type: "string", description: "Optional CSS selector to focus before pressing key" }
},
required: ["key"],
},
},
{
name: "playwright_annotate",
description: "Annotate all interactive elements (buttons, links, inputs, etc.) on the current page with colored boxes and index numbers. Returns a list of elements with their coordinates and properties.",
inputSchema: {
type: "object",
properties: {},
required: [],
},
},
{
name: "playwright_click_by_index",
description: "Click an element by its annotation index number. Use playwright_annotate or playwright_get_annotated_elements first to get element indices.",
inputSchema: {
type: "object",
properties: {
index: { type: "number", description: "The annotation index number of the element to click" },
},
required: ["index"],
},
},
{
name: "playwright_set_auto_annotation",
description: "Enable or disable automatic element annotation. When enabled (default), all interactive elements are automatically highlighted with colored boxes and index numbers when a page loads or changes.",
inputSchema: {
type: "object",
properties: {
enabled: { type: "boolean", description: "Whether to enable auto-annotation (default: true)" },
},
required: ["enabled"],
},
},
{
name: "playwright_get_annotated_elements",
description: "Get the list of currently annotated elements on the page. Returns element information including index, type, coordinates, and text.",
inputSchema: {
type: "object",
properties: {},
required: [],
},
},
] as const satisfies Tool[];
}
// Browser-requiring tools for conditional browser launch
export const BROWSER_TOOLS = [
"playwright_navigate",
"playwright_screenshot",
"playwright_click",
"playwright_iframe_click",
"playwright_iframe_fill",
"playwright_fill_by_index",
"playwright_select",
"playwright_hover",
"playwright_evaluate",
"playwright_close",
"playwright_expect_response",
"playwright_custom_user_agent",
"playwright_get_visible_text",
"playwright_get_visible_html",
"playwright_go_back",
"playwright_go_forward",
"playwright_drag",
"playwright_press_key",
"playwright_annotate",
"playwright_click_by_index",
"playwright_set_auto_annotation",
"playwright_get_annotated_elements"
];
// All available tools
export const tools = [
...BROWSER_TOOLS
];