Skip to content

Commit 0293a7f

Browse files
gfraiteurclaude
andcommitted
Disable Kestrel timeouts for MCP server SSE connections
Configure Kestrel to never timeout long-lived Server-Sent Events connections used by MCP. This prevents sessions from closing after a few hours of inactivity. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f4fcffd commit 0293a7f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/PostSharp.Engineering.BuildTools/Mcp/McpServerCommand.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Microsoft.AspNetCore.Authentication;
44
using Microsoft.AspNetCore.Builder;
55
using Microsoft.AspNetCore.Hosting;
6+
using Microsoft.AspNetCore.Server.Kestrel.Core;
67
using Microsoft.Extensions.DependencyInjection;
78
using Microsoft.Extensions.Hosting;
89
using Microsoft.Extensions.Logging;
@@ -75,6 +76,16 @@ public override async Task<int> ExecuteAsync( CommandContext context, McpServerC
7576
var port = settings.Port;
7677
builder.WebHost.UseUrls( $"http://0.0.0.0:{port}" );
7778

79+
// Configure Kestrel to never timeout long-lived SSE connections
80+
// MCP uses Server-Sent Events which require persistent connections
81+
builder.WebHost.ConfigureKestrel( options =>
82+
{
83+
options.Limits.KeepAliveTimeout = TimeSpan.MaxValue;
84+
options.Limits.RequestHeadersTimeout = TimeSpan.MaxValue;
85+
options.Limits.MinRequestBodyDataRate = null;
86+
options.Limits.MinResponseDataRate = null;
87+
} );
88+
7889
// Enable logging to console for debugging
7990
builder.Logging.ClearProviders();
8091
builder.Logging.AddConsole();

0 commit comments

Comments
 (0)