(
name: string,
configManager: ConfigManager,
options: {
scope: 'local' | 'user' | 'project'
transport?: string
url?: string
headers?: string[]
envVars?: string[]
}
)
| 534 | } |
| 535 | |
| 536 | async function addRemoteMCPServer( |
| 537 | name: string, |
| 538 | configManager: ConfigManager, |
| 539 | options: { |
| 540 | scope: 'local' | 'user' | 'project' |
| 541 | transport?: string |
| 542 | url?: string |
| 543 | headers?: string[] |
| 544 | envVars?: string[] |
| 545 | } |
| 546 | ): Promise<void> { |
| 547 | const spinner = logger.spinner(`Adding remote MCP server: ${name}`) |
| 548 | |
| 549 | try { |
| 550 | // Validate transport and URL |
| 551 | if (options.transport && !['stdio', 'sse', 'http'].includes(options.transport)) { |
| 552 | throw new Error(`Invalid transport: ${options.transport}. Must be stdio, sse, or http`) |
| 553 | } |
| 554 | |
| 555 | if ((options.transport === 'sse' || options.transport === 'http') && !options.url) { |
| 556 | throw new Error(`URL is required for ${options.transport} transport`) |
| 557 | } |
| 558 | |
| 559 | spinner.stop() |
| 560 | |
| 561 | // Show server details |
| 562 | logger.info(`\nAdding remote MCP server: ${name}`) |
| 563 | logger.info(`Transport: ${options.transport || 'stdio'}`) |
| 564 | if (options.url) { |
| 565 | logger.info(`URL: ${options.url}`) |
| 566 | } |
| 567 | logger.info(`Scope: ${options.scope}`) |
| 568 | |
| 569 | // Parse headers |
| 570 | const headers: Record<string, string> = {} |
| 571 | if (options.headers) { |
| 572 | for (const header of options.headers) { |
| 573 | const [key, ...valueParts] = header.split(':') |
| 574 | if (key && valueParts.length > 0) { |
| 575 | headers[key.trim()] = valueParts.join(':').trim() |
| 576 | } |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | // Parse environment variables |
| 581 | const env: Record<string, string> = {} |
| 582 | if (options.envVars) { |
| 583 | for (const envVar of options.envVars) { |
| 584 | const [key, value] = envVar.split('=') |
| 585 | if (key && value) { |
| 586 | env[key] = value |
| 587 | } |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | spinner.start() |
| 592 | |
| 593 | // Create the MCP server configuration |
no test coverage detected