@@ -77,4 +77,59 @@ describe("mcp-client retry helpers", () => {
7777 expect ( sdkClientMock . callTool ) . toHaveBeenCalledTimes ( 2 ) ;
7878 expect ( sdkClientMock . clients ) . toHaveLength ( 2 ) ;
7979 } ) ;
80+
81+ it ( "retries callTool once after a retryable tool error result" , async ( ) => {
82+ sdkClientMock . callTool
83+ . mockResolvedValueOnce ( {
84+ isError : true ,
85+ structuredContent : {
86+ status : "error" ,
87+ tool : "getallaccounts" ,
88+ error : "Not connected" ,
89+ } ,
90+ content : [
91+ {
92+ type : "text" ,
93+ text : '{"status":"error","tool":"getallaccounts","error":"Not connected"}' ,
94+ } ,
95+ ] ,
96+ } )
97+ . mockResolvedValueOnce ( {
98+ content : [ { type : "text" , text : "ok" } ] ,
99+ } ) ;
100+
101+ const result = await callMcpTool (
102+ "test-api-key" ,
103+ "https://aitoearn.ai/api" ,
104+ "getAllAccounts" ,
105+ { }
106+ ) ;
107+
108+ expect ( result ) . toEqual ( {
109+ content : [ { type : "text" , text : "ok" } ] ,
110+ } ) ;
111+ expect ( sdkClientMock . callTool ) . toHaveBeenCalledTimes ( 2 ) ;
112+ expect ( sdkClientMock . clients ) . toHaveLength ( 2 ) ;
113+ } ) ;
114+
115+ it ( "does not retry non-connection tool error results" , async ( ) => {
116+ sdkClientMock . callTool . mockResolvedValueOnce ( {
117+ isError : true ,
118+ content : [ { type : "text" , text : "Insufficient balance" } ] ,
119+ } ) ;
120+
121+ const result = await callMcpTool (
122+ "test-api-key" ,
123+ "https://aitoearn.ai/api" ,
124+ "acceptTask" ,
125+ { }
126+ ) ;
127+
128+ expect ( result ) . toEqual ( {
129+ isError : true ,
130+ content : [ { type : "text" , text : "Insufficient balance" } ] ,
131+ } ) ;
132+ expect ( sdkClientMock . callTool ) . toHaveBeenCalledTimes ( 1 ) ;
133+ expect ( sdkClientMock . clients ) . toHaveLength ( 1 ) ;
134+ } ) ;
80135} ) ;
0 commit comments