Allow JsonSerializerOptions parameters for user-defined and inputs and hardcode everything else to the source generator. (#182)

* Allow user-defined JsonSerializerOptions for user-defined and inputs and hardcode everything else to the source generator.

* Add validation for user-defined JsonSerializerOptions.

* Remove out of date comment.

* Address feedback and add tests
This commit is contained in:
Eirik Tsarpalis 2025-04-02 18:43:54 +01:00 • committed by GitHub
commit f1af251c32
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -79,11 +79,11 @@ internal static class Program
await server.SendMessageAsync(new JsonRpcNotification()
{
Method = NotificationMethods.LoggingMessageNotification,
Params = new LoggingMessageNotificationParams
Params = JsonSerializer.SerializeToNode(new LoggingMessageNotificationParams
{
Level = logLevel,
Data = JsonSerializer.Deserialize<JsonElement>("\"Random log message\"")
}
})
}, cancellationToken);
}
@ -91,10 +91,10 @@ internal static class Program
foreach (var resource in _subscribedResources)
{
ResourceUpdatedNotificationParams notificationParams = new() { Uri = resource.Key };
await server.SendMessageAsync(new JsonRpcNotification()
await server.SendMessageAsync(new JsonRpcNotification
{
Method = NotificationMethods.ResourceUpdatedNotification,
Params = notificationParams
Params = JsonSerializer.SerializeToNode(notificationParams),
}, cancellationToken);
}
}
@ -168,7 +168,7 @@ internal static class Program
}
return new CallToolResponse()
{
Content = [new Content() { Text = "Echo: " + message?.ToString(), Type = "text" }]
Content = [new Content() { Text = "Echo: " + message.ToString(), Type = "text" }]
};
}
else if (request.Params?.Name == "sampleLLM")
@ -179,7 +179,7 @@ internal static class Program
{
throw new McpServerException("Missing required arguments 'prompt' and 'maxTokens'");
}
var sampleResult = await request.Server.RequestSamplingAsync(CreateRequestSamplingParams(prompt?.ToString() ?? "", "sampleLLM", Convert.ToInt32(maxTokens?.ToString())),
var sampleResult = await request.Server.RequestSamplingAsync(CreateRequestSamplingParams(prompt.ToString(), "sampleLLM", Convert.ToInt32(maxTokens.GetRawText())),
cancellationToken);
return new CallToolResponse()