Playwrightium
An MCP server for browser automation that allows AI to perform web tasks using Playwright through direct commands, reusable YAML shortcuts, or custom scripts. It features secure environment variable management and guided automation creation to build robust, repeatable browser workflows.
README
Playwrightium
Model Context Protocol server for browser automation with Playwright
Build reusable browser automation workflows that AI can intelligently select and execute. Stop regenerating the same steps repeatedly—define tested automation once, use everywhere.
🚀 Quick Start
Installation
# Install globally
npm install -g playwrightium
# Or use with npx (no installation needed)
npx playwrightium
MCP Configuration
Add to your MCP settings (VS Code, Claude Desktop, etc.):
{
"mcpServers": {
"playwrightium": {
"command": "npx",
"args": ["-y", "playwrightium"]
}
}
}
That's it! The server will automatically create a .playwright-mcp workspace in your home directory.
Custom Workspace (Optional)
{
"mcpServers": {
"playwrightium": {
"command": "npx",
"args": [
"-y",
"playwrightium",
"--base",
"/path/to/your/workspace"
]
}
}
}
Seed AI Assistant Integration (Optional)
Install chatmodels and prompts for your AI assistant:
# For GitHub Copilot
playwrightium seed --loop=copilot
# For Claude
playwrightium seed --loop=claude
This creates workspace-specific configurations in .github/chatmodels and .github/prompts (Copilot) or .claude/agents (Claude).
Your First Automation
Use the @create-shortcut prompt in your AI assistant:
@create-shortcut Login to my staging environment
The AI will guide you through:
- Testing the workflow manually with
browser-session - Creating a YAML shortcut with proper selectors
- Saving to
.playwright-mcp/shortcuts/login.yaml - Testing the final shortcut
🎯 Three Ways to Automate
1. Browser Session (Built-in)
Execute commands directly without creating files:
{
"tool": "browser-session",
"commands": [
{ "type": "navigate", "url": "https://example.com" },
{ "type": "fill", "selector": "#email", "value": "user@example.com" },
{ "type": "click", "selector": "button[type='submit']" },
{ "type": "screenshot", "path": "result.png" }
]
}
2. Shortcuts (YAML)
Reusable workflows with environment variable support:
# .playwright-mcp/shortcuts/login.yaml
commands:
- type: navigate
url: ${{STAGING_URL}}
- type: fill
selector: "#email"
value: ${{USER_EMAIL}}
- type: fill
selector: "#password"
value: ${{USER_PASSWORD}}
- type: click
selector: 'button[type="submit"]'
- type: wait_for_text
text: "Dashboard"
Run with: execute-shortcut { "shortcutPath": "login.yaml" }
3. Scripts (TypeScript/JavaScript)
Advanced automation with full programming capabilities:
// .playwright-mcp/scripts/extract-users.ts
import type { Page } from 'playwright';
export default async function({ page, logger, env }) {
await page.goto(env.ADMIN_URL);
const users = await page.$$eval('.user-row', rows =>
rows.map(row => ({
name: row.querySelector('.name').textContent,
email: row.querySelector('.email').textContent
}))
);
logger(`Extracted ${users.length} users`);
return { users };
}
Run with: execute-script { "scriptPath": "extract-users.ts" }
🔐 Environment Variables
Keep credentials secure using .env files:
# .env (at repository root)
STAGING_URL=https://staging.example.com
USER_EMAIL=test@example.com
USER_PASSWORD=secure-password
API_KEY=your-api-key
Use in shortcuts: ${{VARIABLE_NAME}}
Use in scripts: env.VARIABLE_NAME
🧰 Built-in Tools
browser-session- Execute 25+ browser commands in one callexecute-shortcut- Run YAML workflow filesexecute-script- Run TypeScript/JavaScript automationbrowser-snapshot- Capture page state for debuggingbrowser-debug- Get console logs and network requestsclose-browser- Reset browser session
Available Commands
Navigate, click, fill, type, hover, screenshot, scroll, evaluate, wait_for_text, get_text, get_attribute, press_key, select_option, check, uncheck, upload_file, drag, reload, get_url, get_title, and more!
🤖 AI Assistant Prompts
Playwrightium includes built-in prompts to guide automation creation:
@create-shortcut
Creates YAML shortcuts with proper testing workflow:
@create-shortcut Login to staging and navigate to user dashboard
@create-script
Creates TypeScript scripts with best practices:
@create-script Extract all product data from the admin panel
Both prompts enforce:
- ✅ Test manually first with
browser-session - ✅ Use environment variables for credentials
- ✅ Create file only after successful testing
- ✅ Include comprehensive error handling
Project-Level Integration
Use playwrightium seed to install chatmodels/agents in your project for team-wide consistency:
playwrightium seed --loop=copilot # → .github/chatmodels & prompts
playwrightium seed --loop=claude # → .claude/agents
See Seed Command Documentation for details.
📖 Documentation
Full documentation available in the docs/ directory:
- Quick Start Guide - Detailed setup and first automation
- Commands Reference - Complete command documentation
- Shortcuts Guide - YAML workflow creation
- Scripts Guide - TypeScript/JavaScript automation
- Secrets Management - Environment variables and security
- Custom Actions - Build reusable TypeScript tools
- Best Practices - Robust automation patterns
- Architecture - How Playwrightium works
🌟 Key Features
- 🖥️ Headed browser by default - see your automation in action
- 🔐 Secure secret management - environment variables with
${{VAR}}syntax - 🎯 Persistent browser sessions - maintain state across actions
- 🤖 AI-guided creation - built-in prompts for shortcuts and scripts
- 📦 Three automation layers - browser commands, shortcuts, and scripts
- 🔧 TypeScript-first - full type safety and intellisense
- ⚡ Zero config - works out of the box with sensible defaults
- 🧪 Test-first workflow - manual testing before file creation
🔄 Development
Local Development
git clone https://github.com/analysta-ai/playwrightium.git
cd playwrightium
npm install
npm run build
npm run dev
Configuration Options
# Headed (default) - watch automation
playwrightium
# Headless - background execution
playwrightium --headless
PLAYWRIGHTIUM_HEADLESS=1 playwrightium
# Custom workspace
playwrightium --base /path/to/workspace --actions .my-actions
# Verbose logging
playwrightium --verbose
� Examples
Quick Search Automation
{
"tool": "browser-session",
"commands": [
{ "type": "navigate", "url": "https://google.com" },
{ "type": "fill", "selector": "input[name='q']", "value": "Playwright" },
{ "type": "press_key", "key": "Enter" },
{ "type": "screenshot", "path": "results.png" }
]
}
E-commerce Testing Shortcut
# test-checkout.yaml
commands:
- type: navigate
url: ${{SHOP_URL}}
- type: fill
selector: "#search"
value: "laptop"
- type: click
selector: ".product:first-child"
- type: click
selector: "#add-to-cart"
- type: screenshot
path: "cart.png"
Data Extraction Script
export default async function({ page, env, logger }) {
await page.goto(`${env.ADMIN_URL}/reports`);
const data = await page.evaluate(() => {
return Array.from(document.querySelectorAll('.data-row'))
.map(row => ({
date: row.querySelector('.date').textContent,
revenue: row.querySelector('.revenue').textContent
}));
});
logger(`Extracted ${data.length} records`);
return { data, timestamp: new Date().toISOString() };
}
🔗 Links
- NPM Package: https://www.npmjs.com/package/playwrightium
- GitHub Repository: https://github.com/analysta-ai/playwrightium
- Documentation: ./docs/
- Model Context Protocol: https://modelcontextprotocol.io
- Playwright: https://playwright.dev
🤝 Contributing
Contributions welcome! Please read our contributing guidelines and submit pull requests to the repository.
Happy automating! 🚀
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。