Update Microsoft.Extensions.AI version & expose JSON configuration on McpServerResourceCreateOptions (#511)

* Update Microsoft.Extensions.AI version

* Update Microsoft.Extensions.AI.OpenAI

* Fix failing tests; add JSON configuration options to McpServerResourceCreateOptions.

* Replace temporary code with `AIFunction.ReturnJsonSchema`

---------

Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
This commit is contained in:
Sven Boemer 2025-06-13 05:50:14 -07:00 • committed by GitHub
commit 28d65470f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 45 additions and 35 deletions

View file

@ -5,6 +5,8 @@ using ModelContextProtocol.Server;
using Moq;
using System.ComponentModel;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Nodes;
namespace ModelContextProtocol.Tests.Server;
@ -324,6 +326,11 @@ public class McpServerPromptTests
{
TransformSchemaNode = (context, node) =>
{
if (node.GetValueKind() is not JsonValueKind.Object)
{
node = new JsonObject();
}
node["description"] = "1234";
return node;
}

View file

@ -451,7 +451,7 @@ public partial class McpServerResourceTests
{
Assert.Same(mockServer.Object, server);
return new TextResourceContents() { Text = "hello" };
}, new() { Name = "Test" });
}, new() { Name = "Test", SerializerOptions = JsonContext6.Default.Options });
var result = await resource.ReadAsync(
new RequestContext<ReadResourceRequestParams>(mockServer.Object) { Params = new() { Uri = "resource://Test" } },
TestContext.Current.CancellationToken);
@ -507,7 +507,7 @@ public partial class McpServerResourceTests
{
Assert.Same(mockServer.Object, server);
return new List<string>() { "42", "43" };
}, new() { Name = "Test" });
}, new() { Name = "Test", SerializerOptions = JsonContext6.Default.Options });
var result = await resource.ReadAsync(
new RequestContext<ReadResourceRequestParams>(mockServer.Object) { Params = new() { Uri = "resource://Test" } },
TestContext.Current.CancellationToken);
@ -547,7 +547,7 @@ public partial class McpServerResourceTests
new TextContent("hello!"),
new DataContent(new byte[] { 4, 5, 6 }, "application/json"),
};
}, new() { Name = "Test" });
}, new() { Name = "Test", SerializerOptions = JsonContext6.Default.Options });
var result = await resource.ReadAsync(
new RequestContext<ReadResourceRequestParams>(mockServer.Object) { Params = new() { Uri = "resource://Test" } },
TestContext.Current.CancellationToken);
@ -575,5 +575,8 @@ public partial class McpServerResourceTests
[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)]
[JsonSerializable(typeof(DisposableResourceType))]
[JsonSerializable(typeof(List<AIContent>))]
[JsonSerializable(typeof(List<string>))]
[JsonSerializable(typeof(TextResourceContents))]
partial class JsonContext6 : JsonSerializerContext;
}

View file

@ -190,7 +190,7 @@ public partial class McpServerToolTests
new DataContent("data:image/png;base64,1234"),
new DataContent("data:audio/wav;base64,1234")
};
});
}, new() { SerializerOptions = JsonContext2.Default.Options });
var result = await tool.InvokeAsync(
new RequestContext<CallToolRequestParams>(mockServer.Object),
@ -288,7 +288,7 @@ public partial class McpServerToolTests
{
Assert.Same(mockServer.Object, server);
return new List<string>() { "42", "43" };
});
}, new() { SerializerOptions = JsonContext2.Default.Options });
var result = await tool.InvokeAsync(
new RequestContext<CallToolRequestParams>(mockServer.Object),
TestContext.Current.CancellationToken);
@ -632,5 +632,7 @@ public partial class McpServerToolTests
[JsonSerializable(typeof(AsyncDisposableToolType))]
[JsonSerializable(typeof(AsyncDisposableAndDisposableToolType))]
[JsonSerializable(typeof(JsonSchema))]
[JsonSerializable(typeof(List<AIContent>))]
[JsonSerializable(typeof(List<string>))]
partial class JsonContext2 : JsonSerializerContext;
}