Chrome MCP Server

repository·master·Indexed 11 days ago

https://github.com/hangwin/mcp-chrome

A Model Context Protocol (MCP) server implemented as a Chrome extension that allows AI models to automate browsing, analyze content, and manage data using existing browser sessions. It includes a Fastify-based Native Messaging service for bidirectional communication and a SIMD-optimized WebAssembly package (@chrome-mcp/wasm-simd) for high-performance vector operations. The server provides over 20 tools for browser management, network monitoring, content analysis, and interaction.

Tokens
29.2K
Snippets
82
Records
131
Agent score
95%

What's inside Chrome MCP Server

  1. Overview of @chrome-mcp/wasm-simd

    master
    The @chrome-mcp/wasm-simd package provides SIMD-optimized WebAssembly math functions designed for high-performance vector operations. It is primarily used to accelerate tasks like cosine similarity, batch processing, and matrix operations by leveraging WebAssembly SIMD instructions, offering significant speedups (typically 4-8x) compared to standard JavaScript implementations.
  2. What is Chrome MCP Server?

    master

    Chrome MCP Server is a Model Context Protocol (MCP) server implemented as a Chrome extension. It allows AI assistants (like Claude) to interact directly with your existing Chrome browser.

    Unlike automation tools like Playwright that launch fresh, isolated browser instances, Chrome MCP Server uses your actual browser, meaning it inherits your existing:

    • User configurations and settings
    • Login states and active sessions
    • Bookmarks and history

    This enables seamless AI-driven browser automation, content analysis, and semantic search within your daily browsing environment.

  3. Create a Full Excalidraw Element Skeleton

    master

    When adding elements via the addElement action, the script uses an internal helper createFullExcalidrawElement(skeleton) to ensure elements have all required properties.

    If you are providing a partial element (a "skeleton"), the script will automatically inject the following properties:

    • id: A unique random string.
    • seed: A random integer.
    • versionNonce: A random integer.
    • updated: Current timestamp.
    • isDeleted: false (default).
    • fillStyle: 'hachure' (default).
    • strokeWidth: 1 (default).
    • strokeStyle: 'solid' (default).
    • roughness: 1 (default).
    • opacity: 100 (default).
    • angle: 0 (default).
    • groupIds: [] (default).
    • strokeColor: '#000000' (default).
    • backgroundColor: 'transparent' (default).
    • version: 1 (default).
    • locked: false (default).

    Note: Any properties provided in your skeleton object will override these defaults.

  4. Understand the Chrome MCP Server Architecture

    master

    Chrome MCP Server is a browser automation platform that connects AI assistants to Chrome browser functionality via the Model Context Protocol (MCP). The architecture is divided into several layers:

    1. AI Assistant Layer: Clients like Claude Desktop or custom MCP clients.
    2. MCP Protocol Layer: Handles HTTP/SSE transport, manages the MCP server instance, and maintains a tool registry.
    3. Native Server Layer (app/native-server/): A Fastify-based HTTP server that implements the MCP protocol and acts as a bridge to Chrome via Native Messaging.
    4. Chrome Extension Layer (app/chrome-extension/): Built with WXT and Vue 3, it contains background scripts (coordinators), content scripts (interaction/extraction), popup interfaces, and offscreen documents (for AI processing).
    5. Browser APIs Layer: Accesses Chrome and Web APIs.
    6. AI Processing Layer: Includes a semantic engine, vector database, and a SIMD-optimized math engine using WebAssembly.
  5. Understand the ExcalidrawElementSkeleton concept

    master

    When adding elements to Excalidraw via programming, you should create ExcalidrawElementSkeleton objects instead of full ExcalidrawElement objects. A skeleton is a simplified object designed for programmatic creation. The Excalidraw frontend will automatically complete necessary properties like version numbers and random seeds.

    Core Principle: Always provide a unique id for elements, especially when you intend to create relationships like bindings, containers, or groups.

  6. How tool execution flows through the system

    master

    When an AI assistant triggers a tool, the request follows this sequence:

    1. AI Assistant sends a tool call to the Native Server.
    2. Native Server forwards the request to the Chrome Extension via Native Messaging.
    3. Chrome Extension executes the tool using Browser APIs.
    4. Browser APIs return a response to the Chrome Extension.
    5. Chrome Extension sends the tool result back to the Native Server.
    6. Native Server sends the final MCP response back to the AI Assistant.
  7. How the Chrome MCP Server architecture works

    master

    Chrome MCP Server uses a multi-layered architecture to bridge AI assistants (like Claude Desktop) with Chrome browser capabilities via the Model Context Protocol (MCP).

    The Four Main Layers:

    1. AI Assistant Layer: The client (e.g., Claude Desktop or custom MCP clients) that initiates requests.
    2. MCP Protocol Layer: Handles communication via HTTP/SSE and manages the Tool Registry and MCP Server instance.
    3. Native Server Layer: A Fastify-based server that acts as a bridge using Native Messaging to communicate with the Chrome extension.
    4. Chrome Extension Layer: The orchestrator within the browser, using Background Scripts, Content Scripts, and Offscreen Documents to execute tools and access Chrome/Web APIs.

    Data Flow for Tool Execution:

    1. AI Assistant sends a Tool Call to the Native Server.
    2. Native Server sends a Native Message to the Chrome Extension.
    3. Chrome Extension executes the tool via Browser APIs.
    4. The API Response flows back through the Extension $\rightarrow$ Native Server $\rightarrow$ AI Assistant as an MCP Response.
    graph TB
        subgraph "AI Assistant Layer"
            A[Claude Desktop]
            B[Custom MCP Client]
            C[Other AI Tools]
        end
    
        subgraph "MCP Protocol Layer"
            D[HTTP/SSE Transport]
            E[MCP Server Instance]
            F[Tool Registry]
        end
    
        subgraph "Native Server Layer"
            G[Fastify HTTP Server]
            H[Native Messaging Host]
            I[Session Management]
        end
    
        subgraph "Chrome Extension Layer"
            J[Background Script]
            K[Content Scripts]
            L[Popup Interface]
            M[Offscreen Documents]
        end
    
        subgraph "Browser APIs Layer"
            N[Chrome APIs]
            O[Web APIs]
            P[Native Messaging]
        end
    
        subgraph "AI Processing Layer"
            Q[Semantic Engine]
            R[Vector Database]
            S[SIMD Math Engine]
            T[Web Workers]
        end
  8. How AI content processing works

    master

    The AI processing pipeline follows these steps:

    1. Content Extraction provides raw content to the Text Chunker.
    2. The Text Chunker breaks content into text blocks.
    3. The Semantic Engine converts blocks into Embedding Vectors.
    4. The Vector Database stores and manages these vectors.
    5. For searches, a Search Query is converted into a Query Vector, which is used to find Similar Documents in the database.
  9. Integrate with Python (Non-AI Agent usage)

    master
    Users have inquired about accessing the MCP server directly via code (e.g., Python) without using an AI agent. While specific demo code is not provided in this issue log, the project supports programmatic access. Refer to the official documentation or check for existing Python integration patterns if you intend to call tools directly via script.
  10. How to group elements and use frames

    master

    Grouping

    To group multiple elements so they can be selected and moved as a single unit, assign them the exact same groupIds array. Example: groupIds: ["auth-group"].

    Framing

    To organize large areas (like architectural layers), use a frame element.

    1. Create an element with type: "frame" and give it an id and a name.
    2. For every element you want inside that frame, set its frameId property to the frame's id.
    [
      {
        "id": "data-layer-frame",
        "type": "frame",
        "x": 50,
        "y": 400,
        "width": 600,
        "height": 300,
        "name": "数据存储层"
      },
      {
        "id": "postgres-db",
        "type": "rectangle",
        "frameId": "data-layer-frame",
        "x": 75,
        "y": 480
      }
    ]
  11. Use the Input Container system for property controls

    master

    The property panel uses a container-based input system instead of standalone <input> elements. This allows for prefixing (labels/icons) and suffixing (units/icons) while maintaining consistent hover and focus styles via the :focus-within pseudo-class.

    Target HTML Structure:

    <div class="we-field">
      <span class="we-field-label">Label Name</span>
      <div class="we-input-container">
        <span class="we-input-container__prefix">Prefix</span>
        <input class="we-input-container__input" />
        <span class="we-input-container__suffix">Suffix</span>
      </div>
    </div>

    Implementation Details:

    • Styles for .we-input-container, .we-input-container__prefix, and .we-input-container__suffix are defined in shadow-host.ts.
    • The ui/property-panel/components/input-container.ts component manages this structure.
    • Use the css-helpers.ts module (providing extractUnitSuffix, hasExplicitUnit, and normalizeLength) to handle unit logic within these containers.
    <div class="we-field">
      <span class="we-field-label">Position</span>
      <div class="we-input-container">
        <span class="we-input-container__prefix">X</span>
        <input class="we-input-container__input" />
        <span class="we-input-container__suffix">px</span>
      </div>
    </div>
  12. How AI processing and semantic search works

    master

    The system performs AI-powered content analysis through a specialized processing pipeline:

    1. Content Extraction: Raw content is pulled from the browser.
    2. Text Chunking: Content is broken into manageable chunks.
    3. Semantic Engine: Chunks are converted into embeddings using supported models (e.g., BGE-small-en-v1.5, E5-small-v2, or Universal Sentence Encoder).
    4. Vector Database: Embeddings are stored in a hnswlib-wasm vector database (using the HNSW algorithm) for efficient retrieval.
    5. Search: When a query is made, the system generates a query vector and performs a similarity search against the stored document vectors to return the most relevant results.

    Processing is optimized using Web Workers for non-blocking execution and SIMD acceleration for vector math.