Token导航 LogoToken导航TokenDH.com
MCP Chrome Bridge logo
运维云端未说明官方级别未说明来源级核验

MCP Chrome Bridge

MCP Server

基于Fastify的TypeScript项目,提供与Chrome扩展的原生通信能力,支持RESTful API和双向消息传递。

工具数

0

提示词数

0

GitHub Stars

0

资源数

0
TypeScriptAPI集成云端部署

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

missbjs

提供方

missbjs

最后核验

2026/5/17 20:21

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

Fastify Chrome Native Messaging服务

这是一个基于Fastify的TypeScript项目,用于与Chrome扩展进行原生通信。

功能特性

  • 通过Chrome Native Messaging协议与Chrome扩展进行双向通信
  • 提供RESTful API服务
  • 完全使用TypeScript开发
  • 包含完整的测试套件
  • 遵循代码质量最佳实践

开发环境设置

前置条件

  • Node.js 14+
  • npm 6+

安装

git clone https://github.com/your-username/fastify-chrome-native.git
cd fastify-chrome-native
npm install

开发

  1. 本地构建注册native server
cd app/native-server
npm run dev
  1. 启动chrome extension
cd app/chrome-extension
npm run dev

构建

npm run build

注册Native Messaging主机

全局安装后会自动注册

npm i -g @vicoplus/mcp-chrome-bridge

与Chrome扩展集成

以下是Chrome扩展中如何使用此服务的简单示例:

// background.js
let nativePort = null;
let serverRunning = false;

// 启动Native Messaging服务
function startServer() {
  if (nativePort) {
    console.log('已连接到Native Messaging主机');
    return;
  }
  
  try {
    nativePort = chrome.runtime.connectNative('com.yourcompany.fastify_native_host');
    
    nativePort.onMessage.addListener(message => {
      console.log('收到Native消息:', message);
      
      if (message.type === 'started') {
        serverRunning = true;
        console.log(`服务已启动,端口: ${message.payload.port}`);
      } else if (message.type === 'stopped') {
        serverRunning = false;
        console.log('服务已停止');
      } else if (message.type === 'error') {
        console.error('Native错误:', message.payload.message);
      }
    });
    
    nativePort.onDisconnect.addListener(() => {
      console.log('Native连接断开:', chrome.runtime.lastError);
      nativePort = null;
      serverRunning = false;
    });
    
    // 启动服务器
    nativePort.postMessage({ type: 'start', payload: { port: 3000 } });
    
  } catch (error) {
    console.error('启动Native Messaging时出错:', error);
  }
}

// 停止服务器
function stopServer() {
  if (nativePort && serverRunning) {
    nativePort.postMessage({ type: 'stop' });
  }
}

// 测试与服务器的通信
async function testPing() {
  try {
    const response = await fetch('http://localhost:3000/ping');
    const data = await response.json();
    console.log('Ping响应:', data);
    return data;
  } catch (error) {
    console.error('Ping失败:', error);
    return null;
  }
}

// 在扩展启动时连接Native主机
chrome.runtime.onStartup.addListener(startServer);

// 导出供popup或内容脚本使用的API
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
  if (message.action === 'startServer') {
    startServer();
    sendResponse({ success: true });
  } else if (message.action === 'stopServer') {
    stopServer();
    sendResponse({ success: true });
  } else if (message.action === 'testPing') {
    testPing().then(sendResponse);
    return true; // 指示我们将异步发送响应
  }
});

测试

npm run test

许可证

MIT "# mcp-chrome-bridge"

目录标签

目录标签

TypeScriptAPI集成云端部署Chrome扩展本地部署原生通信RESTfulAPI双向通信

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明none部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP