Playwright MCP + AI Agents.
Stop hand-writing locators and start describing what you want. The Playwright MCP server exposes a real browser as a set of tools over the Model Context Protocol, so an AI agent can read the page, click, type, and assert in plain language - then hand you a durable @playwright/test spec. This session takes you from "what is MCP" to an agent driving the live TTACart store end to end.
The 30-minute pitch
Four things you walk away able to do today.
Grasp the Model Context Protocol
Know what MCP is, how a client and a tool server talk over stdio or HTTP, and why it lets any LLM call the same browser tools.
Start the Playwright MCP server
Launch npx @playwright/mcp@latest, see it expose a real browser, and confirm the tools appear in your client.
Control TTACart with tools
Snapshot the page, click, type, and assert - using accessibility snapshots, not pixel guesses - to log in and check out.
Wire it into an AI agent
Let an agent perceive, decide, act, and re-snapshot in a loop, with you reviewing - then turn the run into a committed spec.
App under test
We explore TTACart
Every example on this page points the agent at the same live demo store, so you can copy a prompt and watch the browser move. It has a login, an inventory grid, item details, a cart, and a multi-step checkout - enough surface for an agent to perceive and act on.
TTACart store
A small e-commerce app with login, inventory, cart, and checkout. Point the MCP browser at it and let the agent explore.
Login → cart → checkout
The canonical journey. Use the credentials shown on the TTACart login screen - never hard-code secrets into prompts or specs.
Rich, stable structure
Elements carry roles and test ids, so the accessibility snapshot the agent reads is clean - it picks the right element without brittle guessing.
The protocol
What is the Model Context Protocol?
MCP is an open standard for connecting AI applications to external tools and data. Instead of every model inventing its own plugin format, MCP defines one contract: an AI app (the host, with an MCP client) connects to an MCP server that advertises a list of tools. The model picks a tool, the client sends the call, the server runs it and returns the result.
The AI app
Claude Code, Cursor, VS Code, or your own agent. It holds the LLM and an MCP client that discovers and invokes tools.
The tools
A process that advertises tools (here, a browser). It runs each call and returns structured results back to the client.
stdio or HTTP
The client talks to the server over standard input/output for a local process, or over HTTP for a remote one.
The server
The Playwright MCP server
Playwright MCP is an official Microsoft server that exposes a real, automated browser as MCP tools. One command starts it - no spec file, no boilerplate:
# start the Playwright MCP server (latest) npx @playwright/mcp@latest # headless for CI or background runs npx @playwright/mcp@latest --headless # fresh, throwaway profile each run npx @playwright/mcp@latest --isolated # expose over HTTP instead of stdio npx @playwright/mcp@latest --port 8931
Snapshots, not pixels
The agent acts on Playwright's accessibility snapshot of the page - structured roles and names - so it never has to guess from a screenshot.
Fast and reliable
Tool calls map to Playwright actions with built-in auto-waiting, so steps are stable and quick - no vision model in the hot path.
The agent can see and act
A genuine Chromium (or Firefox/WebKit) the agent navigates, reads, and drives - the same engine your tests run on.
Setup
Add Playwright MCP to your client
MCP clients read a JSON config that lists each server by a name, a command to launch, and its args. The block below is the standard Playwright MCP entry - it works in Claude Code, Cursor, and VS Code (the file location differs per client, the entry does not).
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest"]
}
}
}| Flag | Add to args when you want… |
|---|---|
| --headless | No visible window (CI, background, or servers without a display). |
| --isolated | A clean, in-memory profile per session - no cookies persisted to disk. |
| --browser chrome | Pick the engine: chrome, firefox, webkit, or msedge. |
| --port 8931 | Serve over HTTP for a remote or shared agent instead of stdio. |
The toolbox
The key browser tools
These are the tools the agent calls. You rarely name them by hand - you describe the goal and the model chooses - but knowing them helps you read and trust what the agent does.
| Tool | What it does |
|---|---|
| browser_navigate | Load a URL in the current page. |
| browser_snapshot | Capture the accessibility tree - the structured view the agent reads. |
| browser_click | Click a target element from the snapshot. |
| browser_type | Type text into an editable field. |
| browser_fill_form | Fill several form fields in one call. |
| browser_select_option | Choose an option from a dropdown. |
| browser_take_screenshot | Capture a visual image of the viewport or an element. |
| browser_wait_for | Wait until text appears or disappears, or for a time. |
| browser_network_requests | List the network calls made since the page loaded. |
| browser_console_messages | Read console output and errors from the page. |
| browser_tabs | List, open, close, or switch between tabs. |
| browser_evaluate | Run custom JavaScript on the page or an element. |
Hands-on
Drive TTACart with natural language
With the server connected, you talk to the agent in plain English. It translates each instruction into browser_* calls and reports back the snapshot it acted on. Here is a full login-to-checkout exploration.
You: Open https://app.thetestingacademy.com/playwright/ttacart/
and snapshot the page.
Agent: browser_navigate -> https://app.thetestingacademy.com/playwright/ttacart/
browser_snapshot
-> heading "Login", textbox "Username",
textbox "Password", button "Login",
plus the on-screen credentials hint.You: Log in using the username and password shown
on the login screen, then snapshot the result.
Agent: browser_type -> textbox "Username" (from the hint)
browser_type -> textbox "Password" (from the hint)
browser_click -> button "Login"
browser_snapshot
-> heading "Products", a grid of items,
each with an "Add to cart" button.You: Add the first product to the cart, go to the cart,
and complete checkout with sample details.
Agent: browser_click -> "Add to cart" (first item)
browser_click -> cart link
browser_click -> "Checkout"
browser_fill_form -> first name, last name, postal code
browser_click -> "Continue" then "Finish"
browser_snapshot
-> heading "Thank you for your order!"How agents work
The agent loop: perceive, decide, act
An AI agent does not run a script. It runs a loop: read the current state, decide the next step, call one tool, then look again. MCP is what makes each "act" possible and each "perceive" trustworthy.
Perceive
Call browser_snapshot to read the page as a structured accessibility tree.
Decide
The model picks the next action and the element to target from that snapshot.
Act
It calls one tool - browser_click, browser_type, browser_navigate.
Re-snapshot & assert
Snapshot again, confirm the expected text appeared, and repeat or stop.
From exploration to a test
Turn the run into a Playwright spec
An MCP exploration is repeatable but not durable - it lives in a chat. The payoff is asking the agent to emit a real @playwright/test file from what it just did, so the journey becomes a committed test you run in CI.
You: Generate a Playwright Test (TypeScript) spec for the
login-to-checkout flow you just ran on TTACart.
Use role and label locators, read the credentials
on the login screen, and assert the success heading.
Agent: -> writes tests/ttacart-checkout.spec.ts
using getByRole / getByLabel locators and
expect(...).toHaveText("Thank you for your order!")# run the agent-generated spec headed to watch it npx playwright test tests/ttacart-checkout.spec.ts --headed # open the trace if anything fails npx playwright show-trace test-results/.../trace.zip
Reference
The Playwright MCP cheat sheet
| Item | Value |
|---|---|
| Run the server | npx @playwright/mcp@latest |
| Headless | npx @playwright/mcp@latest --headless |
| Isolated profile | npx @playwright/mcp@latest --isolated |
| HTTP transport | npx @playwright/mcp@latest --port 8931 |
| Client config key | mcpServers.playwright.command = npx |
| Client config args | ["@playwright/mcp@latest"] |
| Read the page | browser_snapshot |
| Go to a URL | browser_navigate |
| Click / type | browser_click · browser_type |
| Fill a form | browser_fill_form |
| Pick a dropdown option | browser_select_option |
| Screenshot | browser_take_screenshot |
| Wait for text | browser_wait_for |
| Network / console | browser_network_requests · browser_console_messages |
| Tabs / JS | browser_tabs · browser_evaluate |
Hands-on
Six MCP drills on TTACart
Connect the server
Add the mcpServers entry, restart your client, and confirm the browser_* tools appear.
Snapshot the store
Ask the agent to open TTACart and run browser_snapshot; read the roles and names it returns.
Agent logs in
Have it log in using the credentials shown on the login screen, then snapshot the products page.
Complete checkout
Add an item, go to the cart, and finish checkout; assert the success heading via a snapshot.
Capture a screenshot
Use browser_take_screenshot to grab the order-confirmation page as evidence.
Emit a spec
Ask the agent to generate a @playwright/test file from the run, review the locators, and commit it.
Sources
Official references
| Reference | URL |
|---|---|
| Playwright MCP docs | https://playwright.dev/docs/mcp |
| Playwright MCP on GitHub | https://github.com/microsoft/playwright-mcp |
| Model Context Protocol | https://modelcontextprotocol.io |
| Playwright Test docs | https://playwright.dev/docs/intro |
| TTACart demo app | https://app.thetestingacademy.com/playwright/ttacart/ |