File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
src/ModelContextProtocol/Hosting Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -6,8 +6,18 @@ namespace ModelContextProtocol.Hosting;
66/// <summary>
77/// Hosted service for a single-session (e.g. stdio) MCP server.
88/// </summary>
9- internal sealed class SingleSessionMcpServerHostedService ( IMcpServer session ) : BackgroundService
9+ internal sealed class SingleSessionMcpServerHostedService ( IMcpServer session , IHostApplicationLifetime lifetime ) : BackgroundService
1010{
1111 /// <inheritdoc />
12- protected override Task ExecuteAsync ( CancellationToken stoppingToken ) => session . RunAsync ( stoppingToken ) ;
12+ protected override async Task ExecuteAsync ( CancellationToken stoppingToken )
13+ {
14+ try
15+ {
16+ await session . RunAsync ( stoppingToken ) ;
17+ }
18+ finally
19+ {
20+ lifetime . StopApplication ( ) ;
21+ }
22+ }
1323}
You can’t perform that action at this time.
0 commit comments