File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed 
examples/clients/simple-chatbot/mcp_simple_chatbot Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -291,8 +291,15 @@ async def process_llm_response(self, llm_response: str) -> str:
291291        """ 
292292        import  json 
293293
294+         def  _clean_json_string (json_string : str ) ->  str :
295+             """Remove ```json ... ``` or ``` ... ``` wrappers if the LLM response is fenced.""" 
296+             import  re 
297+ 
298+             pattern  =  r"^```(?:\s*json)?\s*(.*?)\s*```$" 
299+             return  re .sub (pattern , r"\1" , json_string , flags = re .DOTALL  |  re .IGNORECASE ).strip ()
300+ 
294301        try :
295-             tool_call  =  json .loads (llm_response )
302+             tool_call  =  json .loads (_clean_json_string ( llm_response ) )
296303            if  "tool"  in  tool_call  and  "arguments"  in  tool_call :
297304                logging .info (f"Executing tool: { tool_call ['tool' ]}  )
298305                logging .info (f"With arguments: { tool_call ['arguments' ]}  )
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments