How rajendharmendra/playwright-mcp works
Main Components
• MCP Server Core:
• Central server (src/server.ts) that initializes Playwright’s capabilities.
• That it is capable of launching Chrome with a dedicated user profile to run in headless or headed mode.
• CLI/Program Interface:
• Command-line entry points (cli.js, src/program.ts) that start the server and manage arguments (e.g., headless, vision flag).
• Context & Resource Management:
• Context module (src/context.ts) which likely handles shared application state and configurations.
• Resource handling submodules in src/resources (e.g., console.ts and resource.ts) that interface with browser snapshots or accessibility data.
• Tools Layer:
• “tools” directory (src/tools) which provides the core functionalities (common utilities, screenshot, snapshot, tool orchestration, and miscellaneous utilities).
• Separate the tools governing “Snapshot Mode” from those for “Vision Mode,” as highlighted in the README.
• Testing & CI/CD:
• Optionally, show the testing framework (tests folder) along with the GitHub workflows (.github/workflows) which indicate CI/CD integration.
• External Integration Points:
• Integration points with VS Code as described (command line installs, API usage via custom transports).
• API level “createServer()” function (used in programmatic usage) and SSE endpoints used for browser commands.
Denote Relationships and Data Flow
• How the MCP Server interacts with the “Tools” components via function calls—switching behavior between Snapshot Mode and Vision Mode as per command-line flags.
• Interaction from the server’s core to the context and tools modules that process commands (e.g., browser_navigate, browser_click) as defined in the README.
Architectural Patterns & Design Principles
• Modularity: Highlight that the system is divided into multiple modules and directories (each handling context, tools, resources) to isolate concerns.
• Extensibility: Note that the tool commands (from snapshot to vision mode operations) are designed for deterministic execution and are easy to extend.
• CI/CD and Testing: Emphasize the integration of GitHub actions and automated tests in validating changes.
• Clear Separation of Concerns: The CLI, server logic, and tool functionalities are distinctly represented which aligns well with separation of concerns.
Technologies, Frameworks, and Libraries
• Node.js is the runtime (as indicated by package.json, cli.js).
• Playwright is the underlying browser automation library.
• TypeScript is used (src files with .ts, tsconfig.json) ensuring type safety.
• GitHub Actions for CI/CD workflows.
• ESLint for linting (eslint.config.mjs) and testing frameworks (notably, the tests directory with Playwright tests).