Skip to content

Commit 0880b98

Browse files
authored
Merge branch 'main' into cezudas/OPS-3006-tables-helpers
2 parents d09b021 + 0571656 commit 0880b98

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

packages/server/api/src/app/ai/mcp/llm-query-router.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,11 @@ const repairText = (text: string): string | null => {
248248
try {
249249
const parsedText = JSON.parse(text);
250250

251+
const rawToolNames = findFirstKeyInObject(parsedText, 'tool_names');
252+
const toolNames = normalizeToolNames(rawToolNames);
253+
251254
return JSON.stringify({
252-
tool_names: findFirstKeyInObject(parsedText, 'tool_names') || [],
255+
tool_names: toolNames,
253256
query_classification:
254257
findFirstKeyInObject(parsedText, 'query_classification') || [],
255258
reasoning: findFirstKeyInObject(parsedText, 'reasoning') || '',
@@ -260,3 +263,18 @@ const repairText = (text: string): string | null => {
260263
return null;
261264
}
262265
};
266+
267+
export const normalizeToolNames = (value: unknown): string[] => {
268+
if (Array.isArray(value)) {
269+
return value;
270+
}
271+
272+
if (typeof value === 'string') {
273+
return value
274+
.split(',')
275+
.map((name) => name.trim())
276+
.filter((name) => name.length > 0);
277+
}
278+
279+
return [];
280+
};

0 commit comments

Comments
 (0)