浏览器功能调用服务

Bifrost是一个MCP服务器,允许AI工具调用在浏览器中运行的函数,适用于AI与浏览器交互的开发场景。

  • by Business-Maps
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 Business-Maps/bifrost

使用说明

@商业地图/双名册

MCP服务器,允许AI工具调用浏览器中运行的函数。

守护进程位于任何MCP客户端和浏览器选项卡之间。它一边通过stdio与JSON-RPC通信,另一边通过WebSocket通信。你的浏览器应用程序连接、注册工具,人工智能可以调用它们。

快速开始

1.添加到您的AI工具

克劳德代码:

claude mcp add --transport stdio bifrost -- npx @businessmaps/bifrost --no-auth

克劳德桌面版 -添加到 ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "bifrost": {
      "command": "npx",
      "args": ["@businessmaps/bifrost", "--no-auth"]
    }
  }
}

光标 -添加到 .cursor/mcp.json:

{
  "mcpServers": {
    "bifrost": {
      "command": "npx",
      "args": ["@businessmaps/bifrost", "--no-auth"]
    }
  }
}

无需安装。 npx 自动下载并运行该包。

2.将客户端添加到浏览器应用程序

npm i @businessmaps/bifrost-browser

或者通过CDN:

<script src="https://unpkg.com/@businessmaps/bifrost-browser"></script>

包含TypeScript类型。

3.登记工具

import { BifrostBrowser } from "@businessmaps/bifrost-browser";

const bridge = new BifrostBrowser({ port: 3099 });

bridge.registerTools([
  {
    name: "get_page_title",
    description: "Returns the page title",
    inputSchema: { type: "object", properties: {} },
    handler: async () => document.title,
  },
  {
    name: "get_selection",
    description: "Returns the user's current text selection",
    inputSchema: { type: "object", properties: {} },
    handler: async () => window.getSelection().toString(),
  },
]);

bridge.connect();

就是这样。人工智能现在可以呼叫 get_page_title 和 get_selection 在浏览器选项卡中。处理程序可以完全访问DOM、Canvas、IndexedDB、剪贴板, fetch等等。

认证

默认情况下,守护进程在启动时生成随机令牌。有两种方法可以获得它:

  • 终端模式 -守护进程启动时,令牌会打印到屏幕上
  • MCP模式 -AI调用内置 bifrost_connection_info 工具获取令牌,然后告诉您要粘贴到应用程序中的内容

将令牌传递给客户端:

const bridge = new BifrostBrowser({ port: 3099, token: "TOKEN" });

完全跳过身份验证 --no-auth 在地方发展过程中。

多个标签页

每个选项卡都注册了自己的工具。调用路由给拥有该工具的人。断开选项卡的连接会删除其工具。

选项

--port <port>     WebSocket port        (default: 3099)
--timeout <secs>  Tool call timeout     (default: 120)
--no-auth         Disable token auth    (dev only)
--help, -h        Show this message
--version, -v     Show version

开发

git clone https://github.com/Business-Maps/bifrost.git && cd bifrost
npm install
npm test

建筑 · 客户端API · 贡献

许可证

Apache 2.0