@@ -2,7 +2,6 @@ package builtin
22
33import (
44 "context"
5- "encoding/json"
65 "testing"
76
87 "github.com/mark3labs/mcp-go/mcp"
@@ -102,13 +101,11 @@ func TestTodoWrite(t *testing.T) {
102101 t .Errorf ("Expected 2 todos, got %d" , len (storedTodos ))
103102 }
104103
105- // Verify the content
104+ // Verify the content is in readable format
106105 if textContent , ok := mcp .AsTextContent (result .Content [0 ]); ok {
107- var resultTodos []TodoInfo
108- if err := json .Unmarshal ([]byte (textContent .Text ), & resultTodos ); err != nil {
109- t .Errorf ("Failed to parse result JSON: %v" , err )
110- } else if len (resultTodos ) != 2 {
111- t .Errorf ("Expected 2 todos in result, got %d" , len (resultTodos ))
106+ expectedOutput := "\n \n [ ] Test task 1\n [~] Test task 2"
107+ if textContent .Text != expectedOutput {
108+ t .Errorf ("Expected formatted output:\n %s\n Got:\n %s" , expectedOutput , textContent .Text )
112109 }
113110 } else {
114111 t .Error ("Expected text content" )
@@ -148,15 +145,11 @@ func TestTodoRead(t *testing.T) {
148145 t .Fatal ("Expected result to have content" )
149146 }
150147
151- // Verify the content
148+ // Verify the content is in readable format
152149 if textContent , ok := mcp .AsTextContent (result .Content [0 ]); ok {
153- var resultTodos []TodoInfo
154- if err := json .Unmarshal ([]byte (textContent .Text ), & resultTodos ); err != nil {
155- t .Errorf ("Failed to parse result JSON: %v" , err )
156- } else if len (resultTodos ) != 1 {
157- t .Errorf ("Expected 1 todo in result, got %d" , len (resultTodos ))
158- } else if resultTodos [0 ].Content != "Existing task" {
159- t .Errorf ("Expected 'Existing task', got '%s'" , resultTodos [0 ].Content )
150+ expectedOutput := "\n \n [ ] Existing task"
151+ if textContent .Text != expectedOutput {
152+ t .Errorf ("Expected formatted output:\n %s\n Got:\n %s" , expectedOutput , textContent .Text )
160153 }
161154 } else {
162155 t .Error ("Expected text content" )
@@ -282,17 +275,27 @@ func TestTodoActiveCounting(t *testing.T) {
282275 t .Fatalf ("Failed to execute todowrite: %v" , err )
283276 }
284277
285- // Check metadata for correct active count (should be 3: 2 pending + 1 in_progress)
278+ // Check that metadata contains todos
286279 if result .Meta == nil {
287280 t .Fatal ("Expected metadata to be non-nil" )
288281 }
289282
290- title , ok := result .Meta ["title " ].(string )
283+ metaTodos , ok := result .Meta ["todos " ].([] TodoInfo )
291284 if ! ok {
292- t .Fatal ("Expected title in metadata" )
285+ t .Fatal ("Expected todos in metadata" )
293286 }
294287
295- if title != "3 todos" {
296- t .Errorf ("Expected '3 todos', got '%s'" , title )
288+ if len (metaTodos ) != 4 {
289+ t .Errorf ("Expected 4 todos in metadata, got %d" , len (metaTodos ))
290+ }
291+
292+ // Verify the content is in readable format
293+ if textContent , ok := mcp .AsTextContent (result .Content [0 ]); ok {
294+ expectedOutput := "\n \n [ ] Task 1\n [~] Task 2\n [X] Task 3\n [ ] Task 4"
295+ if textContent .Text != expectedOutput {
296+ t .Errorf ("Expected formatted output:\n %s\n Got:\n %s" , expectedOutput , textContent .Text )
297+ }
298+ } else {
299+ t .Error ("Expected text content" )
297300 }
298301}
0 commit comments