File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,13 +48,35 @@ async function main(): Promise<void> {
4848
4949 for ( const [ name , srvConfig ] of Object . entries ( serverConfig . oAuthServers || { } ) ) {
5050 try {
51- mcpClients . push ( await createAutomatedOAuthClient ( name , srvConfig ) ) ;
51+ const client = await createAutomatedOAuthClient ( name , srvConfig ) ;
52+ mcpClients . push ( client ) ;
5253 } catch ( error ) {
5354 logger . error ( `Failed to initialize OAuth server ${ name } :` , error ) ;
5455 throw error ;
5556 }
5657 }
5758
59+ logger . info ( "Connecting to MCP clients with retry..." ) ;
60+ await Promise . all ( mcpClients . map ( async ( client , i ) => {
61+ for ( let attempt = 0 ; attempt < 5 ; attempt ++ ) {
62+ try {
63+ const timeout = new Promise ( ( _ , reject ) =>
64+ setTimeout ( ( ) => reject ( new Error ( `Connection timeout` ) ) , 30000 )
65+ ) ;
66+ await Promise . race ( [ client . connect ( ) , timeout ] ) ;
67+ return ;
68+ } catch ( error ) {
69+ if ( attempt < 4 ) {
70+ const delay = 2000 * Math . pow ( 2 , attempt ) ;
71+ logger . warn ( `Client ${ i } connection failed, retrying in ${ delay } ms...` ) ;
72+ await new Promise ( resolve => setTimeout ( resolve , delay ) ) ;
73+ } else {
74+ throw error ;
75+ }
76+ }
77+ }
78+ } ) ) ;
79+
5880 logger . info ( `Successfully initialized ${ mcpClients . length } MCP clients` ) ;
5981
6082 const userUtterances = Configuration . loadConfig ( "../test_questions.json" ) as string [ ] ;
You can’t perform that action at this time.
0 commit comments