Skip to content

Commit 10c96f2

Browse files
committed
Fix resource subscriptions for HTTP
1 parent 64da739 commit 10c96f2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

samples/EverythingServer/Program.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using EverythingServer.Tools;
55
using Microsoft.Extensions.AI;
66
using ModelContextProtocol;
7-
using ModelContextProtocol.AspNetCore;
87
using ModelContextProtocol.Protocol;
98
using ModelContextProtocol.Server;
109
using OpenTelemetry;
@@ -15,7 +14,8 @@
1514

1615
var builder = WebApplication.CreateBuilder(args);
1716

18-
HashSet<string> subscriptions = [];
17+
// Subscriptions tracks resource URIs to McpServer instances
18+
Dictionary<string, List<IMcpServer>> subscriptions = new();
1919
var _minimumLoggingLevel = LoggingLevel.Debug;
2020

2121
builder.Services
@@ -37,7 +37,11 @@
3737

3838
if (uri is not null)
3939
{
40-
subscriptions.Add(uri);
40+
if (!subscriptions.ContainsKey(uri))
41+
{
42+
subscriptions[uri] = new List<IMcpServer>();
43+
}
44+
subscriptions[uri].Add(ctx.Server);
4145

4246
await ctx.Server.SampleAsync([
4347
new ChatMessage(ChatRole.System, "You are a helpful test server"),
@@ -58,7 +62,11 @@ await ctx.Server.SampleAsync([
5862
var uri = ctx.Params?.Uri;
5963
if (uri is not null)
6064
{
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+
}
6270
}
6371
return new EmptyResult();
6472
})

0 commit comments

Comments
 (0)