MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / initializeAgentRegistry

Function initializeAgentRegistry

cli/src/utils/local-agent-registry.ts:57–90  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

55 * Later directories take precedence, so project agents override global ones.
56 */
57export async function initializeAgentRegistry(): Promise<void> {
58 try {
59 // Let SDK load from all default directories (cwd, parent, home)
60 userAgentsCache = await sdkLoadLocalAgents({ verbose: false })
61 // Build ID-to-filepath map by scanning all agent directories
62 userAgentFilePaths = buildAgentFilePathMap(getDefaultAgentDirs())
63 } catch (error) {
64 // Fall back to empty cache if SDK loading fails, but log a warning
65 logger.warn(
66 { error },
67 'Failed to load user agents from .agents directories',
68 )
69 userAgentsCache = {}
70 userAgentFilePaths = new Map()
71 }
72
73 // Load MCP config from mcp.json files in .agents directories
74 try {
75 const mcpConfig = loadMCPConfigSync({ verbose: false })
76 mcpServersCache = mcpConfig.mcpServers
77 if (Object.keys(mcpServersCache).length > 0) {
78 logger.debug(
79 {
80 mcpServers: Object.keys(mcpServersCache),
81 source: mcpConfig._sourceFilePath,
82 },
83 '[agents] Loaded MCP servers from mcp.json',
84 )
85 }
86 } catch (error) {
87 logger.warn({ error }, 'Failed to load MCP config from .agents directories')
88 mcpServersCache = {}
89 }
90}
91
92/**
93 * Get default agent directories to scan.

Callers 2

mainFunction · 0.90

Calls 3

loadMCPConfigSyncFunction · 0.90
buildAgentFilePathMapFunction · 0.85
getDefaultAgentDirsFunction · 0.70

Tested by

no test coverage detected