🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
chore: Add Playwright MCP setup for frontend agent review (#12719)
Max Deichmann0c23b6399c1e
diff --git a/.codex/config.toml b/.codex/config.tomlnew file mode 100644index 0000000000..bcb9a8f6f6--- /dev/null+++ b/.codex/config.toml@@ -0,0 +1,12 @@+[mcp_servers.playwright]+command = "npx"+args = [+ "-y",+ "@playwright/mcp@latest",+ "--isolated",+ "--save-trace",+ "--output-dir",+ ".playwright-mcp",+ "--test-id-attribute",+ "data-testid",+]diff --git a/.gitignore b/.gitignoreindex a888924343..1bb03f7081 100644--- a/.gitignore+++ b/.gitignore@@ -72,6 +72,7 @@ node_modules.turboweb/test-results/*+.playwright-mcp/*# local config files*.local.*diff --git a/.mcp.json b/.mcp.jsonnew file mode 100644index 0000000000..0dabc5e748--- /dev/null+++ b/.mcp.json@@ -0,0 +1,18 @@+{+ "mcpServers": {+ "playwright": {+ "type": "stdio",+ "command": "npx",+ "args": [+ "-y",+ "@playwright/mcp@latest",+ "--isolated",+ "--save-trace",+ "--output-dir",+ ".playwright-mcp",+ "--test-id-attribute",+ "data-testid"+ ]+ }+ }+}diff --git a/.vscode/mcp.json b/.vscode/mcp.jsonnew file mode 100644index 0000000000..8d041a700f--- /dev/null+++ b/.vscode/mcp.json@@ -0,0 +1,18 @@+{+ "servers": {+ "playwright": {+ "type": "stdio",+ "command": "npx",+ "args": [+ "-y",+ "@playwright/mcp@latest",+ "--isolated",+ "--save-trace",+ "--output-dir",+ ".playwright-mcp",+ "--test-id-attribute",+ "data-testid"+ ]+ }+ }+}diff --git a/AGENTS.md b/AGENTS.mdindex a4c5090791..9a4da293e5 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -69,8 +69,9 @@ langfuse/- Dev all packages: `pnpm run dev`- Dev web only: `pnpm run dev:web`- Dev worker only: `pnpm run dev:worker`-- Codex environment bootstrap: `bash scripts/codex/setup.sh`+- Codex environment bootstrap: `bash scripts/codex/setup.sh` (installs deps, Playwright Chromium, and Prisma artifacts)- Codex environment maintenance: `bash scripts/codex/maintenance.sh`+- Install repo-local Playwright browsers for agents: `pnpm run playwright:install`- Lint all: `pnpm run lint`- Typecheck all: `pnpm run typecheck` / `pnpm tc`- To try running build, always run `pnpm run build:check` and verify that it succeeds. This does not impact running web servers@@ -168,6 +169,16 @@ Minimum verification matrix:- Schema/client drift: run `pnpm run db:generate`.- Local infra issues: run `pnpm run infra:dev:up`; use `pnpm run dx` only when destructive reset is intended.+## Agent Browser Automation+- Shared Playwright MCP configs live in `.mcp.json` and `.vscode/mcp.json`.+- Codex project-scoped MCP config lives in `.codex/config.toml` for trusted-project setups.+- Install Chromium into the default user-level Playwright cache with `pnpm run playwright:install`.+- `scripts/codex/setup.sh` runs the Playwright install step for first-time Codex bootstrap.+- Playwright MCP traces and other browser session artifacts live under `.playwright-mcp/` and are gitignored.+- For user-visible frontend changes in `web/**`, review the affected flow in a real browser with the Playwright MCP server before signoff. Cover the primary changed path with a quick functional pass and a visual check for obvious regressions.+- For web flows, start `pnpm run dev:web` (or `pnpm run dev`) before asking an agent to drive the app in a browser.+- Optional: generate Playwright's planner/generator/healer agent files with `pnpm --filter web exec playwright init-agents --loop=<claude|vscode|copilot|opencode>`.+## Git Notes- Do not use destructive git commands (for example `reset --hard`) unless explicitly requested.diff --git a/package.json b/package.jsonindex 999ee9ff37..ae34740ad2 100644--- a/package.json+++ b/package.json@@ -32,6 +32,7 @@"lint": "turbo run lint","format": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\" --experimental-cli","format:check": "prettier --check \"**/*.{js,jsx,ts,tsx,css}\" --experimental-cli",+ "playwright:install": "pnpm --filter web exec playwright install chromium","test": "turbo run test","release": "dotenv -e ../.env -- release-it","release:cloud": "bash ./scripts/release-cloud.sh",diff --git a/scripts/codex/setup.sh b/scripts/codex/setup.shindex 21fcac5a9e..04d8b3e93d 100755--- a/scripts/codex/setup.sh+++ b/scripts/codex/setup.sh@@ -26,5 +26,9 @@ ensure_env_file .env.test .env.test.examplepnpm install --frozen-lockfile+# Install Chromium into the default user-level Playwright cache so frontend+# browser review works on first bootstrap.+pnpm run playwright:install+# Prisma client generation is needed for typecheck/build tasks in Codex.pnpm run db:generatediff --git a/scripts/codex/setup.test.sh b/scripts/codex/setup.test.shindex a02280fb22..5f6ff70980 100755--- a/scripts/codex/setup.test.sh+++ b/scripts/codex/setup.test.sh@@ -12,6 +12,7 @@ cleanup() {trap cleanup EXITrepo_copy="$tmpdir/repo"+pnpm_log="$tmpdir/pnpm.log"mkdir -p "$tmpdir/bin" "$repo_copy/scripts/codex"@@ -26,8 +27,9 @@ cat <<'EOF' > "$tmpdir/bin/corepack"exit 0EOF-cat <<'EOF' > "$tmpdir/bin/pnpm"+cat <<EOF > "$tmpdir/bin/pnpm"#!/usr/bin/env bash+printf '%s\n' "\$*" >> "$pnpm_log"exit 0EOF@@ -80,4 +82,19 @@ assert_file_contains \'DATABASE_URL="postgresql://postgres:postgres@localhost:5432/langfuse_test"' \"setup.sh should preserve the existing .env.test on rerun"+assert_file_contains \+ "$pnpm_log" \+ "install --frozen-lockfile" \+ "setup.sh should install workspace dependencies"++assert_file_contains \+ "$pnpm_log" \+ "run playwright:install" \+ "setup.sh should install Playwright browsers for frontend review"++assert_file_contains \+ "$pnpm_log" \+ "run db:generate" \+ "setup.sh should generate Prisma artifacts"+echo "setup.sh example bootstrap regression test passed"diff --git a/web/AGENTS.md b/web/AGENTS.mdindex bda5496643..d6fca3b814 100644--- a/web/AGENTS.md+++ b/web/AGENTS.md@@ -70,6 +70,7 @@ performance, bundle size, or React/Next.js performance patterns.- Server tests: `pnpm --filter web run test --testPathPatterns="<pattern>"`- Client tests: `pnpm --filter web run test-client --testPathPatterns="<pattern>"`- E2E tests: `pnpm --filter web run test:e2e`+- Agent browser install to the default user-level Playwright cache: `pnpm run playwright:install`- Build: `pnpm --filter web run build`## Playbooks@@ -92,6 +93,14 @@ performance, bundle size, or React/Next.js performance patterns.1. Prefer `src/features/<feature>/*` for feature-local code.2. Put broadly reusable components in `src/components/*`.3. Keep server logic near feature server folders when possible.+4. Review the affected user flow in a real browser with the Playwright MCP server before signoff, including a quick functional pass and a visual regression check.++### Agent browser loop+1. Start the app with `pnpm run dev:web` unless an existing local server is already running.+2. Install Chromium with `pnpm run playwright:install` if Playwright has not been set up on this machine yet.+3. Use the workspace `playwright` MCP server from `.mcp.json` or `.vscode/mcp.json` for browser-driven review of user-visible frontend changes, not just debugging.+4. Exercise the primary changed flow and check the resulting UI state for obvious visual regressions before signoff.+5. Inspect traces and other artifacts under `../.playwright-mcp/` when a browser session fails.## Package-Specific Rules- Router style is Pages Router-centric; follow existing routing patterns.diff --git a/web/next.config.mjs b/web/next.config.mjsindex e3a7bf2bc9..06eaf95244 100644--- a/web/next.config.mjs+++ b/web/next.config.mjs@@ -49,6 +49,8 @@ const reportToHeader = {const nextConfig = {// Allow building to alternate directory for parallel build checks while dev server runsdistDir: process.env.NEXT_DIST_DIR || ".next",+ // Agent/browser tooling often targets 127.0.0.1 instead of localhost in dev.+ allowedDevOrigins: ["127.0.0.1"],staticPageGenerationTimeout: 500, // default is 60. Required for build process for amdtranspilePackages: ["@langfuse/shared", "vis-network/standalone"],reactStrictMode: true,