mcpErrorData marshals data to JSON for use in jsonrpc.Error.Data field. Returns nil if marshaling fails to avoid errors in error handling.
(v any)
| 15 | // mcpErrorData marshals data to JSON for use in jsonrpc.Error.Data field. |
| 16 | // Returns nil if marshaling fails to avoid errors in error handling. |
| 17 | func mcpErrorData(v any) json.RawMessage { |
| 18 | if v == nil { |
| 19 | return nil |
| 20 | } |
| 21 | data, err := json.Marshal(v) |
| 22 | if err != nil { |
| 23 | // Log the error but return nil to avoid breaking error handling |
| 24 | mcpLog.Printf("Failed to marshal error data: %v", err) |
| 25 | return nil |
| 26 | } |
| 27 | return data |
| 28 | } |