Package Exports
- @hee.jun.yun/playwright-mcp-server
- @hee.jun.yun/playwright-mcp-server/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@hee.jun.yun/playwright-mcp-server) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Playwright MCP Server Example
This project provides an example Model Context Protocol (MCP) server that integrates with Playwright to offer browser automation capabilities, specifically code generation and a prompt for creating user manuals.
Overview
The server exposes:
- A Tool:
playwright_codegen- Launches the Playwright Codegen UI to record browser interactions and generates a Playwright script. - A Prompt:
create_manual_from_codegen- Guides an LLM (or user) through the process of using theplaywright_codegentool to record actions for a web feature and then generating a step-by-step user manual based on the recorded script.
It communicates over standard input/output (stdio), making it easy to integrate with MCP clients.
Prerequisites
- Node.js: Version 16 or later recommended.
- npm or yarn: For package management.
- Playwright Browsers: The server uses Playwright, which requires browser binaries. You might need to install them initially:
npx playwright install
Installation
- Clone the repository (if applicable):
# git clone <your-repo-url> # cd <your-repo-directory>
- Install dependencies:
npm install # or # yarn install
Running the Server
Since the server is written in TypeScript, you can run it directly using ts-node or compile it first.
Using ts-node:
npx ts-node playwright/index.tsCompiling and Running:
- Add a build script to your
package.json(if you don't have one):"scripts": { "build": "tsc", "start": "node dist/playwright/index.js" // ... other scripts }
- Configure your
tsconfig.jsonappropriately (e.g., set"outDir": "./dist"). - Compile the TypeScript code:
npm run build - Run the compiled JavaScript:
npm start
The server will start and listen for MCP requests on stdin/stdout.
Capabilities
Tools
playwright_codegen- Description: Starts Playwright codegen to record browser interactions and generate scripts.
- Arguments:
url(string, optional): The URL to start the codegen browser window with.
- Output: Returns the generated Playwright TypeScript code as text content upon successful completion after the codegen window is closed.
- Note: This tool executes
npx playwright codegendirectly and requires user interaction with the opened browser window.
Prompts
create_manual_from_codegen- Description: Generates a step-by-step user manual for a website feature by recording actions with Playwright codegen, analyzing the script, and producing human-readable instructions.
- Arguments: None directly to the prompt itself (it uses the
playwright_codegentool). - Workflow: When a client requests this prompt using
prompts/get, the server returns an initial message outlining the steps:- Use the
playwright_codegentool (potentially providing a starting URL). - The user interacts with the codegen browser to record the desired actions.
- The tool returns the generated script.
- The LLM/client analyzes the script, removes unnecessary steps, and formats the essential actions into a user-friendly manual.
- Use the
Usage with an MCP Client
A typical interaction flow with an MCP client (like an AI assistant) would be:
- The client connects to the running server.
- The client (or user) lists available prompts (
prompts/list) and discoverscreate_manual_from_codegen. - The client requests the prompt details (
prompts/getwithname: "create_manual_from_codegen"). - The server responds with the initial message explaining the task.
- The client/LLM proceeds with the task, likely involving a call to the
playwright_codegentool (tool/call). - The user interacts with the Playwright Codegen window that appears.
- Once the codegen window is closed, the tool returns the script content to the client.
- The client/LLM processes the script and generates the final user manual.
npx @modelcontextprotocol/inspector node dist/index.js --> 이 명령어로 mcp 테스트 가능
description 수정으로 LLM이 툴 사용을 무조건 우선하게 할것. codegen 진행 중간중간에 snapshot 및 동작 하이라이트 넣을것. manual에 playwright 코드와 사진 함께 넣을것. 유저가 manual 확인할 시 유저에게 메뉴얼 시연 보여주면 좋을 지 물어볼 것.