Change type of Tool.InputSchema to be JsonElement (#4)

* Change type of Tool.InputSchema to be JsonElement

* Add schema validation in the InputSchema property setter.

* Simplify AIFunction tool adapter.

---------

Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
This commit is contained in:
Stephen Toub 2025-03-20 13:16:41 -04:00 • committed by GitHub
commit 3de19d38e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,4 +1,6 @@
using System.Text.Json.Serialization;
using ModelContextProtocol.Utils.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace ModelContextProtocol.Protocol.Types;
@ -23,6 +25,23 @@ public class Tool
/// <summary>
/// A JSON Schema object defining the expected parameters for the tool.
/// </summary>
/// <remarks>
/// Needs to a valid JSON schema object that additionally is of type object.
/// </remarks>
[JsonPropertyName("inputSchema")]
public JsonSchema? InputSchema { get; set; }
public JsonElement InputSchema
{
get => _inputSchema;
set
{
if (!McpJsonUtilities.IsValidMcpToolSchema(value))
{
throw new ArgumentException("The specified document is not a valid MPC tool JSON schema.", nameof(InputSchema));
}
_inputSchema = value;
}
}
private JsonElement _inputSchema = McpJsonUtilities.DefaultMcpToolSchema;
}