interface McpServerConfig {
command?: string;
args?: string[];
url?: string;
env?: Record<string, string>;
}
function generateMcpAddDeeplink(name: string, config: McpServerConfig): string {
if (!name) {
throw new Error('缺少必需参数: name');
}
if (!config) {
throw new Error('缺少必需参数: config');
}
if (!config.command && !config.url) {
throw new Error('配置必须包含 "command" 或 "url"');
}
const configJson = JSON.stringify(config);
const base64Config = btoa(encodeURIComponent(configJson));
const encodedName = encodeURIComponent(name);
const encodedConfig = encodeURIComponent(base64Config);
return `qoder://aicoding.aicoding-deeplink/mcp/add?name=${encodedName}&config=${encodedConfig}`;
}
// 示例 1: PostgreSQL MCP 服务器
const postgresDeeplink = generateMcpAddDeeplink('postgres', {
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-postgres', 'postgresql://localhost/mydb']
});
console.log(postgresDeeplink);
// 示例 2: 带环境变量的 GitHub MCP 服务器
const githubDeeplink = generateMcpAddDeeplink('github', {
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-github'],
env: { GITHUB_PERSONAL_ACCESS_TOKEN: '<YOUR_TOKEN>' }
});
console.log(githubDeeplink);
// 示例 3: 基于 HTTP 的 MCP 服务器
const httpDeeplink = generateMcpAddDeeplink('custom-server', {
url: 'https://mcp.example.com/sse'
});
console.log(httpDeeplink);