File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
packages/server/api/src/app/ai/mcp Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff 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+ } ;
You can’t perform that action at this time.
0 commit comments