Fix resource subscription handling (#89)
* Fix resource subscription handling Add resource subscription tests * Fix typo * Typo * small fixes * Fix concurrency issue with test * Align with specification schemas
This commit is contained in:
parent
08b0a04dab
commit
34a6f1c665
7 changed files with 210 additions and 36 deletions
|
|
@ -126,13 +126,13 @@ public record ResourcesCapability
|
|||
/// Gets or sets the handler for subscribe to resources messages.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public Func<RequestContext<string>, CancellationToken, Task>? SubscribeToResourcesHandler { get; init; }
|
||||
public Func<RequestContext<SubscribeRequestParams>, CancellationToken, Task<EmptyResult>>? SubscribeToResourcesHandler { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the handler for unsubscribe from resources messages.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public Func<RequestContext<string>, CancellationToken, Task>? UnsubscribeFromResourcesHandler { get; init; }
|
||||
public Func<RequestContext<UnsubscribeRequestParams>, CancellationToken, Task<EmptyResult>>? UnsubscribeFromResourcesHandler { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
16
src/mcpdotnet/Protocol/Types/CompleteResult.cs
Normal file
16
src/mcpdotnet/Protocol/Types/CompleteResult.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace McpDotNet.Protocol.Types;
|
||||
|
||||
/// <summary>
|
||||
/// The server's response to a completion/complete request
|
||||
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json">See the schema for details</see>
|
||||
/// </summary>
|
||||
public class CompleteResult
|
||||
{
|
||||
/// <summary>
|
||||
/// The completion object containing the completion values.
|
||||
/// </summary>
|
||||
[JsonPropertyName("completion")]
|
||||
public Completion Completion { get; set; } = new Completion();
|
||||
}
|
||||
10
src/mcpdotnet/Protocol/Types/EmptyResult.cs
Normal file
10
src/mcpdotnet/Protocol/Types/EmptyResult.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
namespace McpDotNet.Protocol.Types;
|
||||
|
||||
/// <summary>
|
||||
/// An empty result object.
|
||||
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json">See the schema for details</see>
|
||||
/// </summary>
|
||||
public class EmptyResult
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -66,15 +66,3 @@ public class Reference
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The server's response to a completion/complete request
|
||||
/// </summary>
|
||||
public class CompleteResult
|
||||
{
|
||||
/// <summary>
|
||||
/// The completion object containing the completion values.
|
||||
/// </summary>
|
||||
[JsonPropertyName("completion")]
|
||||
public Completion Completion { get; set; } = new Completion();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
namespace McpDotNet.Protocol.Types;
|
||||
|
||||
/// <summary>
|
||||
/// Sent from the server as the payload of "notifications/resources/updated" notifications whenever a subscribed resource changes.
|
||||
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json">See the schema for details</see>
|
||||
/// </summary>
|
||||
public class ResourceUpdatedNotificationParams
|
||||
{
|
||||
/// <summary>
|
||||
/// The URI of the resource to subscribe to. The URI can use any protocol; it is up to the server how to interpret it.
|
||||
/// </summary>
|
||||
[System.Text.Json.Serialization.JsonPropertyName("uri")]
|
||||
public string? Uri { get; init; }
|
||||
}
|
||||
14
src/mcpdotnet/Protocol/Types/SubscribeRequestParams.cs
Normal file
14
src/mcpdotnet/Protocol/Types/SubscribeRequestParams.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
namespace McpDotNet.Protocol.Types;
|
||||
|
||||
/// <summary>
|
||||
/// Sent from the client to request updated notifications from the server whenever a particular primitive changes.
|
||||
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json">See the schema for details</see>
|
||||
/// </summary>
|
||||
public class SubscribeRequestParams
|
||||
{
|
||||
/// <summary>
|
||||
/// The URI of the resource to subscribe to. The URI can use any protocol; it is up to the server how to interpret it.
|
||||
/// </summary>
|
||||
[System.Text.Json.Serialization.JsonPropertyName("uri")]
|
||||
public string? Uri { get; init; }
|
||||
}
|
||||
14
src/mcpdotnet/Protocol/Types/UnsubscribeRequestParams.cs
Normal file
14
src/mcpdotnet/Protocol/Types/UnsubscribeRequestParams.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
namespace McpDotNet.Protocol.Types;
|
||||
|
||||
/// <summary>
|
||||
/// Sent from the client to request not receiving updated notifications from the server whenever a primitive resource changes.
|
||||
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json">See the schema for details</see>
|
||||
/// </summary>
|
||||
public class UnsubscribeRequestParams
|
||||
{
|
||||
/// <summary>
|
||||
/// The URI of the resource to unsubscribe fro. The URI can use any protocol; it is up to the server how to interpret it.
|
||||
/// </summary>
|
||||
[System.Text.Json.Serialization.JsonPropertyName("uri")]
|
||||
public string? Uri { get; init; }
|
||||
}
|
||||
Loading…
Reference in a new issue