Compare AIFind AIAI NewsAI How-To
About Us
PrivacyTermsFAQContactContact
AIB Inc.Company info
© 2026 AIB Inc.

Build a Minimal WebMCP Agent with Playwright and Gemini

Build a Minimal WebMCP Agent with Playwright and Gemini

DEV.to·Thursday, July 2, 2026
  • •Developer builds agent connecting Gemini API and WebMCP using Playwright
  • •Solution requires Chrome flag enable-webmcp-testing and Node.js 20+
  • •Playwright bridges Node.js and browser context to execute WebMCP tools
  • •Developer builds agent connecting Gemini API and WebMCP using Playwright
  • •Solution requires Chrome flag enable-webmcp-testing and Node.js 20+
  • •Playwright bridges Node.js and browser context to execute WebMCP tools

Daniel Balcarek has released a tutorial on creating a minimal agent that connects the Gemini API with WebMCP (a tool allowing web pages to expose functions for AI models) using Playwright. This setup enables developers to test WebMCP tools with powerful Gemini models directly in the Chrome browser, overcoming the limitations of standard browser extensions. The project requires Node.js 20+ and a Google Chrome installation, where WebMCP must be enabled by setting the chrome://flags/#enable-webmcp-testing flag to Enabled.

The development process involves installing Playwright, the Gemini SDK (@google/genai), and TypeScript dependencies. The core logic relies on Playwright to open a persistent Chrome context, which provides a real browser environment necessary for experimental features like WebMCP. The agent uses page.evaluate to bridge the gap between Node.js and the browser, allowing the AI to query exposed tools such as 'getGameState'. This function accesses either navigator.modelContext or document.modelContext to retrieve and execute tools on the web page.

In the provided proof-of-concept, the developer demonstrates an end-to-end flow: the script sends a tool definition to Gemini, which then requests a function call. The Playwright instance intercepts this call, executes the logic inside the browser page, and returns the result back to the model. This bridge allows automated agents to interact with web content in real-time, validated against specific function requirements. The implementation avoids the need for secondary browser extensions, instead utilizing Playwright to maintain control over the browser session for both discovery and execution of web-based tools.

Daniel Balcarek has released a tutorial on creating a minimal agent that connects the Gemini API with WebMCP (a tool allowing web pages to expose functions for AI models) using Playwright. This setup enables developers to test WebMCP tools with powerful Gemini models directly in the Chrome browser, overcoming the limitations of standard browser extensions. The project requires Node.js 20+ and a Google Chrome installation, where WebMCP must be enabled by setting the chrome://flags/#enable-webmcp-testing flag to Enabled.

The development process involves installing Playwright, the Gemini SDK (@google/genai), and TypeScript dependencies. The core logic relies on Playwright to open a persistent Chrome context, which provides a real browser environment necessary for experimental features like WebMCP. The agent uses page.evaluate to bridge the gap between Node.js and the browser, allowing the AI to query exposed tools such as 'getGameState'. This function accesses either navigator.modelContext or document.modelContext to retrieve and execute tools on the web page.

In the provided proof-of-concept, the developer demonstrates an end-to-end flow: the script sends a tool definition to Gemini, which then requests a function call. The Playwright instance intercepts this call, executes the logic inside the browser page, and returns the result back to the model. This bridge allows automated agents to interact with web content in real-time, validated against specific function requirements. The implementation avoids the need for secondary browser extensions, instead utilizing Playwright to maintain control over the browser session for both discovery and execution of web-based tools.

Read original (English)·Jul 1, 2026
Coding#webmcp#playwright#gemini#agentic ai#typescript#automation