fix: disable MCP session idle timeout completely

The 24-hour timeout was still not being respected - sessions were being
killed after ~14 minutes. Using Timeout.InfiniteTimeSpan completely
disables idle-based session pruning in the SDK's IdleTrackingBackgroundService.

This makes the MCP server bulletproof against session drops during long
periods of inactivity (e.g., when users are discussing/planning before
making tool calls).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Barry Walker
2026-01-24 13:15:50 -05:00
parent b94cef4546
commit b74a73f793
+4 -3
View File
@@ -40,8 +40,9 @@ else
.AddMcpServer()
.WithHttpTransport(options =>
{
// Increase idle timeout to 24 hours to prevent session drops during long operations
options.IdleTimeout = TimeSpan.FromHours(24);
// Disable idle timeout completely - sessions should never be killed due to inactivity
// The SDK's IdleTrackingBackgroundService respects InfiniteTimeSpan to skip idle-based pruning
options.IdleTimeout = Timeout.InfiniteTimeSpan;
})
.WithToolsFromAssembly();
@@ -52,7 +53,7 @@ else
app.MapMcp("/mcp");
app.Logger.LogInformation("PaperlessMCP server starting on port {Port}", port);
app.Logger.LogInformation("PaperlessMCP server starting on port {Port} with infinite session timeout", port);
app.Logger.LogInformation("MCP endpoint available at: http://localhost:{Port}/mcp", port);
await app.RunAsync($"http://0.0.0.0:{port}");