* Helper method to find a connection by server name and source * @param serverName The name of the server to find * @param source Optional source to filter by (global or project) * @returns The matching connection or undefined if not found
(serverName: string, source?: "global" | "project")
| 1376 | * @returns The matching connection or undefined if not found |
| 1377 | */ |
| 1378 | private findConnection(serverName: string, source?: "global" | "project"): McpConnection | undefined { |
| 1379 | // If source is specified, only find servers with that source |
| 1380 | if (source !== undefined) { |
| 1381 | return this.connections.find((conn) => conn.server.name === serverName && conn.server.source === source) |
| 1382 | } |
| 1383 | |
| 1384 | // If no source is specified, first look for project servers, then global servers |
| 1385 | // This ensures that when servers have the same name, project servers are prioritized |
| 1386 | const projectConn = this.connections.find( |
| 1387 | (conn) => conn.server.name === serverName && conn.server.source === "project", |
| 1388 | ) |
| 1389 | if (projectConn) return projectConn |
| 1390 | |
| 1391 | // If no project server is found, look for global servers |
| 1392 | return this.connections.find( |
| 1393 | (conn) => conn.server.name === serverName && (conn.server.source === "global" || !conn.server.source), |
| 1394 | ) |
| 1395 | } |
| 1396 | |
| 1397 | /** |
| 1398 | * Find a connection by sanitized server name. |
no outgoing calls
no test coverage detected