| | | 1 | | using System.Text.Json.Serialization; |
| | | 2 | | |
| | | 3 | | namespace NexusLabs.Needlr.Copilot; |
| | | 4 | | |
| | | 5 | | // ── MCP JSON-RPC DTOs ── |
| | | 6 | | |
| | | 7 | | [JsonSerializable(typeof(McpJsonRpcRequest))] |
| | | 8 | | [JsonSerializable(typeof(McpJsonRpcResponse))] |
| | | 9 | | [JsonSourceGenerationOptions( |
| | | 10 | | PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, |
| | | 11 | | DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] |
| | | 12 | | internal partial class McpJsonContext : JsonSerializerContext; |
| | | 13 | | |
| | | 14 | | internal sealed class McpJsonRpcRequest |
| | | 15 | | { |
| | | 16 | | [JsonPropertyName("jsonrpc")] |
| | | 17 | | public string Jsonrpc { get; set; } = "2.0"; |
| | | 18 | | |
| | | 19 | | [JsonPropertyName("id")] |
| | | 20 | | public int Id { get; set; } |
| | | 21 | | |
| | | 22 | | [JsonPropertyName("method")] |
| | | 23 | | public string Method { get; set; } = ""; |
| | | 24 | | |
| | | 25 | | [JsonPropertyName("params")] |
| | | 26 | | public McpCallParams? Params { get; set; } |
| | | 27 | | } |
| | | 28 | | |
| | | 29 | | internal sealed class McpCallParams |
| | | 30 | | { |
| | | 31 | | [JsonPropertyName("name")] |
| | | 32 | | public string Name { get; set; } = ""; |
| | | 33 | | |
| | | 34 | | [JsonPropertyName("arguments")] |
| | | 35 | | public Dictionary<string, string>? Arguments { get; set; } |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | internal sealed class McpJsonRpcResponse |
| | | 39 | | { |
| | | 40 | | [JsonPropertyName("jsonrpc")] |
| | 2 | 41 | | public string? Jsonrpc { get; set; } |
| | | 42 | | |
| | | 43 | | [JsonPropertyName("id")] |
| | 2 | 44 | | public int Id { get; set; } |
| | | 45 | | |
| | | 46 | | [JsonPropertyName("result")] |
| | 4 | 47 | | public McpResult? Result { get; set; } |
| | | 48 | | |
| | | 49 | | [JsonPropertyName("error")] |
| | 2 | 50 | | public McpError? Error { get; set; } |
| | | 51 | | } |
| | | 52 | | |
| | | 53 | | internal sealed class McpResult |
| | | 54 | | { |
| | | 55 | | [JsonPropertyName("content")] |
| | | 56 | | public List<McpContent>? Content { get; set; } |
| | | 57 | | } |
| | | 58 | | |
| | | 59 | | internal sealed class McpContent |
| | | 60 | | { |
| | | 61 | | [JsonPropertyName("type")] |
| | | 62 | | public string? Type { get; set; } |
| | | 63 | | |
| | | 64 | | [JsonPropertyName("text")] |
| | | 65 | | public string? Text { get; set; } |
| | | 66 | | } |
| | | 67 | | |
| | | 68 | | internal sealed class McpError |
| | | 69 | | { |
| | | 70 | | [JsonPropertyName("code")] |
| | | 71 | | public int Code { get; set; } |
| | | 72 | | |
| | | 73 | | [JsonPropertyName("message")] |
| | | 74 | | public string? Message { get; set; } |
| | | 75 | | } |