@@ -81,12 +81,12 @@ private async Task RunServerInstanceAsync(CancellationToken cancellationToken)
8181 // Wait for client connection
8282 Console . Error . WriteLine ( "[DEBUG] Before WaitForConnectionAsync" ) ;
8383 Console . Error . Flush ( ) ;
84- await pipeServer . WaitForConnectionAsync ( cancellationToken ) ;
84+ await pipeServer . WaitForConnectionAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
8585 Console . Error . WriteLine ( "[DEBUG] After WaitForConnectionAsync - Client connected to Named Pipe" ) ;
8686 Console . Error . Flush ( ) ;
8787
8888 // Handle communication with connected client
89- await HandleClientAsync ( pipeServer , cancellationToken ) ;
89+ await HandleClientAsync ( pipeServer , cancellationToken ) . ConfigureAwait ( false ) ;
9090 }
9191 catch ( OperationCanceledException )
9292 {
@@ -103,7 +103,7 @@ private async Task RunServerInstanceAsync(CancellationToken cancellationToken)
103103 // Wait a moment before retrying on error
104104 try
105105 {
106- await Task . Delay ( 1000 , cancellationToken ) ;
106+ await Task . Delay ( 1000 , cancellationToken ) . ConfigureAwait ( false ) ;
107107 }
108108 catch ( OperationCanceledException )
109109 {
@@ -149,7 +149,7 @@ private static async Task HandleClientAsync(NamedPipeServerStream pipeServer, Ca
149149 {
150150 // Receive request
151151 Console . Error . WriteLine ( "[DEBUG] Calling ReceiveMessageAsync..." ) ;
152- var requestJson = await ReceiveMessageAsync ( pipeServer , cancellationToken ) ;
152+ var requestJson = await ReceiveMessageAsync ( pipeServer , cancellationToken ) . ConfigureAwait ( false ) ;
153153 Console . Error . WriteLine ( $ "[DEBUG] Received request: { requestJson . Substring ( 0 , Math . Min ( 100 , requestJson . Length ) ) } ...") ;
154154
155155 // Parse JSON-RPC request
@@ -180,7 +180,7 @@ private static async Task HandleClientAsync(NamedPipeServerStream pipeServer, Ca
180180
181181Please provide how to update the MCP client configuration to the user." ;
182182
183- await SendMessageAsync ( pipeServer , versionErrorResponse , cancellationToken ) ;
183+ await SendMessageAsync ( pipeServer , versionErrorResponse , cancellationToken ) . ConfigureAwait ( false ) ;
184184 return ;
185185 }
186186
@@ -194,15 +194,15 @@ 2. Manually terminate console (LLM will then restart automatically)
194194
195195LLM should prompt user to choose." ;
196196
197- await SendMessageAsync ( pipeServer , busyResponse , cancellationToken ) ;
197+ await SendMessageAsync ( pipeServer , busyResponse , cancellationToken ) . ConfigureAwait ( false ) ;
198198 return ;
199199 }
200200
201201 // Execute tool
202- var result = await Task . Run ( ( ) => ExecuteTool ( name ! , requestRoot ) ) ;
202+ var result = await Task . Run ( ( ) => ExecuteTool ( name ! , requestRoot ) ) . ConfigureAwait ( false ) ;
203203
204204 // Send response
205- await SendMessageAsync ( pipeServer , result , cancellationToken ) ;
205+ await SendMessageAsync ( pipeServer , result , cancellationToken ) . ConfigureAwait ( false ) ;
206206 }
207207 catch ( Exception ex )
208208 {
@@ -226,7 +226,7 @@ 2. Manually terminate console (LLM will then restart automatically)
226226
227227 try
228228 {
229- await SendMessageAsync ( pipeServer , errorJson , cancellationToken ) ;
229+ await SendMessageAsync ( pipeServer , errorJson , cancellationToken ) . ConfigureAwait ( false ) ;
230230 }
231231 catch
232232 {
@@ -270,7 +270,7 @@ private static async Task<string> ReceiveMessageAsync(NamedPipeServerStream pipe
270270
271271 // Receive message length (4 bytes)
272272 var lengthBytes = new byte [ 4 ] ;
273- await ReadExactAsync ( pipeServer , lengthBytes , cancellationToken ) ;
273+ await ReadExactAsync ( pipeServer , lengthBytes , cancellationToken ) . ConfigureAwait ( false ) ;
274274 var messageLength = BitConverter . ToInt32 ( lengthBytes , 0 ) ;
275275 Console . Error . WriteLine ( $ "[DEBUG] Server ReceiveMessageAsync: Message length = { messageLength } ") ;
276276
@@ -282,7 +282,7 @@ private static async Task<string> ReceiveMessageAsync(NamedPipeServerStream pipe
282282 // Receive message body
283283 Console . Error . WriteLine ( "[DEBUG] Server ReceiveMessageAsync: Reading message body..." ) ;
284284 var messageBytes = new byte [ messageLength ] ;
285- await ReadExactAsync ( pipeServer , messageBytes , cancellationToken ) ;
285+ await ReadExactAsync ( pipeServer , messageBytes , cancellationToken ) . ConfigureAwait ( false ) ;
286286 Console . Error . WriteLine ( "[DEBUG] Server ReceiveMessageAsync: Complete" ) ;
287287
288288 return Encoding . UTF8 . GetString ( messageBytes ) ;
@@ -297,11 +297,11 @@ public static async Task SendMessageAsync(NamedPipeServerStream pipeServer, stri
297297 var lengthBytes = BitConverter . GetBytes ( messageBytes . Length ) ;
298298
299299 // Send message length (4 bytes)
300- await pipeServer . WriteAsync ( lengthBytes , 0 , 4 , cancellationToken ) ;
300+ await pipeServer . WriteAsync ( lengthBytes , 0 , 4 , cancellationToken ) . ConfigureAwait ( false ) ;
301301
302302 // Send message body
303- await pipeServer . WriteAsync ( messageBytes , 0 , messageBytes . Length , cancellationToken ) ;
304- await pipeServer . FlushAsync ( cancellationToken ) ;
303+ await pipeServer . WriteAsync ( messageBytes , 0 , messageBytes . Length , cancellationToken ) . ConfigureAwait ( false ) ;
304+ await pipeServer . FlushAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
305305 }
306306
307307 /// <summary>
@@ -312,7 +312,7 @@ private static async Task ReadExactAsync(NamedPipeServerStream stream, byte[] bu
312312 var totalBytesRead = 0 ;
313313 while ( totalBytesRead < buffer . Length )
314314 {
315- var bytesRead = await stream . ReadAsync ( buffer , totalBytesRead , buffer . Length - totalBytesRead , cancellationToken ) ;
315+ var bytesRead = await stream . ReadAsync ( buffer , totalBytesRead , buffer . Length - totalBytesRead , cancellationToken ) . ConfigureAwait ( false ) ;
316316 if ( bytesRead == 0 )
317317 {
318318 throw new IOException ( "Connection closed while reading data" ) ;
0 commit comments