Clean up and add more comments (#2)
This commit is contained in:
parent
79af38cf21
commit
9a244f5770
4 changed files with 349 additions and 653 deletions
|
|
@ -1,15 +1,15 @@
|
|||
// Utils/Json/ContentJsonConverter.cs
|
||||
namespace McpDotNet.Utils.Json;
|
||||
|
||||
using System.Text.Json;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using global::McpDotNet.Protocol.Types;
|
||||
using McpDotNet.Protocol.Types;
|
||||
|
||||
namespace McpDotNet.Utils.Json;
|
||||
|
||||
/// <summary>
|
||||
/// JSON converter for IContent that handles polymorphic deserialization based on the "type" property.
|
||||
/// </summary>
|
||||
public class ContentJsonConverter : JsonConverter<IContent>
|
||||
{
|
||||
/// </inheritdoc>
|
||||
public override IContent? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType != JsonTokenType.StartObject)
|
||||
|
|
@ -34,6 +34,7 @@ public class ContentJsonConverter : JsonConverter<IContent>
|
|||
};
|
||||
}
|
||||
|
||||
/// </inheritdoc>
|
||||
public override void Write(Utf8JsonWriter writer, IContent value, JsonSerializerOptions options)
|
||||
{
|
||||
switch (value)
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
// Utils/Json/JsonRpcMessageConverter.cs (continued)
|
||||
namespace McpDotNet.Utils.Json;
|
||||
|
||||
using System.Text.Json;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using global::McpDotNet.Protocol.Messages;
|
||||
using McpDotNet.Protocol.Messages;
|
||||
|
||||
namespace McpDotNet.Utils.Json;
|
||||
|
||||
/// <summary>
|
||||
/// JSON converter for IJsonRpcMessage that handles polymorphic deserialization of different message types.
|
||||
/// </summary>
|
||||
public class JsonRpcMessageConverter : JsonConverter<IJsonRpcMessage>
|
||||
{
|
||||
/// </inheritdoc>
|
||||
public override IJsonRpcMessage? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType != JsonTokenType.StartObject)
|
||||
|
|
@ -63,6 +63,7 @@ public class JsonRpcMessageConverter : JsonConverter<IJsonRpcMessage>
|
|||
throw new JsonException("Invalid JSON-RPC message format");
|
||||
}
|
||||
|
||||
/// </inheritdoc>
|
||||
public override void Write(Utf8JsonWriter writer, IJsonRpcMessage value, JsonSerializerOptions options)
|
||||
{
|
||||
switch (value)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
namespace McpDotNet.Utils.Json;
|
||||
|
||||
using System.Text.Json;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace McpDotNet.Utils.Json;
|
||||
/// <summary>
|
||||
/// Extensions for configuring System.Text.Json serialization options for MCP.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
namespace McpDotNet.Utils.Json;
|
||||
|
||||
using System.Text.Json;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using global::McpDotNet.Protocol.Types;
|
||||
using McpDotNet.Protocol.Types;
|
||||
|
||||
namespace McpDotNet.Utils.Json;
|
||||
|
||||
/// <summary>
|
||||
/// JSON converter for IResourceContents that handles polymorphic deserialization based on content properties.
|
||||
/// </summary>
|
||||
public class ResourceContentsJsonConverter : JsonConverter<IResourceContents>
|
||||
{
|
||||
/// </inheritdoc>
|
||||
public override IResourceContents? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType != JsonTokenType.StartObject)
|
||||
|
|
@ -32,6 +33,7 @@ public class ResourceContentsJsonConverter : JsonConverter<IResourceContents>
|
|||
throw new JsonException("Resource contents must have either 'text' or 'blob' property");
|
||||
}
|
||||
|
||||
/// </inheritdoc>
|
||||
public override void Write(Utf8JsonWriter writer, IResourceContents value, JsonSerializerOptions options)
|
||||
{
|
||||
switch (value)
|
||||
|
|
|
|||
Loading…
Reference in a new issue