Cover image
Try Now
2025-03-31

Chrome扩展桥,使您可以连接到MCP服务器以使用全局窗口对象。

3 years

Works with Finder

1

Github Watches

0

Github Forks

9

Github Stars

Chrome Extension Bridge MCP

A Chrome extension that establishes a WebSocket connection between web pages and a local MCP server. This allows you to interact with web page resources and execute functions from your mcp server.

Inspired by playcanvas/editor-mcp-server.

Example

Overview

This project consists of two main components:

  1. Chrome Extension: Injects a client script into web pages that establishes a WebSocket connection to your local server.
  2. Local MCP Server: A WebSocket server that can send commands to the extension and receive responses.

With this setup, you can:

  • Access browser APIs and DOM elements from your local server
  • Execute JavaScript functions in the context of web pages
  • Retrieve resources and information from web pages
  • Especially, access the global object like editor, e.x : https://threejs.org/editor/. You can use window.editor which is exposed by the website to control the editor. Just like playcanvas/editor-mcp-server.

Installation

Setup

  1. Clone the repository:
git clone https://github.com/yourusername/chrome-extension-socket-mcp.git
cd chrome-extension-socket-mcp
  1. Install dependencies:
npm install

Development

Run the following command to build the extension in development mode:

npm run debug

Loading the Extension

  1. Open Chrome and navigate to chrome://extensions/
  2. Enable "Developer mode" by toggling the switch in the top right corner
  3. Click "Load unpacked" and select the extension folder from this project
  4. The extension is now installed. You should see a small red indicator in the top right corner of any web page indicating "MCP Extension Loaded"

Usage

Server-side

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod"; 
import { Client } from "../src/client";

// Define the port for WebSocket connection
// This should match the port in your Chrome extension's WebSocket connection
const port = 54319;
const client = new Client(port);

// Establish connection to the Chrome extension
await client.connect();

// Create a new MCP server instance with name and version
const server = new McpServer({
  name: "Extension-Socket-Server",
  version: "1.0.0",
});

// Register a tool that executes the window.alert function in the browser
// This demonstrates how to interact with browser APIs from your server
server.tool(
  "alert",                  // Tool name
  "use window.alert",       // Tool description
  { message: z.string() },  // Tool parameters schema using Zod
  async ({ message }) => {  // Tool implementation function
    // Call the extension to execute alert in the browser context
    const response = await client.callToolExtension("alert", { message });
    return response;
  }
);

// Register a resource to retrieve the browser's user agent
// This demonstrates how to access browser properties from your server
server.resource(
  "userAgent",              // Resource name
  "useragent://chrome",     // Resource URI template
  async (uri) => {          // Resource handler function
    // Get the user agent from the browser
    const { content } = await client.callResourceExtension("navigator.userAgent");
    // Return the formatted resource
    return {
      contents: [
        {
          uri: uri.href,
          text: content[0].text,
        },
      ],
    };
  }
);

// Set up a transport layer for the MCP server
// StdioServerTransport uses standard input/output for communication
const transport = new StdioServerTransport();
await server.connect(transport);

// Handle application termination gracefully
process.on("SIGINT", async () => {
  console.log("SIGINT signal received");  // Log when SIGINT is received
  await client.dispose();                 // Close the WebSocket connection
  process.exit(0);                        // Exit the process
});

Extension-side

The extension automatically connects to ws://localhost:54319 by default. You can modify this in extension/content.js.

The extension exposes two main entry points for server commands:

  • mcp:resource.* - For accessing browser resources and properties
  • mcp:tool.* - For executing functions in the browser context

API Reference

Client

  • new Client(port) - Create a new client instance connecting to specified port
  • connect() - Connect to the MCP server
  • callToolExtension(toolName, params) - Call a tool in the browser
  • callResourceExtension(resourceName, params) - Get a resource from the browser
  • dispose() - Close the connection

WebSocket Protocol

The extension uses a simple JSON-RPC-like protocol:

Request:

{
  "id": "unique-request-id",
  "method": "mcp:resource.navigator.userAgent",
  "params": {}
}

Response:

{
  "id": "unique-request-id",
  "result": "Mozilla/5.0 ..."
}

License

MIT

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Lists Tailwind CSS classes in monospaced font

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • https://appia.in
  • Siri Shortcut Finder – your go-to place for discovering amazing Siri Shortcuts with ease

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Daren White
  • A supportive coach for mastering all Spanish tenses.

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

  • HiveNexus
  • 一个适用于中小型团队的AI聊天机器人,支持DeepSeek,Open AI,Claude和Gemini等车型。 专为中小团队设计的ai聊天应用,支持deepSeek,打开ai,claude,双子座等模型。

  • ravitemer
  • 一个功能强大的Neovim插件,用于管理MCP(模型上下文协议)服务器

  • patruff
  • Ollama和MCP服务器之间的桥梁,使本地LLMS可以使用模型上下文协议工具

    Reviews

    5 (1)
    Avatar
    user_grvpg289
    2025-04-18

    chrome-extension-bridge-mcp by Oanakiaja is an outstanding tool for enhancing my web browsing experience. It seamlessly bridges multiple platforms and provides a smooth and efficient workflow. The intuitive interface and robust performance make it a must-have extension for Chrome users. Highly recommended for anyone looking to boost productivity and streamline their online activities. Check it out on GitHub!