在介绍了 CodeBuddy 的协议支持后,今天我们将介绍如何通过 Protocol Launcher 与 Trae 联动,让 AI 原生编程体验更加流畅。
作为开发者,你可能经常遇到这些场景:
- 在文档中提供一个「在 Trae 中打开」的按钮,方便用户快速体验 AI 编程。
- 一键安装 MCP 服务,让团队成员快速配置 AI 扩展能力。
- 直接打开远程开发环境,无缝衔接本地与云端工作流。
- 分享自定义 Agent,让团队复用优秀的 AI 工作模式。
现在,通过 Protocol Launcher,你可以以类型安全的方式生成深度链接,极大提升 AI 编程协作效率。
Trae 与深度链接
Trae 是字节跳动推出的一款 AI 原生代码编辑器,提供 SOLO Coder、SOLO Builder 等智能编程模式,支持 MCP Server 扩展、自定义 Agent、多任务处理等功能。
Trae 基于 VS Code 构建,因此继承了其强大的深度链接协议支持。你可以从网页或第三方应用直接触发以下操作:
- 打开文件或文件夹
- 安装 MCP 服务(支持 stdio、HTTP Streamable、SSE 三种类型)
- 连接远程开发环境(SSH、WSL、Dev Container)
- 打开扩展或自定义 Agent
- 直接跳转到特定设置页面
然而,手动拼接这些链接需要处理复杂的参数编码和协议格式,极易出错。
核心能力:AI 原生编辑器的全场景支持
Protocol Launcher 为 Trae 专门提供了 protocol-launcher/trae 模块,支持以下核心功能:
- 基础打开能力:一键唤起 Trae 编辑器,打开本地文件或文件夹。
- MCP 服务安装:支持三种 MCP 类型(stdio、http、sse),自动处理配置编码。
- 远程开发:支持 SSH Remote、WSL、Dev Container 三种远程模式。
- 扩展与 Agent:直接打开扩展详情页或分享自定义 Agent。
- 设置跳转:直接定位到特定设置项,方便配置引导。
快速上手
首先,确保你的项目中已安装:
bash
npm install protocol-launcher
在代码中你可以根据场景选择两种导入方式:
- 按需加载(通过子路径导入),支持 Tree Shaking,体积更小;
- 全量导入(从根包导入),写法更简单,但会引入所有已支持应用的逻辑。
typescript
// ✅ 推荐:按需加载 Trae 模块
import { open, openFile, installMCP } from 'protocol-launcher/trae'
// 也可以从根包导入,但会包含所有应用模块
// import { trae } from 'protocol-launcher'
场景一:一键打开 Trae 编辑器 (open)
最简单的用法,直接唤起 Trae:
typescript
import { open } from 'protocol-launcher/trae'
const url = open()
// => 'trae://'
场景二:打开本地文件 (openFile)
在 Trae 中打开特定文件,并可选定位到具体行列:
typescript
import { openFile } from 'protocol-launcher/trae'
const url = openFile({
path: '/etc/hosts', // 文件路径
line: 10, // 可选:行号
column: 5, // 可选:列号
openInNewWindow: true, // 可选:在新窗口打开
})
// => 'trae://file/etc/hosts:10:5?windowId=_blank'
场景三:打开文件夹 (openFolder)
直接在 Trae 中打开项目文件夹:
typescript
import { openFolder } from 'protocol-launcher/trae'
const url = openFolder({
path: '/code/my-project', // 文件夹路径
openInNewWindow: true, // 可选:在新窗口打开
})
// => 'trae://file/code/my-project?windowId=_blank'
场景四:安装 MCP 服务 (installMCP)
这是 Trae 的核心功能之一。Protocol Launcher 支持三种 MCP 类型:
1. STDIO 类型的 MCP 服务
typescript
import { installMCP } from 'protocol-launcher/trae'
const url = installMCP({
name: 'server-everything',
type: 'stdio',
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-everything'],
})
// => 'trae://trae.ai-ide/mcp-import?name=server-everything&type=stdio&config=...'
2. Streamable HTTP 类型的 MCP 服务
typescript
import { installMCP } from 'protocol-launcher/trae'
const url = installMCP({
name: '企查查企业信息 MCP',
type: 'http',
url: 'https://mcp.qcc.com/basic/stream',
headers: {
Authorization: 'REPLACE_WITH_YOUR_TOKEN',
},
})
3. SSE 类型的 MCP 服务
typescript
import { installMCP } from 'protocol-launcher/trae'
const url = installMCP({
name: '企查查风险信息 MCP',
type: 'http',
url: 'https://mcp.qcc.com/basic/sse',
headers: {
Authorization: 'REPLACE_WITH_YOUR_TOKEN',
},
})
场景五:远程开发 (openRemote)
Trae 支持三种远程开发模式,与 VS Code Remote 兼容:
1. SSH Remote
typescript
import { openRemote } from 'protocol-launcher/trae'
const url = openRemote({
type: 'ssh-remote',
host: 'root@172.18.105.209:22', // SSH 连接目标
path: '/code/my-project', // 远程路径
})
// => 'trae://vscode-remote/ssh-remote+root@172.18.105.209:22/code/my-project'
2. WSL
typescript
import { openRemote } from 'protocol-launcher/trae'
const url = openRemote({
type: 'wsl',
host: 'Ubuntu-22.04', // WSL 发行版名称
path: '/home/user/my-project',
})
3. Dev Container
typescript
import { openRemote } from 'protocol-launcher/trae'
const url = openRemote({
type: 'dev-container',
host: 'my-project-container', // 容器标识
path: '/workspace',
})
场景六:打开扩展 (openExtension)
直接跳转到扩展详情页:
typescript
import { openExtension } from 'protocol-launcher/trae'
const url = openExtension({
id: 'esbenp.prettier-vscode',
})
// => 'trae:extension/esbenp.prettier-vscode'
场景七:打开自定义 Agent (openAgent)
分享自定义 Agent 给团队成员:
typescript
import { openAgent } from 'protocol-launcher/trae'
const url = openAgent({
agentId: '878f64',
})
// => 'trae://trae.ai-ide/agent/share/878f64'
场景八:打开设置页面 (openSettings)
直接定位到特定设置项:
typescript
import { openSettings } from 'protocol-launcher/trae'
const url = openSettings({
path: 'terminal.integrated.suggest.enabled',
})
// => 'trae://settings/terminal.integrated.suggest.enabled'
为什么选择 Protocol Launcher?
- 自动编码与参数处理 :MCP 配置等复杂参数需要 URL 编码。库内部会自动处理所有转义逻辑,确保生成的 URL 绝不乱码。
- 类型安全与智能提示:TypeScript 类型定义完整,IDE 会提示所有可用参数,避免拼写错误。
- 协议兼容性:Trae 基于 VS Code 构建,Protocol Launcher 自动处理协议兼容性问题,确保在不同场景下都能正常工作。
- MCP 全类型支持:完整支持 stdio、http(含 Streamable 和 SSE)三种 MCP 类型,覆盖所有主流使用场景。
- 远程开发无缝衔接:与 VS Code Remote 协议兼容,SSH、WSL、Dev Container 三种模式一网打尽。
- 极致的按需加载 (Tree Shaking) :
- 推荐方式 :使用子路径导入(如
import { installMCP } from 'protocol-launcher/trae'),构建工具只会打包相关代码。 - 全量方式 :从根包导入(如
import { trae } from 'protocol-launcher')会包含所有应用模块,适合快速原型开发。
- 推荐方式 :使用子路径导入(如
结语
通过 Protocol Launcher,你可以将 Trae 的 AI 编程能力无缝集成到文档、内部平台或协作工具中。无论是引导用户安装 MCP 服务,还是分享自定义 Agent,它都是连接 Web 与本地 AI 编辑器最优雅的桥梁。
🔗 相关链接
- Protocol Launcher 官网:https://protocol-launcher.huayi-data.com/
- Trae 模块文档:Trae | Protocol Launcher