Bring up to 0.1.13 conformance (#1254)
This commit is contained in:
parent
9c1538fd98
commit
27b5eb8031
2 changed files with 1249 additions and 78 deletions
|
|
@ -1,7 +1,11 @@
|
|||
using ConformanceServer.Prompts;
|
||||
using ConformanceServer.Resources;
|
||||
using ConformanceServer.Tools;
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Options;
|
||||
using ModelContextProtocol.Protocol;
|
||||
using ModelContextProtocol.Server;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Text.Json;
|
||||
|
||||
|
|
@ -26,8 +30,28 @@ public class Program
|
|||
|
||||
builder.Services
|
||||
.AddMcpServer()
|
||||
.WithHttpTransport()
|
||||
.WithHttpTransport(options =>
|
||||
{
|
||||
// Enable resumability for SSE polling conformance test
|
||||
options.EventStreamStore = new DistributedCacheEventStreamStore(
|
||||
new MemoryDistributedCache(Options.Create(new MemoryDistributedCacheOptions())));
|
||||
})
|
||||
.WithTools<ConformanceTools>()
|
||||
.WithTools([ConformanceTools.CreateJsonSchema202012Tool()])
|
||||
.AddCallToolFilter(next => async (request, cancellationToken) =>
|
||||
{
|
||||
var result = await next(request, cancellationToken);
|
||||
|
||||
// For the test_reconnection tool, enable polling mode after the tool runs.
|
||||
// This stores the result and closes the SSE stream, so the client
|
||||
// must reconnect via GET with Last-Event-ID to retrieve the result.
|
||||
if (request.Params?.Name == "test_reconnection")
|
||||
{
|
||||
await request.EnablePollingAsync(TimeSpan.FromMilliseconds(500), cancellationToken);
|
||||
}
|
||||
|
||||
return result;
|
||||
})
|
||||
.WithPrompts<ConformancePrompts>()
|
||||
.WithResources<ConformanceResources>()
|
||||
.WithSubscribeToResourcesHandler(async (ctx, ct) =>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ using ModelContextProtocol.Protocol;
|
|||
using ModelContextProtocol.Server;
|
||||
using System.ComponentModel;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ConformanceServer.Tools;
|
||||
|
||||
|
|
@ -399,4 +398,48 @@ public class ConformanceTools
|
|||
return $"Elicitation not supported or error: {ex.Message}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Create the json_schema_2020_12_tool with a raw JSON Schema 2020-12 inputSchema.</summary>
|
||||
public static McpServerTool CreateJsonSchema202012Tool()
|
||||
{
|
||||
var tool = McpServerTool.Create(
|
||||
() => "JSON Schema 2020-12 tool executed successfully",
|
||||
new()
|
||||
{
|
||||
Name = "json_schema_2020_12_tool",
|
||||
Description = "Tool with JSON Schema 2020-12 features"
|
||||
});
|
||||
|
||||
tool.ProtocolTool.InputSchema = JsonElement.Parse("""
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"type": "object",
|
||||
"$defs": {
|
||||
"address": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"street": { "type": "string" },
|
||||
"city": { "type": "string" }
|
||||
}
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"name": { "type": "string" },
|
||||
"address": { "$ref": "#/$defs/address" }
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
""");
|
||||
|
||||
return tool;
|
||||
}
|
||||
|
||||
[McpServerTool(Name = "test_reconnection")]
|
||||
[Description("Tests SSE stream reconnection by closing the stream mid-call")]
|
||||
public static string TestReconnection()
|
||||
{
|
||||
// This tool doesn't need to do anything - the call filter will close the stream after this tool runs,
|
||||
// and the client must reconnect to get the result.
|
||||
return "Reconnection test completed successfully";
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue