Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Commit 1eb9b99

Browse files
committed
Align with specification schemas
1 parent 36839a2 commit 1eb9b99

File tree

10 files changed

+44
-16
lines changed

10 files changed

+44
-16
lines changed

src/mcpdotnet/Configuration/McpServerBuilderExtensions.Handler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public static IMcpServerBuilder WithGetCompletionHandler(this IMcpServerBuilder
107107
/// </summary>
108108
/// <param name="builder">The builder instance.</param>
109109
/// <param name="handler">The handler.</param>
110-
public static IMcpServerBuilder WithSubscribeToResourcesHandler(this IMcpServerBuilder builder, Func<RequestContext<SubscribeToResourceRequestParams>, CancellationToken, Task<EmptyResult>> handler)
110+
public static IMcpServerBuilder WithSubscribeToResourcesHandler(this IMcpServerBuilder builder, Func<RequestContext<SubscribeRequestParams>, CancellationToken, Task<EmptyResult>> handler)
111111
{
112112
Throw.IfNull(builder);
113113

@@ -120,7 +120,7 @@ public static IMcpServerBuilder WithSubscribeToResourcesHandler(this IMcpServerB
120120
/// </summary>
121121
/// <param name="builder">The builder instance.</param>
122122
/// <param name="handler">The handler.</param>
123-
public static IMcpServerBuilder WithUnsubscribeFromResourcesHandler(this IMcpServerBuilder builder, Func<RequestContext<SubscribeToResourceRequestParams>, CancellationToken, Task<EmptyResult>> handler)
123+
public static IMcpServerBuilder WithUnsubscribeFromResourcesHandler(this IMcpServerBuilder builder, Func<RequestContext<UnsubscribeRequestParams>, CancellationToken, Task<EmptyResult>> handler)
124124
{
125125
Throw.IfNull(builder);
126126

src/mcpdotnet/Protocol/Types/Capabilities.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ public record ResourcesCapability
126126
/// Gets or sets the handler for subscribe to resources messages.
127127
/// </summary>
128128
[JsonIgnore]
129-
public Func<RequestContext<SubscribeToResourceRequestParams>, CancellationToken, Task<EmptyResult>>? SubscribeToResourcesHandler { get; init; }
129+
public Func<RequestContext<SubscribeRequestParams>, CancellationToken, Task<EmptyResult>>? SubscribeToResourcesHandler { get; init; }
130130

131131
/// <summary>
132132
/// Gets or sets the handler for unsubscribe from resources messages.
133133
/// </summary>
134134
[JsonIgnore]
135-
public Func<RequestContext<SubscribeToResourceRequestParams>, CancellationToken, Task<EmptyResult>>? UnsubscribeFromResourcesHandler { get; init; }
135+
public Func<RequestContext<UnsubscribeRequestParams>, CancellationToken, Task<EmptyResult>>? UnsubscribeFromResourcesHandler { get; init; }
136136
}
137137

138138
/// <summary>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace McpDotNet.Protocol.Types;
2+
3+
/// <summary>
4+
/// Sent from the server as the payload of "notifications/resources/updated" notifications whenever a subscribed resource changes.
5+
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json">See the schema for details</see>
6+
/// </summary>
7+
public class ResourceUpdatedNotificationParams
8+
{
9+
/// <summary>
10+
/// The URI of the resource to subscribe to. The URI can use any protocol; it is up to the server how to interpret it.
11+
/// </summary>
12+
[System.Text.Json.Serialization.JsonPropertyName("uri")]
13+
public string? Uri { get; init; }
14+
}

src/mcpdotnet/Protocol/Types/SubscribeToResourceRequestParams.cs renamed to src/mcpdotnet/Protocol/Types/SubscribeRequestParams.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
namespace McpDotNet.Protocol.Types;
22

33
/// <summary>
4-
/// Sent from the client to request resources/updated notifications from the server whenever a particular resource changes.
4+
/// Sent from the client to request updated notifications from the server whenever a particular primitive changes.
55
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json">See the schema for details</see>
66
/// </summary>
7-
public class SubscribeToResourceRequestParams
7+
public class SubscribeRequestParams
88
{
99
/// <summary>
1010
/// The URI of the resource to subscribe to. The URI can use any protocol; it is up to the server how to interpret it.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace McpDotNet.Protocol.Types;
2+
3+
/// <summary>
4+
/// Sent from the client to request not receiving updated notifications from the server whenever a primitive resource changes.
5+
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json">See the schema for details</see>
6+
/// </summary>
7+
public class UnsubscribeRequestParams
8+
{
9+
/// <summary>
10+
/// The URI of the resource to unsubscribe fro. The URI can use any protocol; it is up to the server how to interpret it.
11+
/// </summary>
12+
[System.Text.Json.Serialization.JsonPropertyName("uri")]
13+
public string? Uri { get; init; }
14+
}

src/mcpdotnet/Server/McpServer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ private void SetResourcesHandler(McpServerOptions options)
163163
throw new McpServerException("Resources capability was enabled with subscribe support, but SubscribeToResources and/or UnsubscribeFromResources handlers were not specified.");
164164
}
165165

166-
SetRequestHandler<SubscribeToResourceRequestParams, EmptyResult>("resources/subscribe", request => subscribeHandler(new(this, request), cancellationToken));
167-
SetRequestHandler<SubscribeToResourceRequestParams, EmptyResult>("resources/unsubscribe", request => unsubscribeHandler(new(this, request), cancellationToken));
166+
SetRequestHandler<SubscribeRequestParams, EmptyResult>("resources/subscribe", request => subscribeHandler(new(this, request), cancellationToken));
167+
SetRequestHandler<UnsubscribeRequestParams, EmptyResult>("resources/unsubscribe", request => unsubscribeHandler(new(this, request), cancellationToken));
168168
}
169169

170170
private void SetPromptsHandler(McpServerOptions options)

src/mcpdotnet/Server/McpServerHandlers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ public sealed class McpServerHandlers
4545
/// <summary>
4646
/// Gets or sets the handler for subscribe to resources messages.
4747
/// </summary>
48-
public Func<RequestContext<SubscribeToResourceRequestParams>, CancellationToken, Task<EmptyResult>>? SubscribeToResourcesHandler { get; set; }
48+
public Func<RequestContext<SubscribeRequestParams>, CancellationToken, Task<EmptyResult>>? SubscribeToResourcesHandler { get; set; }
4949

5050
/// <summary>
5151
/// Gets or sets the handler for unsubscribe from resources messages.
5252
/// </summary>
53-
public Func<RequestContext<SubscribeToResourceRequestParams>, CancellationToken, Task<EmptyResult>>? UnsubscribeFromResourcesHandler { get; set; }
53+
public Func<RequestContext<UnsubscribeRequestParams>, CancellationToken, Task<EmptyResult>>? UnsubscribeFromResourcesHandler { get; set; }
5454

5555
/// <summary>
5656
/// Overwrite any handlers in McpServerOptions with non-null handlers from this instance.

tests/mcpdotnet.TestServer/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ private static async Task Main(string[] args)
6868

6969
foreach (var resource in resources)
7070
{
71-
SubscribeToResourceRequestParams responseParams = new() { Uri = resource };
71+
ResourceUpdatedNotificationParams notificationParams = new() { Uri = resource };
7272
await server.SendMessageAsync(new JsonRpcNotification()
7373
{
7474
Method = NotificationMethods.ResourceUpdatedNotification,
75-
Params = responseParams
75+
Params = notificationParams
7676
});
7777
}
7878
}

tests/mcpdotnet.Tests/ClientIntegrationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public async Task SubscribeResource_Stdio()
221221
await using var client = await _fixture.CreateClientAsync(clientId);
222222
client.AddNotificationHandler(NotificationMethods.ResourceUpdatedNotification, (notification) =>
223223
{
224-
var notificationParams = JsonSerializer.Deserialize<SubscribeToResourceRequestParams>(notification.Params!.ToString() ?? string.Empty);
224+
var notificationParams = JsonSerializer.Deserialize<ResourceUpdatedNotificationParams>(notification.Params!.ToString() ?? string.Empty);
225225
++counter;
226226
return Task.CompletedTask;
227227
});
@@ -246,7 +246,7 @@ public async Task UnsubscribeResource_Stdio()
246246
await using var client = await _fixture.CreateClientAsync(clientId);
247247
client.AddNotificationHandler(NotificationMethods.ResourceUpdatedNotification, (notification) =>
248248
{
249-
var notificationParams = JsonSerializer.Deserialize<SubscribeToResourceRequestParams>(notification.Params!.ToString() ?? string.Empty);
249+
var notificationParams = JsonSerializer.Deserialize<ResourceUpdatedNotificationParams>(notification.Params!.ToString() ?? string.Empty);
250250
++counter;
251251
return Task.CompletedTask;
252252
});

tests/mcpdotnet.Tests/Configuration/McpServerBuilderExtensionsHandlerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void WithGetCompletionHandler_Sets_Handler()
113113
[Fact]
114114
public void WithSubscribeToResourcesHandler_Sets_Handler()
115115
{
116-
Func<RequestContext<SubscribeToResourceRequestParams>, CancellationToken, Task<EmptyResult>> handler = (context, token) => Task.FromResult(new EmptyResult());
116+
Func<RequestContext<SubscribeRequestParams>, CancellationToken, Task<EmptyResult>> handler = (context, token) => Task.FromResult(new EmptyResult());
117117

118118
_builder.Object.WithSubscribeToResourcesHandler(handler);
119119

@@ -126,7 +126,7 @@ public void WithSubscribeToResourcesHandler_Sets_Handler()
126126
[Fact]
127127
public void WithUnsubscribeFromResourcesHandler_Sets_Handler()
128128
{
129-
Func<RequestContext<SubscribeToResourceRequestParams>, CancellationToken, Task<EmptyResult>> handler = (context, token) => Task.FromResult(new EmptyResult());
129+
Func<RequestContext<UnsubscribeRequestParams>, CancellationToken, Task<EmptyResult>> handler = (context, token) => Task.FromResult(new EmptyResult());
130130

131131
_builder.Object.WithUnsubscribeFromResourcesHandler(handler);
132132

0 commit comments

Comments
 (0)