forked from modelcontextprotocol/csharp-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonRpcRequest.cs
More file actions
45 lines (40 loc) · 1.43 KB
/
JsonRpcRequest.cs
File metadata and controls
45 lines (40 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
namespace ModelContextProtocol.Protocol;
/// <summary>
/// A request message in the JSON-RPC protocol.
/// </summary>
/// <remarks>
/// Requests are messages that require a response from the receiver. Each request includes a unique ID
/// that will be included in the corresponding response message (either a success response or an error).
///
/// The receiver of a request message is expected to execute the specified method with the provided parameters
/// and return either a <see cref="JsonRpcResponse"/> with the result, or a <see cref="JsonRpcError"/>
/// if the method execution fails.
/// </remarks>
public sealed class JsonRpcRequest : JsonRpcMessageWithId
{
internal const string MethodPropertyName = "method";
internal const string ParamsPropertyName = "params";
/// <summary>
/// Name of the method to invoke.
/// </summary>
[JsonPropertyName(MethodPropertyName)]
public required string Method { get; init; }
/// <summary>
/// Optional parameters for the method.
/// </summary>
[JsonPropertyName(ParamsPropertyName)]
public JsonNode? Params { get; init; }
internal JsonRpcRequest WithId(RequestId id)
{
return new JsonRpcRequest
{
JsonRpc = JsonRpc,
Id = id,
Method = Method,
Params = Params,
RelatedTransport = RelatedTransport,
};
}
}