@@ -234,6 +234,32 @@ func TestFormatRPCMessageMarkdown(t *testing.T) {
234234 want : []string {"**github**→`tools/call`" , "`{invalid json syntax}`" },
235235 notWant : []string {"~~~" }, // Should NOT use code blocks for invalid JSON
236236 },
237+ {
238+ name : "request with only params null after field removal" ,
239+ info : & RPCMessageInfo {
240+ Direction : RPCDirectionOutbound ,
241+ MessageType : RPCMessageRequest ,
242+ ServerID : "github" ,
243+ Method : "tools/list" ,
244+ PayloadSize : 50 ,
245+ Payload : `{"jsonrpc":"2.0","method":"tools/list","params":null}` ,
246+ },
247+ want : []string {"**github**→`tools/list`" },
248+ notWant : []string {"~~~" , `"params"` }, // Should NOT show JSON block when only params: null
249+ },
250+ {
251+ name : "request with empty object after field removal" ,
252+ info : & RPCMessageInfo {
253+ Direction : RPCDirectionOutbound ,
254+ MessageType : RPCMessageRequest ,
255+ ServerID : "github" ,
256+ Method : "tools/list" ,
257+ PayloadSize : 50 ,
258+ Payload : `{"jsonrpc":"2.0","method":"tools/list"}` ,
259+ },
260+ want : []string {"**github**→`tools/list`" },
261+ notWant : []string {"~~~" }, // Should NOT show JSON block when empty
262+ },
237263 }
238264
239265 for _ , tt := range tests {
@@ -263,6 +289,7 @@ func TestFormatJSONWithoutFields(t *testing.T) {
263289 wantContains []string
264290 wantNotContain []string
265291 wantValid bool
292+ wantEmpty bool
266293 }{
267294 {
268295 name : "remove jsonrpc and method" ,
@@ -271,6 +298,7 @@ func TestFormatJSONWithoutFields(t *testing.T) {
271298 wantContains : []string {`"params"` , `"arg"` , `"value"` , `"id"` },
272299 wantNotContain : []string {`"jsonrpc"` , `"method"` },
273300 wantValid : true ,
301+ wantEmpty : false ,
274302 },
275303 {
276304 name : "indent with 2 spaces" ,
@@ -279,6 +307,7 @@ func TestFormatJSONWithoutFields(t *testing.T) {
279307 wantContains : []string {" \" a\" " , " \" c\" " , " \" d\" " },
280308 wantNotContain : []string {},
281309 wantValid : true ,
310+ wantEmpty : false ,
282311 },
283312 {
284313 name : "invalid JSON returns as-is with false" ,
@@ -287,6 +316,7 @@ func TestFormatJSONWithoutFields(t *testing.T) {
287316 wantContains : []string {`{invalid json}` },
288317 wantNotContain : []string {},
289318 wantValid : false ,
319+ wantEmpty : false ,
290320 },
291321 {
292322 name : "empty object" ,
@@ -295,17 +325,40 @@ func TestFormatJSONWithoutFields(t *testing.T) {
295325 wantContains : []string {`{}` },
296326 wantNotContain : []string {},
297327 wantValid : true ,
328+ wantEmpty : true ,
329+ },
330+ {
331+ name : "only params null after removal" ,
332+ input : `{"jsonrpc":"2.0","method":"tools/list","params":null}` ,
333+ fieldsToRemove : []string {"jsonrpc" , "method" },
334+ wantContains : []string {`"params"` , `null` },
335+ wantNotContain : []string {},
336+ wantValid : true ,
337+ wantEmpty : true ,
338+ },
339+ {
340+ name : "params with value is not empty" ,
341+ input : `{"jsonrpc":"2.0","method":"tools/list","params":{"key":"value"}}` ,
342+ fieldsToRemove : []string {"jsonrpc" , "method" },
343+ wantContains : []string {`"params"` },
344+ wantNotContain : []string {},
345+ wantValid : true ,
346+ wantEmpty : false ,
298347 },
299348 }
300349
301350 for _ , tt := range tests {
302351 t .Run (tt .name , func (t * testing.T ) {
303- result , isValid := formatJSONWithoutFields (tt .input , tt .fieldsToRemove )
352+ result , isValid , isEmpty := formatJSONWithoutFields (tt .input , tt .fieldsToRemove )
304353
305354 if isValid != tt .wantValid {
306355 t .Errorf ("Expected isValid=%v, got %v" , tt .wantValid , isValid )
307356 }
308357
358+ if isEmpty != tt .wantEmpty {
359+ t .Errorf ("Expected isEmpty=%v, got %v" , tt .wantEmpty , isEmpty )
360+ }
361+
309362 for _ , want := range tt .wantContains {
310363 if ! strings .Contains (result , want ) {
311364 t .Errorf ("Expected result to contain %q, got:\n %s" , want , result )
0 commit comments