MCPcopy Index your code
hub / github.com/codeaashu/claude-code / prefetchAllMcpResources

Function prefetchAllMcpResources

src/services/mcp/client.ts:2408–2473  ·  view source on GitHub ↗
(
  mcpConfigs: Record<string, ScopedMcpServerConfig>,
)

Source from the content-addressed store, hash-verified

2406// (connectToServer, fetch*ForClient) is already cached. Memoizing here by
2407// mcpConfigs object ref leaked — main.tsx creates fresh config objects each call.
2408export function prefetchAllMcpResources(
2409 mcpConfigs: Record<string, ScopedMcpServerConfig>,
2410): Promise<{
2411 clients: MCPServerConnection[]
2412 tools: Tool[]
2413 commands: Command[]
2414}> {
2415 return new Promise(resolve => {
2416 let pendingCount = 0
2417 let completedCount = 0
2418
2419 pendingCount = Object.keys(mcpConfigs).length
2420
2421 if (pendingCount === 0) {
2422 void resolve({
2423 clients: [],
2424 tools: [],
2425 commands: [],
2426 })
2427 return
2428 }
2429
2430 const clients: MCPServerConnection[] = []
2431 const tools: Tool[] = []
2432 const commands: Command[] = []
2433
2434 getMcpToolsCommandsAndResources(result => {
2435 clients.push(result.client)
2436 tools.push(...result.tools)
2437 commands.push(...result.commands)
2438
2439 completedCount++
2440 if (completedCount >= pendingCount) {
2441 const commandsMetadataLength = commands.reduce((sum, command) => {
2442 const commandMetadataLength =
2443 command.name.length +
2444 (command.description ?? '').length +
2445 (command.argumentHint ?? '').length
2446 return sum + commandMetadataLength
2447 }, 0)
2448 logEvent('tengu_mcp_tools_commands_loaded', {
2449 tools_count: tools.length,
2450 commands_count: commands.length,
2451 commands_metadata_length: commandsMetadataLength,
2452 })
2453
2454 void resolve({
2455 clients,
2456 tools,
2457 commands,
2458 })
2459 }
2460 }, mcpConfigs).catch(error => {
2461 logMCPError(
2462 'prefetchAllMcpResources',
2463 `Failed to get MCP resources: ${errorMessage(error)}`,
2464 )
2465 // Still resolve with empty results

Callers 2

runFunction · 0.85
logContextMetricsFunction · 0.85

Calls 7

logEventFunction · 0.85
logMCPErrorFunction · 0.85
keysMethod · 0.80
resolveFunction · 0.70
errorMessageFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected