Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ModelContextProtocol/Server/AIFunctionMcpServerTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ private static AIFunctionFactoryOptions CreateAIFunctionFactoryOptions(
return null;
}
},
JsonSchemaCreateOptions = options?.SchemaCreateOptions,
};

/// <summary>Creates an <see cref="McpServerTool"/> that wraps the specified <see cref="AIFunction"/>.</summary>
Expand Down
10 changes: 10 additions & 0 deletions src/ModelContextProtocol/Server/McpServerToolCreateOptions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Microsoft.Extensions.AI;
using ModelContextProtocol.Utils.Json;
using System.ComponentModel;
using System.Text.Json;
Expand Down Expand Up @@ -132,6 +133,14 @@ public sealed class McpServerToolCreateOptions
/// </remarks>
public JsonSerializerOptions? SerializerOptions { get; set; }

/// <summary>
/// Gets or sets the JSON schema options when creating <see cref="AIFunction"/> from a method.
/// </summary>
/// <remarks>
/// Defaults to <see cref="AIJsonSchemaCreateOptions.Default"/> if left unspecified.
/// </remarks>
public AIJsonSchemaCreateOptions? SchemaCreateOptions { get; set; }

/// <summary>
/// Creates a shallow clone of the current <see cref="McpServerToolCreateOptions"/> instance.
/// </summary>
Expand All @@ -147,5 +156,6 @@ internal McpServerToolCreateOptions Clone() =>
OpenWorld = OpenWorld,
ReadOnly = ReadOnly,
SerializerOptions = SerializerOptions,
SchemaCreateOptions = SchemaCreateOptions,
};
}
21 changes: 21 additions & 0 deletions tests/ModelContextProtocol.Tests/Server/McpServerToolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,27 @@ public async Task CanReturnCallToolResponse()
Assert.Equal("image", result.Content[1].Type);
}

[Fact]
public async Task SupportsSchemaCreateOptions()
{
AIJsonSchemaCreateOptions schemaCreateOptions = new ()
{
RequireAllProperties = false
};

McpServerTool tool = McpServerTool.Create((int num1, int num2 = 42) =>
{
return num2.ToString();
}, new() { SchemaCreateOptions = schemaCreateOptions });

Assert.Collection(
tool.ProtocolTool.InputSchema.GetProperty("required").EnumerateArray().Select(x => x.GetString()),
[
x => Assert.Equal("num1", x),
]
);
}

private sealed class MyService;

private class DisposableToolType : IDisposable
Expand Down