@@ -20,8 +20,6 @@ const {
2020 parseToolCalls : standaloneParseToolCalls ,
2121 repairToolCalls,
2222 _recoverWriteFileContent,
23- _detectProseCommands,
24- _detectFallbackFileOperations : standaloneFallbackDetect ,
2523 TOOL_NAME_ALIASES ,
2624 VALID_TOOLS ,
2725} = require ( './tools/toolParser' ) ;
@@ -2615,83 +2613,11 @@ class MCPToolServer {
26152613 console . log ( `[MCP] Capped tool calls: executing ${ maxToolsPerResponse } , skipping ${ skippedCount } ` ) ;
26162614 }
26172615
2618- // Fallback detection if no formal tool calls
2616+ // No formal tool calls found — return without attempting fallback detection.
2617+ // The model should use proper tool call format (native functions or JSON fences).
2618+ // Removed: prose command detection and fallback file operation classification.
26192619 if ( toolCalls . length === 0 ) {
2620- console . log ( '[MCP] No formal tool calls found, trying fallback detection...' ) ;
2621-
2622- const proseCommands = _detectProseCommands ( responseText ) ;
2623- if ( proseCommands . length > 0 ) {
2624- console . log ( '[MCP] Found prose command fallback:' , proseCommands . length ) ;
2625- toolCalls . push ( ...proseCommands ) ;
2626- }
2627-
2628- const fallbackCalls = this . _detectFallbackFileOperations ( responseText , options . userMessage , [ ..._repairDropped , ...( options . lastDroppedFilePaths || [ ] ) ] ) ;
2629- if ( fallbackCalls . length > 0 ) {
2630- console . log ( '[MCP] Found fallback tool calls:' , fallbackCalls . length ) ;
2631- let effectiveFallbackCalls = fallbackCalls ;
2632- let fbCapped = false ;
2633- let fbSkipped = 0 ;
2634- if ( maxToolsPerResponse > 0 && fallbackCalls . length > maxToolsPerResponse ) {
2635- fbSkipped = fallbackCalls . length - maxToolsPerResponse ;
2636- effectiveFallbackCalls = fallbackCalls . slice ( 0 , maxToolsPerResponse ) ;
2637- fbCapped = true ;
2638- }
2639- const results = [ ] ;
2640- for ( const call of effectiveFallbackCalls ) {
2641- if ( toolPaceMs > 0 && results . length > 0 ) {
2642- await new Promise ( r => setTimeout ( r , toolPaceMs ) ) ;
2643- }
2644- if ( options . writeFileHistory && call . tool === 'write_file' ) {
2645- const wfPath = call . params ?. filePath || call . params ?. path || call . params ?. file_path ;
2646- const wfLimit = ( options . continuationCount || 0 ) > 0 ? 5 : 6 ;
2647- if ( wfPath && options . writeFileHistory [ wfPath ] && options . writeFileHistory [ wfPath ] . count >= wfLimit ) {
2648- console . log ( `[MCP] Write dedup: blocking ${ call . tool } to "${ wfPath } " (already written ${ options . writeFileHistory [ wfPath ] . count } x)` ) ;
2649- let autoConverted = false ;
2650- const newContent = call . params ?. content || '' ;
2651- if ( newContent . length > 50 ) {
2652- try {
2653- const _fs = require ( 'fs' ) , _path = require ( 'path' ) ;
2654- const fullPath = _path . resolve ( this . projectPath || '.' , wfPath ) ;
2655- const existing = _fs . existsSync ( fullPath ) ? _fs . readFileSync ( fullPath , 'utf-8' ) : '' ;
2656- if ( existing . length > 0 ) {
2657- const extracted = this . _extractNewContentForAutoConvert ( existing , newContent ) ;
2658- if ( extracted ) {
2659- console . log ( `[MCP] Write dedup auto-convert (${ extracted . method } ): "${ wfPath } " (${ extracted . overlapLines } overlap lines)` ) ;
2660- const ar = await this . executeTool ( 'append_to_file' , { filePath : wfPath , content : extracted . newContent } ) ;
2661- results . push ( { tool : 'append_to_file' , params : { filePath : wfPath , content : '...(auto-converted)' } , result : ar } ) ;
2662- autoConverted = true ;
2663- }
2664- if ( ! autoConverted ) {
2665- // No extractable new content — file content is a subset or duplicate
2666- results . push ( { tool : call . tool , params : call . params , result : { success : true , message : `File "${ wfPath } " already has this content (${ existing . split ( '\n' ) . length } lines). Use append_to_file to add new content, or move on to the next task.` } } ) ;
2667- autoConverted = true ;
2668- }
2669- }
2670- } catch ( e ) { console . warn ( `[MCP] Write dedup auto-convert failed: ${ e . message } ` ) ; }
2671- }
2672- if ( ! autoConverted ) {
2673- // Include file tail so model knows where to append from
2674- let fileTailHint = '' ;
2675- try {
2676- const _fs2 = require ( 'fs' ) , _path2 = require ( 'path' ) ;
2677- const fp = _path2 . resolve ( this . projectPath || '.' , wfPath ) ;
2678- if ( _fs2 . existsSync ( fp ) ) {
2679- const lines = _fs2 . readFileSync ( fp , 'utf-8' ) . split ( '\n' ) ;
2680- const tail = lines . slice ( - 10 ) . join ( '\n' ) ;
2681- fileTailHint = ` The file currently has ${ lines . length } lines. Last 10 lines:\n${ tail } \nUse append_to_file with filePath="${ wfPath } " to continue from here.` ;
2682- }
2683- } catch ( _ ) { }
2684- results . push ( { tool : call . tool , params : call . params , result : { success : false , error : `BLOCKED: "${ wfPath } " already written ${ options . writeFileHistory [ wfPath ] . count } times.${ fileTailHint || ' Use append_to_file or edit_file instead.' } ` } } ) ;
2685- }
2686- continue ;
2687- }
2688- }
2689- const result = await this . executeTool ( call . tool , call . params || { } ) ;
2690- results . push ( { tool : call . tool , params : call . params , result } ) ;
2691- }
2692- return { hasToolCalls : true , results, capped : fbCapped , skippedToolCalls : fbSkipped , formalCallCount : 0 , droppedFilePaths : [ ] } ;
2693- }
2694- console . log ( '[MCP] No fallback tool calls either' ) ;
2620+ console . log ( '[MCP] No formal tool calls found' ) ;
26952621 return { hasToolCalls : false , results : [ ] , formalCallCount : 0 , droppedFilePaths : _repairDropped } ;
26962622 }
26972623
@@ -2750,49 +2676,6 @@ class MCPToolServer {
27502676 if ( call . tool . startsWith ( 'browser_' ) ) call . params = this . _normalizeBrowserParams ( call . tool , call . params || { } ) ;
27512677 else call . params = this . _normalizeFsParams ( call . tool , call . params || { } ) ;
27522678 }
2753- if ( options . writeFileHistory && call . tool === 'write_file' ) {
2754- const wfPath = call . params ?. filePath || call . params ?. path || call . params ?. file_path ;
2755- const wfLimit = ( options . continuationCount || 0 ) > 0 ? 5 : 6 ;
2756- if ( wfPath && options . writeFileHistory [ wfPath ] && options . writeFileHistory [ wfPath ] . count >= wfLimit ) {
2757- console . log ( `[MCP] Write dedup: blocking ${ call . tool } to "${ wfPath } " (already written ${ options . writeFileHistory [ wfPath ] . count } x)` ) ;
2758- let autoConverted = false ;
2759- const newContent = call . params ?. content || '' ;
2760- if ( newContent . length > 50 ) {
2761- try {
2762- const _fs = require ( 'fs' ) , _path = require ( 'path' ) ;
2763- const fullPath = _path . resolve ( this . projectPath || '.' , wfPath ) ;
2764- const existing = _fs . existsSync ( fullPath ) ? _fs . readFileSync ( fullPath , 'utf-8' ) : '' ;
2765- if ( existing . length > 0 ) {
2766- const extracted = this . _extractNewContentForAutoConvert ( existing , newContent ) ;
2767- if ( extracted ) {
2768- console . log ( `[MCP] Write dedup auto-convert (${ extracted . method } ): "${ wfPath } " (${ extracted . overlapLines } overlap lines)` ) ;
2769- const ar = await this . executeTool ( 'append_to_file' , { filePath : wfPath , content : extracted . newContent } ) ;
2770- results . push ( { tool : 'append_to_file' , params : { filePath : wfPath , content : '...(auto-converted)' } , result : ar } ) ;
2771- autoConverted = true ;
2772- }
2773- if ( ! autoConverted ) {
2774- results . push ( { tool : call . tool , params : call . params , result : { success : true , message : `File "${ wfPath } " already has this content (${ existing . split ( '\n' ) . length } lines). Use append_to_file to add new content, or move on to the next task.` } } ) ;
2775- autoConverted = true ;
2776- }
2777- }
2778- } catch ( e ) { console . warn ( `[MCP] Write dedup auto-convert failed: ${ e . message } ` ) ; }
2779- }
2780- if ( ! autoConverted ) {
2781- let fileTailHint = '' ;
2782- try {
2783- const _fs2 = require ( 'fs' ) , _path2 = require ( 'path' ) ;
2784- const fp = _path2 . resolve ( this . projectPath || '.' , wfPath ) ;
2785- if ( _fs2 . existsSync ( fp ) ) {
2786- const lines = _fs2 . readFileSync ( fp , 'utf-8' ) . split ( '\n' ) ;
2787- const tail = lines . slice ( - 10 ) . join ( '\n' ) ;
2788- fileTailHint = ` The file currently has ${ lines . length } lines. Last 10 lines:\n${ tail } \nUse append_to_file with filePath="${ wfPath } " to continue from here.` ;
2789- }
2790- } catch ( _ ) { }
2791- results . push ( { tool : call . tool , params : call . params , result : { success : false , error : `BLOCKED: "${ wfPath } " already written ${ options . writeFileHistory [ wfPath ] . count } times.${ fileTailHint || ' Use append_to_file or edit_file instead.' } ` } } ) ;
2792- }
2793- continue ;
2794- }
2795- }
27962679 const result = await this . executeTool ( call . tool , call . params || { } ) ;
27972680 console . log ( '[MCP] Executed tool:' , call . tool , 'result:' , result . success ? 'success' : 'failed' ) ;
27982681 results . push ( { tool : call . tool , params : call . params , result } ) ;
@@ -2809,10 +2692,6 @@ class MCPToolServer {
28092692 return { hasToolCalls : true , results, capped : capped || browserCapped , skippedToolCalls : skippedCount + browserSkipped , formalCallCount : toolCalls . length , droppedFilePaths : _repairDropped } ;
28102693 }
28112694
2812- _detectFallbackFileOperations ( responseText , userMessage , lastDroppedFilePaths = [ ] ) {
2813- return standaloneFallbackDetect ( responseText , userMessage , lastDroppedFilePaths ) ;
2814- }
2815-
28162695 // ─── Tool Prompt Building ────────────────────────────────────────────────
28172696
28182697 getToolPrompt ( ) {
0 commit comments