Skip to content

Commit b6c87b9

Browse files
committed
Keep JsonIgnore properties and mark them as Obsolete
1 parent 1cb8fac commit b6c87b9

10 files changed

Lines changed: 362 additions & 6 deletions

src/ModelContextProtocol.Core/Protocol/ClientCapabilities.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
using ModelContextProtocol.Server;
21
using System.Text.Json.Serialization;
2+
using ModelContextProtocol.Client;
3+
using ModelContextProtocol.Server;
34

45
namespace ModelContextProtocol.Protocol;
56

@@ -83,5 +84,10 @@ public sealed class ClientCapabilities
8384
/// </para>
8485
/// </remarks>
8586
[JsonIgnore]
86-
public IEnumerable<KeyValuePair<string, Func<JsonRpcNotification, CancellationToken, ValueTask>>>? NotificationHandlers { get; set; }
87+
[Obsolete($"Use {nameof(McpClientHandlers.NotificationHandlers)} instead.")]
88+
public IEnumerable<KeyValuePair<string, Func<JsonRpcNotification, CancellationToken, ValueTask>>>? NotificationHandlers
89+
{
90+
get => throw new NotSupportedException($"Use {nameof(McpClientHandlers.NotificationHandlers)} instead.");
91+
set => throw new NotSupportedException($"Use {nameof(McpClientHandlers.NotificationHandlers)} instead.");
92+
}
8793
}

src/ModelContextProtocol.Core/Protocol/CompletionsCapability.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using System.Text.Json.Serialization;
2+
using ModelContextProtocol.Server;
3+
14
namespace ModelContextProtocol.Protocol;
25

36
/// <summary>
@@ -24,4 +27,19 @@ namespace ModelContextProtocol.Protocol;
2427
/// </remarks>
2528
public sealed class CompletionsCapability
2629
{
30+
/// <summary>
31+
/// Gets or sets the handler for completion requests.
32+
/// </summary>
33+
/// <remarks>
34+
/// This handler provides auto-completion suggestions for prompt arguments or resource references in the Model Context Protocol.
35+
/// The handler receives a reference type (e.g., "ref/prompt" or "ref/resource") and the current argument value,
36+
/// and should return appropriate completion suggestions.
37+
/// </remarks>
38+
[JsonIgnore]
39+
[Obsolete($"Use {nameof(McpServerHandlers.CompleteHandler)} instead.")]
40+
public McpRequestHandler<CompleteRequestParams, CompleteResult>? CompleteHandler
41+
{
42+
get => throw new NotSupportedException($"Use {nameof(McpServerHandlers.CompleteHandler)} instead.");
43+
set => throw new NotSupportedException($"Use {nameof(McpServerHandlers.CompleteHandler)} instead.");
44+
}
2745
}

src/ModelContextProtocol.Core/Protocol/ElicitationCapability.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using System.Text.Json.Serialization;
2+
using ModelContextProtocol.Client;
3+
14
namespace ModelContextProtocol.Protocol;
25

36
/// <summary>
@@ -19,4 +22,24 @@ namespace ModelContextProtocol.Protocol;
1922
/// </remarks>
2023
public sealed class ElicitationCapability
2124
{
25+
/// <summary>
26+
/// Gets or sets the handler for processing <see cref="RequestMethods.ElicitationCreate"/> requests.
27+
/// </summary>
28+
/// <remarks>
29+
/// <para>
30+
/// This handler function is called when an MCP server requests the client to provide additional
31+
/// information during interactions. The client must set this property for the elicitation capability to work.
32+
/// </para>
33+
/// <para>
34+
/// The handler receives message parameters and a cancellation token.
35+
/// It should return a <see cref="ElicitResult"/> containing the response to the elicitation request.
36+
/// </para>
37+
/// </remarks>
38+
[JsonIgnore]
39+
[Obsolete($"Use {nameof(McpClientHandlers.ElicitationHandler)} instead.")]
40+
public Func<ElicitRequestParams?, CancellationToken, ValueTask<ElicitResult>>? ElicitationHandler
41+
{
42+
get => throw new NotSupportedException($"Use {nameof(McpClientHandlers.ElicitationHandler)} instead.");
43+
set => throw new NotSupportedException($"Use {nameof(McpClientHandlers.ElicitationHandler)} instead.");
44+
}
2245
}

src/ModelContextProtocol.Core/Protocol/LoggingCapability.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using System.Text.Json.Serialization;
2+
using ModelContextProtocol.Server;
3+
14
namespace ModelContextProtocol.Protocol;
25

36
/// <summary>
@@ -16,4 +19,14 @@ namespace ModelContextProtocol.Protocol;
1619
/// </remarks>
1720
public sealed class LoggingCapability
1821
{
22+
/// <summary>
23+
/// Gets or sets the handler for set logging level requests from clients.
24+
/// </summary>
25+
[JsonIgnore]
26+
[Obsolete($"Use {nameof(McpServerHandlers.SetLoggingLevelHandler)} instead.")]
27+
public McpRequestHandler<SetLevelRequestParams, EmptyResult>? SetLoggingLevelHandler
28+
{
29+
get => throw new NotSupportedException($"Use {nameof(McpServerHandlers.SetLoggingLevelHandler)} instead.");
30+
set => throw new NotSupportedException($"Use {nameof(McpServerHandlers.SetLoggingLevelHandler)} instead.");
31+
}
1932
}

src/ModelContextProtocol.Core/Protocol/PromptsCapability.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,68 @@ public sealed class PromptsCapability
3030
/// </remarks>
3131
[JsonPropertyName("listChanged")]
3232
public bool? ListChanged { get; set; }
33+
34+
/// <summary>
35+
/// Gets or sets the handler for <see cref="RequestMethods.PromptsList"/> requests.
36+
/// </summary>
37+
/// <remarks>
38+
/// This handler is invoked when a client requests a list of available prompts from the server
39+
/// via a <see cref="RequestMethods.PromptsList"/> request. Results from this handler are returned
40+
/// along with any prompts defined in <see cref="PromptCollection"/>.
41+
/// </remarks>
42+
[JsonIgnore]
43+
[Obsolete($"Use {nameof(McpServerHandlers.ListPromptsHandler)} instead.")]
44+
public McpRequestHandler<ListPromptsRequestParams, ListPromptsResult>? ListPromptsHandler
45+
{
46+
get => throw new NotSupportedException($"Use {nameof(McpServerHandlers.ListPromptsHandler)} instead.");
47+
set => throw new NotSupportedException($"Use {nameof(McpServerHandlers.ListPromptsHandler)} instead.");
48+
}
49+
50+
/// <summary>
51+
/// Gets or sets the handler for <see cref="RequestMethods.PromptsGet"/> requests.
52+
/// </summary>
53+
/// <remarks>
54+
/// <para>
55+
/// This handler is invoked when a client requests details for a specific prompt by name and provides arguments
56+
/// for the prompt if needed. The handler receives the request context containing the prompt name and any arguments,
57+
/// and should return a <see cref="GetPromptResult"/> with the prompt messages and other details.
58+
/// </para>
59+
/// <para>
60+
/// This handler will be invoked if the requested prompt name is not found in the <see cref="PromptCollection"/>,
61+
/// allowing for dynamic prompt generation or retrieval from external sources.
62+
/// </para>
63+
/// </remarks>
64+
[JsonIgnore]
65+
[Obsolete($"Use {nameof(McpServerHandlers.GetPromptHandler)} instead.")]
66+
public McpRequestHandler<GetPromptRequestParams, GetPromptResult>? GetPromptHandler
67+
{
68+
get => throw new NotSupportedException($"Use {nameof(McpServerHandlers.GetPromptHandler)} instead.");
69+
set => throw new NotSupportedException($"Use {nameof(McpServerHandlers.GetPromptHandler)} instead.");
70+
}
71+
72+
/// <summary>
73+
/// Gets or sets a collection of prompts that will be served by the server.
74+
/// </summary>
75+
/// <remarks>
76+
/// <para>
77+
/// The <see cref="PromptCollection"/> contains the predefined prompts that clients can request from the server.
78+
/// This collection works in conjunction with <see cref="ListPromptsHandler"/> and <see cref="GetPromptHandler"/>
79+
/// when those are provided:
80+
/// </para>
81+
/// <para>
82+
/// - For <see cref="RequestMethods.PromptsList"/> requests: The server returns all prompts from this collection
83+
/// plus any additional prompts provided by the <see cref="ListPromptsHandler"/> if it's set.
84+
/// </para>
85+
/// <para>
86+
/// - For <see cref="RequestMethods.PromptsGet"/> requests: The server first checks this collection for the requested prompt.
87+
/// If not found, it will invoke the <see cref="GetPromptHandler"/> as a fallback if one is set.
88+
/// </para>
89+
/// </remarks>
90+
[JsonIgnore]
91+
[Obsolete($"Use {nameof(McpServerOptions.PromptCollection)} instead.")]
92+
public McpServerPrimitiveCollection<McpServerPrompt>? PromptCollection
93+
{
94+
get => throw new NotSupportedException($"Use {nameof(McpServerOptions.PromptCollection)} instead.");
95+
set => throw new NotSupportedException($"Use {nameof(McpServerOptions.PromptCollection)} instead.");
96+
}
3397
}

src/ModelContextProtocol.Core/Protocol/ResourcesCapability.cs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,110 @@ public sealed class ResourcesCapability
2828
/// </remarks>
2929
[JsonPropertyName("listChanged")]
3030
public bool? ListChanged { get; set; }
31+
32+
/// <summary>
33+
/// Gets or sets the handler for <see cref="RequestMethods.ResourcesTemplatesList"/> requests.
34+
/// </summary>
35+
/// <remarks>
36+
/// This handler is called when clients request available resource templates that can be used
37+
/// to create resources within the Model Context Protocol server.
38+
/// Resource templates define the structure and URI patterns for resources accessible in the system,
39+
/// allowing clients to discover available resource types and their access patterns.
40+
/// </remarks>
41+
[JsonIgnore]
42+
[Obsolete($"Use {nameof(McpServerHandlers.ListResourceTemplatesHandler)} instead.")]
43+
public McpRequestHandler<ListResourceTemplatesRequestParams, ListResourceTemplatesResult>? ListResourceTemplatesHandler
44+
{
45+
get => throw new NotSupportedException($"Use {nameof(McpServerHandlers.ListResourceTemplatesHandler)} instead.");
46+
set => throw new NotSupportedException($"Use {nameof(McpServerHandlers.ListResourceTemplatesHandler)} instead.");
47+
}
48+
49+
/// <summary>
50+
/// Gets or sets the handler for <see cref="RequestMethods.ResourcesList"/> requests.
51+
/// </summary>
52+
/// <remarks>
53+
/// This handler responds to client requests for available resources and returns information about resources accessible through the server.
54+
/// The implementation should return a <see cref="ListResourcesResult"/> with the matching resources.
55+
/// </remarks>
56+
[JsonIgnore]
57+
[Obsolete($"Use {nameof(McpServerHandlers.ListResourcesHandler)} instead.")]
58+
public McpRequestHandler<ListResourcesRequestParams, ListResourcesResult>? ListResourcesHandler
59+
{
60+
get => throw new NotSupportedException($"Use {nameof(McpServerHandlers.ListResourcesHandler)} instead.");
61+
set => throw new NotSupportedException($"Use {nameof(McpServerHandlers.ListResourcesHandler)} instead.");
62+
}
63+
64+
/// <summary>
65+
/// Gets or sets the handler for <see cref="RequestMethods.ResourcesRead"/> requests.
66+
/// </summary>
67+
/// <remarks>
68+
/// This handler is responsible for retrieving the content of a specific resource identified by its URI in the Model Context Protocol.
69+
/// When a client sends a resources/read request, this handler is invoked with the resource URI.
70+
/// The handler should implement logic to locate and retrieve the requested resource, then return
71+
/// its contents in a ReadResourceResult object.
72+
/// </remarks>
73+
[JsonIgnore]
74+
[Obsolete($"Use {nameof(McpServerHandlers.ReadResourceHandler)} instead.")]
75+
public McpRequestHandler<ReadResourceRequestParams, ReadResourceResult>? ReadResourceHandler
76+
{
77+
get => throw new NotSupportedException($"Use {nameof(McpServerHandlers.ReadResourceHandler)} instead.");
78+
set => throw new NotSupportedException($"Use {nameof(McpServerHandlers.ReadResourceHandler)} instead.");
79+
}
80+
81+
/// <summary>
82+
/// Gets or sets the handler for <see cref="RequestMethods.ResourcesSubscribe"/> requests.
83+
/// </summary>
84+
/// <remarks>
85+
/// When a client sends a <see cref="RequestMethods.ResourcesSubscribe"/> request, this handler is invoked with the resource URI
86+
/// to be subscribed to. The implementation should register the client's interest in receiving updates
87+
/// for the specified resource.
88+
/// Subscriptions allow clients to receive real-time notifications when resources change, without
89+
/// requiring polling.
90+
/// </remarks>
91+
[JsonIgnore]
92+
[Obsolete($"Use {nameof(McpServerHandlers.SubscribeToResourcesHandler)} instead.")]
93+
public McpRequestHandler<SubscribeRequestParams, EmptyResult>? SubscribeToResourcesHandler
94+
{
95+
get => throw new NotSupportedException($"Use {nameof(McpServerHandlers.SubscribeToResourcesHandler)} instead.");
96+
set => throw new NotSupportedException($"Use {nameof(McpServerHandlers.SubscribeToResourcesHandler)} instead.");
97+
}
98+
99+
/// <summary>
100+
/// Gets or sets the handler for <see cref="RequestMethods.ResourcesUnsubscribe"/> requests.
101+
/// </summary>
102+
/// <remarks>
103+
/// When a client sends a <see cref="RequestMethods.ResourcesUnsubscribe"/> request, this handler is invoked with the resource URI
104+
/// to be unsubscribed from. The implementation should remove the client's registration for receiving updates
105+
/// about the specified resource.
106+
/// </remarks>
107+
[JsonIgnore]
108+
[Obsolete($"Use {nameof(McpServerHandlers.UnsubscribeFromResourcesHandler)} instead.")]
109+
public McpRequestHandler<UnsubscribeRequestParams, EmptyResult>? UnsubscribeFromResourcesHandler
110+
{
111+
get => throw new NotSupportedException($"Use {nameof(McpServerHandlers.UnsubscribeFromResourcesHandler)} instead.");
112+
set => throw new NotSupportedException($"Use {nameof(McpServerHandlers.UnsubscribeFromResourcesHandler)} instead.");
113+
}
114+
115+
/// <summary>
116+
/// Gets or sets a collection of resources served by the server.
117+
/// </summary>
118+
/// <remarks>
119+
/// <para>
120+
/// Resources specified via <see cref="ResourceCollection"/> augment the <see cref="ListResourcesHandler"/>, <see cref="ListResourceTemplatesHandler"/>
121+
/// and <see cref="ReadResourceHandler"/> handlers, if provided. Resources with template expressions in their URI templates are considered resource templates
122+
/// and are listed via ListResourceTemplate, whereas resources without template parameters are considered static resources and are listed with ListResources.
123+
/// </para>
124+
/// <para>
125+
/// ReadResource requests will first check the <see cref="ResourceCollection"/> for the exact resource being requested. If no match is found, they'll proceed to
126+
/// try to match the resource against each resource template in <see cref="ResourceCollection"/>. If no match is still found, the request will fall back to
127+
/// any handler registered for <see cref="ReadResourceHandler"/>.
128+
/// </para>
129+
/// </remarks>
130+
[JsonIgnore]
131+
[Obsolete($"Use {nameof(McpServerOptions.ResourceCollection)} instead.")]
132+
public McpServerResourceCollection? ResourceCollection
133+
{
134+
get => throw new NotSupportedException($"Use {nameof(McpServerOptions.ResourceCollection)} instead.");
135+
set => throw new NotSupportedException($"Use {nameof(McpServerOptions.ResourceCollection)} instead.");
136+
}
31137
}

src/ModelContextProtocol.Core/Protocol/RootsCapability.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Text.Json.Serialization;
2+
using ModelContextProtocol.Client;
23

34
namespace ModelContextProtocol.Protocol;
45

@@ -31,4 +32,19 @@ public sealed class RootsCapability
3132
/// </remarks>
3233
[JsonPropertyName("listChanged")]
3334
public bool? ListChanged { get; set; }
35+
36+
/// <summary>
37+
/// Gets or sets the handler for <see cref="RequestMethods.RootsList"/> requests.
38+
/// </summary>
39+
/// <remarks>
40+
/// This handler is invoked when a client sends a <see cref="RequestMethods.RootsList"/> request to retrieve available roots.
41+
/// The handler receives request parameters and should return a <see cref="ListRootsResult"/> containing the collection of available roots.
42+
/// </remarks>
43+
[JsonIgnore]
44+
[Obsolete($"Use {nameof(McpClientHandlers.RootsHandler)} instead.")]
45+
public Func<ListRootsRequestParams?, CancellationToken, ValueTask<ListRootsResult>>? RootsHandler
46+
{
47+
get => throw new NotSupportedException($"Use {nameof(McpClientHandlers.RootsHandler)} instead.");
48+
set => throw new NotSupportedException($"Use {nameof(McpClientHandlers.RootsHandler)} instead.");
49+
}
3450
}

src/ModelContextProtocol.Core/Protocol/SamplingCapability.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
using System.Text.Json.Serialization;
2+
using Microsoft.Extensions.AI;
3+
using ModelContextProtocol.Client;
4+
15
namespace ModelContextProtocol.Protocol;
26

37
/// <summary>
@@ -19,4 +23,29 @@ namespace ModelContextProtocol.Protocol;
1923
/// </remarks>
2024
public sealed class SamplingCapability
2125
{
26+
/// <summary>
27+
/// Gets or sets the handler for processing <see cref="RequestMethods.SamplingCreateMessage"/> requests.
28+
/// </summary>
29+
/// <remarks>
30+
/// <para>
31+
/// This handler function is called when an MCP server requests the client to generate content
32+
/// using an AI model. The client must set this property for the sampling capability to work.
33+
/// </para>
34+
/// <para>
35+
/// The handler receives message parameters, a progress reporter for updates, and a
36+
/// cancellation token. It should return a <see cref="CreateMessageResult"/> containing the
37+
/// generated content.
38+
/// </para>
39+
/// <para>
40+
/// You can create a handler using the <see cref="McpClient.CreateSamplingHandler"/> extension
41+
/// method with any implementation of <see cref="IChatClient"/>.
42+
/// </para>
43+
/// </remarks>
44+
[JsonIgnore]
45+
[Obsolete($"Use {nameof(McpClientHandlers.SamplingHandler)} instead.")]
46+
public Func<CreateMessageRequestParams?, IProgress<ProgressNotificationValue>, CancellationToken, ValueTask<CreateMessageResult>>? SamplingHandler
47+
{
48+
get => throw new NotSupportedException($"Use {nameof(McpClientHandlers.SamplingHandler)} instead.");
49+
set => throw new NotSupportedException($"Use {nameof(McpClientHandlers.SamplingHandler)} instead.");
50+
}
2251
}

0 commit comments

Comments
 (0)