Run the complete Playwright server demo with tool execution.
()
| 243 | |
| 244 | |
| 245 | async def main(): |
| 246 | """Run the complete Playwright server demo with tool execution.""" |
| 247 | |
| 248 | output.rule( |
| 249 | "[bold magenta]🎭 Playwright MCP Server - Complete Demo with Tool Execution[/bold magenta]" |
| 250 | ) |
| 251 | output.print() |
| 252 | output.info("This demo shows the complete lifecycle:") |
| 253 | output.info(" 1. Add Playwright MCP server") |
| 254 | output.info(" 2. Connect to the server") |
| 255 | output.info(" 3. List available tools") |
| 256 | output.info(" 4. Execute a Playwright tool") |
| 257 | output.info(" 5. Remove the server") |
| 258 | output.print() |
| 259 | |
| 260 | try: |
| 261 | # Step 1: Add Playwright server |
| 262 | await add_playwright_server() |
| 263 | |
| 264 | # Step 2: Connect to servers |
| 265 | tm = await connect_to_playwright() |
| 266 | |
| 267 | if tm: |
| 268 | # Step 3: List Playwright tools |
| 269 | tools = await list_playwright_tools(tm) |
| 270 | |
| 271 | # Step 4: Execute a tool |
| 272 | if tools: |
| 273 | await execute_playwright_tool(tm, tools) |
| 274 | |
| 275 | # Cleanup tool manager |
| 276 | await tm.cleanup() |
| 277 | |
| 278 | # Step 5: Remove Playwright server |
| 279 | await remove_playwright_server() |
| 280 | |
| 281 | # Summary |
| 282 | output.rule("[bold green]✅ Demo Complete![/bold green]") |
| 283 | output.success("Successfully demonstrated the complete server lifecycle:") |
| 284 | output.info(" ✓ Added Playwright MCP server") |
| 285 | output.info(" ✓ Connected to the server") |
| 286 | output.info(" ✓ Listed available tools") |
| 287 | output.info(" ✓ Executed a Playwright tool") |
| 288 | output.info(" ✓ Removed the server") |
| 289 | output.print() |
| 290 | |
| 291 | output.tip("💡 To use in chat mode:") |
| 292 | output.print( |
| 293 | " 1. Add server: /server add playwright stdio npx @playwright/mcp@latest" |
| 294 | ) |
| 295 | output.print(" 2. Restart session or use: /server reload") |
| 296 | output.print(" 3. Use tools: /tools --server playwright") |
| 297 | output.print(" 4. Execute: Use natural language to request browser actions") |
| 298 | output.print() |
| 299 | |
| 300 | except Exception as e: |
| 301 | output.error(f"Demo error: {e}") |
| 302 | import traceback |
no test coverage detected