From c31f5787991d09d8d03b0b369487bdbfec435d34 Mon Sep 17 00:00:00 2001 From: Meftun Akarsu Date: Sat, 20 Jun 2026 22:37:51 +0300 Subject: [PATCH] fix(enrichment): don't crash on a missing optional mcp.json or skills/ dir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit loadMcpTools and loadSkills called fs.promises.stat() OUTSIDE their try blocks. fs.promises.stat rejects with ENOENT when the path is absent, so a missing (optional) mcp.json or skills/ directory threw an uncaught ENOENT up through enrichCommand and aborted 'kcagent enrich' — the !stat.isFile()/!stat.isDirectory() guards were dead code for that case. Move the stat() calls inside the existing try blocks and treat ENOENT as 'not configured' (return [] without a spurious warning); other errors still warn. Matches the catch blocks' existing return-[] intent. --- toolbox/enrichment/src/agent/tools.ts | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/toolbox/enrichment/src/agent/tools.ts b/toolbox/enrichment/src/agent/tools.ts index 2cdd159..94f1339 100644 --- a/toolbox/enrichment/src/agent/tools.ts +++ b/toolbox/enrichment/src/agent/tools.ts @@ -15,12 +15,12 @@ function expandEnvVars(str: string): string { export async function loadMcpTools(configPath: string): Promise { const mcpConfigPath = path.join(configPath, 'mcp.json'); - const stat = await fs.promises.stat(mcpConfigPath); - if (!stat.isFile()) { - return []; - } try { + const stat = await fs.promises.stat(mcpConfigPath); + if (!stat.isFile()) { + return []; + } const content = await fs.promises.readFile(mcpConfigPath, 'utf-8'); const config = JSON.parse(content); const toolsets: adk.MCPToolset[] = []; @@ -61,19 +61,22 @@ export async function loadMcpTools(configPath: string): Promise { const skillsBasePath = path.join(configPath, 'skills'); - const stat = await fs.promises.stat(skillsBasePath); - if (!stat.isDirectory()) { - return []; - } try { + const stat = await fs.promises.stat(skillsBasePath); + if (!stat.isDirectory()) { + return []; + } const skillsMap = await adk.loadAllSkillsInDir(skillsBasePath); if (Object.keys(skillsMap).length === 0) { return []; @@ -86,7 +89,10 @@ export async function loadSkills(configPath: string): Promise