# blackwhite084/playwright-plus-python-mcp architecture

> Architecture diagram of the GitHub repository blackwhite084/playwright-plus-python-mcp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/blackwhite084/playwright-plus-python-mcp
- Repository: https://github.com/blackwhite084/playwright-plus-python-mcp

## Overview

##### Main Components
- MCP Server Core: Represented by the “src/playwright_server/server.py” file and its corresponding package. This is the central component that initializes the server, listens for commands, and dispatches requests.
- Storage & Prompt Engine: A component that manages “note://” resources—storing note metadata (name, description, plain text) and providing a summarization prompt (“summarize-notes”) which combines stored notes.
- Playwright Tools Module: A set of helper functions or tool endpoints (as declared in the README) for various browser interactions:
- playwright_navigate: Handle URL navigations and manage browser sessions.
- playwright_screenshot: Capture full-page or element screenshots.
- playwright_click & playwright_click_text: Perform click actions based on selectors or text.
- playwright_fill: Fill input fields.
- playwright_evaluate: Execute JavaScript in the browser.
- playwright_get_text_content & playwright_get_html_content: Retrieve content from web pages.
- External Browser/Playwright Instance: While not part of the core codebase, the interaction with a live browser session (or a headless browser) is a key external element.
- Command-Line / Deployment Interface: Build and publish scripts (using “uv sync”, “uv build”, “uv publish”), configuration files (pyproject.toml, uv.lock), and the dependency on MCP Inspector for debugging.

##### Relationships and Data Flow
- Dispatching: Within the server, commands are parsed, and based on their type they either operate on the note storage system or invoke one of the Playwright tool functions.
- Browser Interaction: When a Playwright command is executed, if no active browser session exists, the server automatically creates one. Then, it communicates with the external browser to perform the automation actions.
- Output/Response: The results of the operations (such as screenshots, web page content, or summaries) are communicated back to the MCP client.
- Debugging & Monitoring: The MCP Inspector (running externally via npm) attaches to the server’s stdio for real-time debugging.

##### Architectural Patterns/Design Principles
- Modular Separation: The project logically separates note resources from browser automation tools. Each “tool” (such as navigating or clicking) is a distinct functionality that can be independently extended.
- Command Dispatcher Pattern: The server likely uses a dispatcher mechanism to decide which tool and resource logic to invoke based on the received command.
- Loose Coupling with External Systems: The design ensures that browser automation (via Playwright) is handled as an independent module, which makes integration of the MCP Inspector straightforward.

##### Including Relevant Technologies and Frameworks
- Python for the core server logic.
- Playwright as the automation driver (implied in tool names and operations).
- MCP protocol (for inter-process communication over stdio).
- “uv” and “uvx” for building, synchronizing, and deploying the server.
- (Optionally) The MCP Inspector for debugging purposes.

- Labels detailing which parts are “internal logic” vs. “external interactions” with technologies noted (Python, Playwright, MCP).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "External Systems"
        MCP_Client["MCP Client"]:::external
        External_Browser["Browser Session (Playwright)"]:::external
        MCP_Inspector["MCP Inspector (Debugging)"]:::external
    end

    subgraph "Deployment"
        PyProject["pyproject.toml"]:::deployment
        UV_Lock["uv.lock"]:::deployment
        Deployment_Interface["Command-Line/Deployment Interface"]:::deployment
    end

    subgraph "Server Core"
        MCP_Server["MCP Server Core"]:::core
        subgraph "Internal Modules"
            Command_Handler["MCP Command Handler"]:::core
            Note_Storage["Note Storage & Summarization"]:::core
            Playwright_Tools["Playwright Tools Module<br/>(navigate, screenshot, click, fill, evaluate, get content)"]:::core
        end
    end

    MCP_Client -->|"send_commands"| Command_Handler
    Deployment_Interface -->|"deploy_configure"| MCP_Server
    PyProject -->|"configure"| Deployment_Interface
    UV_Lock -->|"lock_dependencies"| Deployment_Interface
    Command_Handler -->|"dispatch_note_cmds"| Note_Storage
    Command_Handler -->|"dispatch_playwright_cmds"| Playwright_Tools
    Playwright_Tools -->|"invoke_automation"| External_Browser
    External_Browser -->|"return_response"| Playwright_Tools
    Note_Storage -->|"generate_summary"| Command_Handler
    Command_Handler -->|"return_response"| MCP_Client
    MCP_Inspector --- MCP_Server

    click MCP_Server "https://github.com/blackwhite084/playwright-plus-python-mcp/blob/master/src/playwright_server/server.py"
    click Note_Storage "https://github.com/blackwhite084/playwright-plus-python-mcp/blob/master/src/playwright_server/server.py"
    click Playwright_Tools "https://github.com/blackwhite084/playwright-plus-python-mcp/blob/master/src/playwright_server/server.py"
    click PyProject "https://github.com/blackwhite084/playwright-plus-python-mcp/blob/master/pyproject.toml"
    click UV_Lock "https://github.com/blackwhite084/playwright-plus-python-mcp/blob/master/uv.lock"

    classDef core fill:#AED6F1,stroke:#3498DB,stroke-width:2px;
    classDef external fill:#ABEBC6,stroke:#27AE60,stroke-width:2px;
    classDef deployment fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
```
