Skip to content

Commit 3ba6c05

Browse files
committed
为 GET 添加日志
1 parent bbb20b0 commit 3ba6c05

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/DotNetCampus.ModelContextProtocol.TouchSocket.Http/Transports/TouchSocket/TouchSocketHttpServerTransport.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ private async ValueTask HandleStreamableHttpConnectionAsync(HttpContext context,
233233
context.Response.ContentType = "text/event-stream";
234234
context.Response.Headers.Add("Cache-Control", "no-cache");
235235

236+
Log.Info($"[McpServer][TouchSocket] SSE connection established. SessionId={sessionId}");
237+
236238
try
237239
{
238240
context.Response.IsChunk = true;
@@ -248,10 +250,12 @@ private async ValueTask HandleStreamableHttpConnectionAsync(HttpContext context,
248250
await output.WriteAsync(SseKeepAliveBytes, cancellationToken);
249251
await output.FlushAsync(cancellationToken);
250252
}
253+
Log.Info($"[McpServer][TouchSocket] SSE connection cancelled. SessionId={sessionId}");
251254
}
252255
catch (OperationCanceledException)
253256
{
254257
// 正常关闭
258+
Log.Info($"[McpServer][TouchSocket] SSE connection ended. SessionId={sessionId}");
255259
}
256260
catch (Exception ex)
257261
{

src/DotNetCampus.ModelContextProtocol/Transports/Http/LocalHostHttpServerTransport.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ private async Task HandleGetRequestAsync(HttpListenerContext context, Cancellati
420420
context.Response.ContentType = "text/event-stream";
421421
context.Response.Headers["Cache-Control"] = "no-cache";
422422

423+
Log.Info($"[McpServer][StreamableHttp] SSE connection established. SessionId={sessionId}");
424+
423425
try
424426
{
425427
var output = context.Response.OutputStream;
@@ -434,14 +436,16 @@ private async Task HandleGetRequestAsync(HttpListenerContext context, Cancellati
434436
await output.WriteAsync(SseKeepAliveBytes, cancellationToken);
435437
await output.FlushAsync(cancellationToken);
436438
}
439+
Log.Info($"[McpServer][StreamableHttp] SSE connection cancelled. SessionId={sessionId}");
437440
}
438441
catch (OperationCanceledException)
439442
{
440443
// 正常关闭
444+
Log.Info($"[McpServer][StreamableHttp] SSE connection ended. SessionId={sessionId}");
441445
}
442446
catch (Exception ex)
443447
{
444-
Log.Debug($"[McpServer][StreamableHttp] SSE connection ended. SessionId={sessionId}, Error={ex.Message}");
448+
Log.Info($"[McpServer][StreamableHttp] SSE connection ended. SessionId={sessionId}, Error={ex.Message}");
445449
}
446450
finally
447451
{

0 commit comments

Comments
 (0)