4
4
using EverythingServer . Tools ;
5
5
using Microsoft . Extensions . AI ;
6
6
using ModelContextProtocol ;
7
- using ModelContextProtocol . AspNetCore ;
8
7
using ModelContextProtocol . Protocol ;
9
8
using ModelContextProtocol . Server ;
10
9
using OpenTelemetry ;
15
14
16
15
var builder = WebApplication . CreateBuilder ( args ) ;
17
16
18
- HashSet < string > subscriptions = [ ] ;
17
+ // Subscriptions tracks resource URIs to McpServer instances
18
+ Dictionary < string , List < IMcpServer > > subscriptions = new ( ) ;
19
19
var _minimumLoggingLevel = LoggingLevel . Debug ;
20
20
21
21
builder . Services
37
37
38
38
if ( uri is not null )
39
39
{
40
- subscriptions . Add ( uri ) ;
40
+ if ( ! subscriptions . ContainsKey ( uri ) )
41
+ {
42
+ subscriptions [ uri ] = new List < IMcpServer > ( ) ;
43
+ }
44
+ subscriptions [ uri ] . Add ( ctx . Server ) ;
41
45
42
46
await ctx . Server . SampleAsync ( [
43
47
new ChatMessage ( ChatRole . System , "You are a helpful test server" ) ,
@@ -58,7 +62,11 @@ await ctx.Server.SampleAsync([
58
62
var uri = ctx . Params ? . Uri ;
59
63
if ( uri is not null )
60
64
{
61
- subscriptions . Remove ( uri ) ;
65
+ if ( subscriptions . ContainsKey ( uri ) )
66
+ {
67
+ // Remove ctx.Server from the subscription list
68
+ subscriptions [ uri ] . Remove ( ctx . Server ) ;
69
+ }
62
70
}
63
71
return new EmptyResult ( ) ;
64
72
} )
0 commit comments