(
onConnectionAttempt: (params: {
client: MCPServerConnection
tools: Tool[]
commands: Command[]
resources?: ServerResource[]
}) => void,
mcpConfigs?: Record<string, ScopedMcpServerConfig>,
)
| 2224 | } |
| 2225 | |
| 2226 | export async function getMcpToolsCommandsAndResources( |
| 2227 | onConnectionAttempt: (params: { |
| 2228 | client: MCPServerConnection |
| 2229 | tools: Tool[] |
| 2230 | commands: Command[] |
| 2231 | resources?: ServerResource[] |
| 2232 | }) => void, |
| 2233 | mcpConfigs?: Record<string, ScopedMcpServerConfig>, |
| 2234 | ): Promise<void> { |
| 2235 | let resourceToolsAdded = false |
| 2236 | |
| 2237 | const allConfigEntries = Object.entries( |
| 2238 | mcpConfigs ?? (await getAllMcpConfigs()).servers, |
| 2239 | ) |
| 2240 | |
| 2241 | // Partition into disabled and active entries — disabled servers should |
| 2242 | // never generate HTTP connections or flow through batch processing |
| 2243 | const configEntries: typeof allConfigEntries = [] |
| 2244 | for (const entry of allConfigEntries) { |
| 2245 | if (isMcpServerDisabled(entry[0])) { |
| 2246 | onConnectionAttempt({ |
| 2247 | client: { name: entry[0], type: 'disabled', config: entry[1] }, |
| 2248 | tools: [], |
| 2249 | commands: [], |
| 2250 | }) |
| 2251 | } else { |
| 2252 | configEntries.push(entry) |
| 2253 | } |
| 2254 | } |
| 2255 | |
| 2256 | // Calculate transport counts for logging |
| 2257 | const totalServers = configEntries.length |
| 2258 | const stdioCount = count(configEntries, ([_, c]) => c.type === 'stdio') |
| 2259 | const sseCount = count(configEntries, ([_, c]) => c.type === 'sse') |
| 2260 | const httpCount = count(configEntries, ([_, c]) => c.type === 'http') |
| 2261 | const sseIdeCount = count(configEntries, ([_, c]) => c.type === 'sse-ide') |
| 2262 | const wsIdeCount = count(configEntries, ([_, c]) => c.type === 'ws-ide') |
| 2263 | |
| 2264 | // Split servers by type: local (stdio/sdk) need lower concurrency due to |
| 2265 | // process spawning, remote servers can connect with higher concurrency |
| 2266 | const localServers = configEntries.filter(([_, config]) => |
| 2267 | isLocalMcpServer(config), |
| 2268 | ) |
| 2269 | const remoteServers = configEntries.filter( |
| 2270 | ([_, config]) => !isLocalMcpServer(config), |
| 2271 | ) |
| 2272 | |
| 2273 | const serverStats = { |
| 2274 | totalServers, |
| 2275 | stdioCount, |
| 2276 | sseCount, |
| 2277 | httpCount, |
| 2278 | sseIdeCount, |
| 2279 | wsIdeCount, |
| 2280 | } |
| 2281 | |
| 2282 | const processServer = async ([name, config]: [ |
| 2283 | string, |
no test coverage detected