@@ -135,7 +135,8 @@ export async function run() {
135135 if ( ! azureOpenAiEndpoint || ! burgerMcpEndpoint ) {
136136 const errorMessage = 'Missing required environment variables: AZURE_OPENAI_API_ENDPOINT or BURGER_MCP_URL' ;
137137 console . error ( errorMessage ) ;
138- process . exit ( 1 ) ;
138+ process . exitCode = 1 ;
139+ return ;
139140 }
140141
141142 let session : SessionData ;
@@ -167,8 +168,6 @@ export async function run() {
167168 const tools = await loadMcpTools ( 'burger' , client ) ;
168169 console . log ( `Loaded ${ tools . length } tools from Burger MCP server` ) ;
169170
170- console . log ( `Thinking...` ) ;
171-
172171 const prompt = ChatPromptTemplate . fromMessages ( [
173172 [ 'system' , agentSystemPrompt + ( session . userId ? `\n\nUser ID: ${ session . userId } ` : '' ) ] ,
174173 [ 'placeholder' , '{chat_history}' ] ,
@@ -189,6 +188,7 @@ export async function run() {
189188
190189 const chatHistory = convertHistoryToMessages ( session . history ) ;
191190
191+ console . log ( `Thinking...` ) ;
192192 const response = await agentExecutor . invoke ( {
193193 input : question ,
194194 chat_history : chatHistory
@@ -215,14 +215,14 @@ export async function run() {
215215 const error = _error as Error ;
216216 console . error ( `Error when processing request: ${ error . message } ` ) ;
217217 process . exitCode = 1 ;
218- } finally {
219- if ( client ) {
220- try {
221- await client . close ( ) ;
222- } catch ( error ) {
223- console . error ( 'Error closing MCP client:' , error ) ;
224- }
218+ }
219+
220+ if ( client ) {
221+ try {
222+ await client . close ( ) ;
223+ } catch ( error ) {
224+ console . error ( 'Error closing MCP client:' , error ) ;
225225 }
226- process . exitCode = 0 ;
227226 }
227+ process . exitCode = 0 ;
228228}
0 commit comments