Files
pfm/PostFundManagement.Application/Mcp/Records.cs
T
2026-10-30 10:16:27 +02:00

42 lines
1.9 KiB
C#

namespace PostFundManagement.Application.Mcp;
/// <summary>
/// Token-optimized standardized tool response wrapper for MCP tool execution.
/// </summary>
public record Records<T>(bool Success, T? Data = default, string? Message = null, IReadOnlyList<string>? Errors = null)
{
public static Records<T> Ok(T data, string? message = null) => new(true, data, message, null);
public static Records<T> Fail(string error, IReadOnlyList<string>? errors = null) => new(false, default, error, errors);
}
/// <summary>
/// Token-optimized standardized non-generic tool response wrapper for MCP tool execution.
/// </summary>
public record McpToolResult(bool Success, string Message, IReadOnlyList<string>? Errors = null)
{
public static McpToolResult Ok(string message = "Operation completed successfully.") => new(true, message);
public static McpToolResult Fail(string error, IReadOnlyList<string>? errors = null) => new(false, error, errors);
}
public sealed record McpToolDefinition(string Name, string Title, string Description, string Group, bool ReadOnly, IReadOnlyList<McpToolParameter> Parameters);
public sealed record McpToolParameter(string Name, string Type, string Description, bool IsRequired, object? DefaultValue);
public sealed record McpToolExecutionResult(bool Success, object? Data, string? Error, string? SerializedResult)
{
public static McpToolExecutionResult Ok(object? data, JsonSerializerOptions? options = null) =>
new(true, data, null, data != null ? JsonSerializer.Serialize(data, options ?? DefaultJsonOptions) : null);
public static McpToolExecutionResult Fail(string error) =>
new(false, null, error, null);
private static readonly JsonSerializerOptions DefaultJsonOptions = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = false
};
}
public sealed record ToolMethodInfo(Type TargetType, MethodInfo Method, ParameterInfo[] Parameters);