Skip to content

Change type of Tool.InputSchema to be JsonElement #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 20, 2025

Conversation

stephentoub
Copy link
Contributor

No description provided.

@@ -24,5 +25,5 @@ public class Tool
/// A JSON Schema object defining the expected parameters for the tool.
/// </summary>
[JsonPropertyName("inputSchema")]
public JsonSchema? InputSchema { get; set; }
public JsonElement InputSchema { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all JsonElement are valid JSON schemas, and not all JSON schemas are valid root-level schemas per the MCP specification. We should try to insert baseline validation (e.g. using a wrapper type or validation on the setter) to make sure we conform.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Roughly, this should be checking that the JsonElement is an object and also contains a "type" keyword that is set to "object". Everything else including the "properties" keyword is optional IIRC.

@stephentoub
Copy link
Contributor Author

This seems to be causing hangs in the Ubuntu debug leg.

@eiriktsarpalis
Copy link
Member

This seems to be causing hangs in the Ubuntu debug leg.

There appear to be general reliability issues with our integration testing, although this is the first time I see a hang happening.

@stephentoub
Copy link
Contributor Author

The Ubuntu hand is happening on #9 as well, so whatever the issue is, it's already in main it seems.

@eiriktsarpalis
Copy link
Member

Adding validation to the property setter revealed a few bugs in the process :-) Merging since CI is borked right now.

@@ -481,8 +481,8 @@ private sealed class McpAIFunction(IMcpClient client, Tool tool) : AIFunction
["type"] = "object",
["title"] = tool.Name,
["description"] = tool.Description ?? string.Empty,
["properties"] = tool.InputSchema?.Properties ?? [],
["required"] = tool.InputSchema?.Required ?? []
["properties"] = new Dictionary<string, object?>(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed this. Your changes are leaving the properties and required keywords empty. Was this an intentional change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the code so that it always just forwards the JsonElement in the Tool. It is now always guaranteed to be populated.

@eiriktsarpalis eiriktsarpalis merged commit 3de19d3 into main Mar 20, 2025
0 of 6 checks passed
@eiriktsarpalis eiriktsarpalis deleted the fixschematype branch March 20, 2025 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants