Add SchemaCreateOptions in McpServerToolCreateOptions/McpServerPromptCreateOptions (#354)
* Add SchemaCreateOptions in McpServerToolCreateOptions * Use TransformSchemaNode for SchemaCreateOptions testing * Add SchemaCreateOptions in McpServerPromptCreateOptions also
This commit is contained in:
parent
ea296f5dc4
commit
e190844218
2 changed files with 71 additions and 0 deletions
|
|
@ -3,7 +3,9 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
using ModelContextProtocol.Protocol.Types;
|
||||
using ModelContextProtocol.Server;
|
||||
using Moq;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ModelContextProtocol.Tests.Server;
|
||||
|
||||
|
|
@ -316,6 +318,30 @@ public class McpServerPromptTests
|
|||
TestContext.Current.CancellationToken));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SupportsSchemaCreateOptions()
|
||||
{
|
||||
AIJsonSchemaCreateOptions schemaCreateOptions = new()
|
||||
{
|
||||
TransformSchemaNode = (context, node) =>
|
||||
{
|
||||
node["description"] = "1234";
|
||||
return node;
|
||||
}
|
||||
};
|
||||
|
||||
McpServerPrompt prompt = McpServerPrompt.Create(([Description("argument1")] int num, [Description("argument2")] string str) =>
|
||||
{
|
||||
return new ChatMessage(ChatRole.User, "Hello");
|
||||
}, new() { SchemaCreateOptions = schemaCreateOptions });
|
||||
|
||||
Assert.NotNull(prompt.ProtocolPrompt.Arguments);
|
||||
Assert.All(
|
||||
prompt.ProtocolPrompt.Arguments,
|
||||
x => Assert.Equal("1234", x.Description)
|
||||
);
|
||||
}
|
||||
|
||||
private sealed class MyService;
|
||||
|
||||
private class DisposablePromptType : IDisposable
|
||||
|
|
|
|||
|
|
@ -355,6 +355,29 @@ public partial class McpServerToolTests
|
|||
Assert.Equal("image", result.Content[1].Type);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SupportsSchemaCreateOptions()
|
||||
{
|
||||
AIJsonSchemaCreateOptions schemaCreateOptions = new ()
|
||||
{
|
||||
TransformSchemaNode = (context, node) =>
|
||||
{
|
||||
node["text"] = "1234";
|
||||
return node;
|
||||
},
|
||||
};
|
||||
|
||||
McpServerTool tool = McpServerTool.Create((int num, string str) =>
|
||||
{
|
||||
return "42";
|
||||
}, new() { SchemaCreateOptions = schemaCreateOptions });
|
||||
|
||||
Assert.All(
|
||||
tool.ProtocolTool.InputSchema.GetProperty("properties").EnumerateObject(),
|
||||
x => Assert.True(x.Value.TryGetProperty("text", out JsonElement value) && value.ToString() == "1234")
|
||||
);
|
||||
}
|
||||
|
||||
private sealed class MyService;
|
||||
|
||||
private class DisposableToolType : IDisposable
|
||||
|
|
|
|||
Loading…
Reference in a new issue