manishamishraacc/playwright-mcp-server
If you are the rightful owner of playwright-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
The Playwright MCP Server is a FastAPI-based server that integrates AI-powered test automation with Playwright and Azure DevOps.
Playwright MCP Server
A FastAPI-based Model Context Protocol (MCP) server that provides AI-powered test automation capabilities using Playwright and Azure DevOps integration.
🚀 Features
- AI-Powered Test Automation: Leverage AI to create and execute browser automation tests
- Playwright Integration: Full browser automation with Chrome, Firefox, and Safari support
- Azure DevOps Integration: Manage releases, builds, and deployments
- Session-Based Testing: Maintain browser sessions for complex E2E testing workflows
- Real-time Communication: WebSocket support for live interaction
- Comprehensive API: RESTful API with automatic documentation
🛠️ Available Tools
Playwright Tools (Session-based E2E Testing)
create_browser_session- Create a new browser sessionnavigate_to_url- Navigate to a URLclick_element- Click an element on the pagefill_form_field- Fill a form field with texttake_screenshot- Take a screenshotget_page_content- Get text content from the pageclose_browser_session- Close the browser session
Legacy Playwright Tools
run_ui_tests- Run UI tests using Playwrightrun_accessibility_tests- Run accessibility testsgenerate_test_report- Generate test reports
Azure DevOps Tools
get_release_info- Get release informationcreate_release- Create a new releaseget_build_info- Get build informationtrigger_build- Trigger a new build
📋 Prerequisites
- Python 3.9+
- Playwright
- FastAPI
- Uvicorn
🚀 Installation
-
Clone the repository
git clone <your-repo-url> cd playwright-mcp-server -
Install dependencies
pip install -r requirements.txt -
Install Playwright browsers
playwright install
🏃♂️ Quick Start
-
Start the server
python main_fixed.py -
Access the API documentation
- Swagger UI: http://localhost:8002/docs
- ReDoc: http://localhost:8002/redoc
-
Test the API
# Get all available tools curl http://localhost:8002/api/v1/tools # Health check curl http://localhost:8002/health
📚 API Endpoints
Core Endpoints
GET /- Root endpointGET /health- Health checkGET /test- Test endpoint
MCP Endpoints (with /api/v1 prefix)
GET /api/v1/tools- List all available toolsGET /api/v1/tools/{tool_name}- Get specific tool informationPOST /api/v1/tools/{tool_name}/execute- Execute a tool directlyPOST /api/v1/chat- Process chat requestsPOST /api/v1/chat/stream- Stream chat responsesGET /api/v1/sessions- List all active sessionsGET /api/v1/sessions/{session_id}- Get session informationDELETE /api/v1/sessions/{session_id}- Delete a sessionWS /api/v1/ws/{session_id}- WebSocket endpoint for real-time communication
🔧 Configuration
The server runs on port 8002 by default. You can modify the configuration in main_fixed.py:
uvicorn.run(
"main_fixed:app",
host="0.0.0.0",
port=8002,
reload=True,
log_level="info"
)
🧪 Usage Examples
Creating a Browser Session
curl -X POST "http://localhost:8002/api/v1/tools/create_browser_session/execute" \
-H "Content-Type: application/json" \
-d '{
"session_id": "test-session-1",
"browser": "chrome",
"headless": false
}'
Navigating to a URL
curl -X POST "http://localhost:8002/api/v1/tools/navigate_to_url/execute" \
-H "Content-Type: application/json" \
-d '{
"session_id": "test-session-1",
"url": "https://example.com",
"wait_for_load": true
}'
Taking a Screenshot
curl -X POST "http://localhost:8002/api/v1/tools/take_screenshot/execute" \
-H "Content-Type: application/json" \
-d '{
"session_id": "test-session-1",
"full_page": true,
"path": "screenshot.png"
}'
🏗️ Project Structure
playwright-mcp-server/
├── agents/ # AI agent implementations
│ ├── __init__.py
│ └── base_agent.py
├── context/ # Session and memory management
│ ├── __init__.py
│ └── memory.py
├── routes/ # API route definitions
│ ├── __init__.py
│ └── mcp.py
├── schemas/ # Pydantic models and schemas
│ ├── __init__.py
│ └── mcp.py
├── tools/ # Tool implementations
│ ├── __init__.py
│ ├── playwright_runner.py
│ └── azure_devops.py
├── utils/ # Utility functions
│ ├── __init__.py
│ └── helpers.py
├── main_fixed.py # Main application entry point
├── main.py # Alternative main file
├── registry.py # Tool registry
├── requirements.txt # Python dependencies
└── README.md # This file
🔍 Development
Running in Development Mode
The server includes auto-reload functionality for development:
python main_fixed.py
Adding New Tools
- Create your tool function in the appropriate module under
tools/ - Register it in the
register_tools()function inmain_fixed.py - The tool will be automatically available via the API
Testing
# Run the test script
python test_tools_api.py
# Or use the example client
python example_client.py
🤝 Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📄 License
This project is licensed under the MIT License - see the file for details.
🆘 Support
If you encounter any issues or have questions:
- Check the API documentation when the server is running
- Review the logs for error messages
- Open an issue on GitHub with detailed information about the problem