File tree Expand file tree Collapse file tree 5 files changed +21
-21
lines changed
samples/AspNetCoreSseServer
ModelContextProtocol.AspNetCore
ModelContextProtocol/Shared
tests/ModelContextProtocol.TestSseServer Expand file tree Collapse file tree 5 files changed +21
-21
lines changed Original file line number Diff line number Diff line change 1
- using ModelContextProtocol . AspNetCore ;
2
-
3
1
var builder = WebApplication . CreateBuilder ( args ) ;
4
2
builder . Services . AddMcpServer ( ) . WithToolsFromAssembly ( ) ;
5
3
var app = builder . Build ( ) ;
Original file line number Diff line number Diff line change 1
- using Microsoft . AspNetCore . Builder ;
2
- using Microsoft . AspNetCore . Http ;
1
+ using Microsoft . AspNetCore . Http ;
3
2
using Microsoft . AspNetCore . Routing ;
4
3
using Microsoft . AspNetCore . WebUtilities ;
5
4
using Microsoft . Extensions . DependencyInjection ;
12
11
using System . Collections . Concurrent ;
13
12
using System . Security . Cryptography ;
14
13
15
- namespace ModelContextProtocol . AspNetCore ;
14
+ namespace Microsoft . AspNetCore . Builder ;
16
15
17
16
/// <summary>
18
17
/// Extension methods for <see cref="IEndpointRouteBuilder"/> to add MCP endpoints.
Original file line number Diff line number Diff line change @@ -30,7 +30,6 @@ dotnet add package ModelContextProtocol.AspNetCore --prerelease
30
30
31
31
``` csharp
32
32
// Program.cs
33
- using ModelContextProtocol .AspNetCore ;
34
33
using ModelContextProtocol .Server ;
35
34
using System .ComponentModel ;
36
35
Original file line number Diff line number Diff line change @@ -94,25 +94,30 @@ public virtual async ValueTask DisposeUnsynchronizedAsync()
94
94
{
95
95
_logger . CleaningUpEndpoint ( EndpointName ) ;
96
96
97
- if ( _sessionCts is not null )
97
+ try
98
98
{
99
- await _sessionCts . CancelAsync ( ) . ConfigureAwait ( false ) ;
100
- }
101
-
102
- if ( MessageProcessingTask is not null )
103
- {
104
- try
99
+ if ( _sessionCts is not null )
105
100
{
106
- await MessageProcessingTask . ConfigureAwait ( false ) ;
101
+ await _sessionCts . CancelAsync ( ) . ConfigureAwait ( false ) ;
107
102
}
108
- catch ( OperationCanceledException )
103
+
104
+ if ( MessageProcessingTask is not null )
109
105
{
110
- // Ignore cancellation
106
+ try
107
+ {
108
+ await MessageProcessingTask . ConfigureAwait ( false ) ;
109
+ }
110
+ catch ( OperationCanceledException )
111
+ {
112
+ // Ignore cancellation
113
+ }
111
114
}
112
115
}
113
-
114
- _session ? . Dispose ( ) ;
115
- _sessionCts ? . Dispose ( ) ;
116
+ finally
117
+ {
118
+ _session ? . Dispose ( ) ;
119
+ _sessionCts ? . Dispose ( ) ;
120
+ }
116
121
117
122
_logger . EndpointCleanedUp ( EndpointName ) ;
118
123
}
Original file line number Diff line number Diff line change 1
- using ModelContextProtocol . AspNetCore ;
2
- using ModelContextProtocol . Protocol . Types ;
1
+ using ModelContextProtocol . Protocol . Types ;
3
2
using ModelContextProtocol . Server ;
4
3
using Serilog ;
5
4
using System . Text ;
You can’t perform that action at this time.
0 commit comments