深度链接(deeplinks)
Cursor 深度链接概览
MCP 服务器安装
可通过 Cursor 深度链接安装 MCP 服务器。其配置格式基于 mcp.json,包含名称和传输配置。
链接格式
安装链接格式如下:
cursor://anysphere.cursor-deeplink/mcp/install?name=$NAME&config=$BASE64_ENCODED_CONFIG
组件 | 描述 |
---|---|
cursor:// | 协议方案 |
anysphere.cursor-deeplink | 深度链接处理器 |
/mcp/install | 路径 |
name | 服务器名称的查询参数 |
config | Base64 编码的 JSON 配置的查询参数 |
生成安装链接
- 🔧 链接生成器
- 📋 配置示例
- 📖 手动生成
JSON 配置
在下方输入您的MCP服务器配置:
✅ 检测到服务器: postgres
配置示例
以下是一些常用的MCP服务器配置示例,您可以复制使用:
PostgreSQL
PostgreSQL数据库连接
配置示例
{
"postgres": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://localhost/mydb"
]
}
}
SQLite
SQLite数据库连接
配置示例
{
"sqlite": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-sqlite",
"--db-path",
"./database.sqlite"
]
}
}
File System
文件系统访问
配置示例
{
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/path/to/allowed/files"
]
}
}
如果您希望手动生成安装链接,请按照以下步骤:
- 获取服务器配置:准备您的 MCP 服务器 JSON 配置
- 序列化配置:使用
JSON.stringify()
将配置对象转换为字符串 - Base64 编码:对序列化后的配置进行 base64 编码
- 构建链接:将服务器名称和编码后的配置替换到链接模板中
JavaScript 示例代码:
// 1. 准备配置对象
const serverConfig = {
"postgres": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://localhost/mydb"
]
}
};
// 2. 获取服务器名称和配置
const serverName = Object.keys(serverConfig)[0]; // "postgres"
const config = serverConfig[serverName];
// 3. 序列化并编码
const configString = JSON.stringify(config);
const base64Config = btoa(configString);
// 4. 生成安装链接
const installLink = `cursor://anysphere.cursor-deeplink/mcp/install?name=${serverName}&config=${base64Config}`;
console.log(installLink);
Python 示例代码:
import json
import base64
# 1. 准备配置
server_config = {
"postgres": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://localhost/mydb"
]
}
}
# 2. 获取服务器名称和配置
server_name = list(server_config.keys())[0]
config = server_config[server_name]
# 3. 序列化并编码
config_string = json.dumps(config)
base64_config = base64.b64encode(config_string.encode()).decode()
# 4. 生成安装链接
install_link = f"cursor://anysphere.cursor-deeplink/mcp/install?name={server_name}&config={base64_config}"
print(install_link)