(
name: string,
config: McpServerConfig,
)
| 95 | } |
| 96 | |
| 97 | async connect( |
| 98 | name: string, |
| 99 | config: McpServerConfig, |
| 100 | ): Promise<MCPServerConnection> { |
| 101 | if (!this.connectFn) { |
| 102 | throw new Error( |
| 103 | 'McpManager: connectFn not set. Call setConnectFn() first.', |
| 104 | ) |
| 105 | } |
| 106 | |
| 107 | const scopedConfig: ScopedMcpServerConfig = { ...config, scope: 'dynamic' } |
| 108 | |
| 109 | try { |
| 110 | const connection = await this.connectFn(name, scopedConfig) |
| 111 | this.connections.set(name, connection) |
| 112 | |
| 113 | if (connection.type === 'connected') { |
| 114 | this.emit('connected', name) |
| 115 | // Fetch tools for this server |
| 116 | await this.refreshTools(name, connection) |
| 117 | } else if (connection.type === 'needs-auth') { |
| 118 | this.emit('authRequired', name) |
| 119 | } |
| 120 | |
| 121 | return connection |
| 122 | } catch (err) { |
| 123 | const error = err instanceof Error ? err : new Error(String(err)) |
| 124 | this.emit('error', name, error) |
| 125 | throw err |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | async disconnect(name: string): Promise<void> { |
| 130 | const conn = this.connections.get(name) |
nothing calls this directly
no test coverage detected