package main import ( "context" "log" "github.com/modelcontextprotocol/go-sdk/mcp" todo "github.com/1set/todotxt" ) // var todoFilePath string = "./todo.txt" func getTasksList(path string) todo.TaskList { if tasklist, err := todo.LoadFromPath(path); err != nil { log.Fatal(err) return todo.NewTaskList() } else { return tasklist } } type GetTasksListPrams struct { } func getTasks(ctx context.Context, req *mcp.CallToolRequest, params *GetTasksListPrams) (*mcp.CallToolResult, any, error) { tasksList := getTasksList(*todoFilePath) return &mcp.CallToolResult{ Content: []mcp.Content{ &mcp.TextContent{Text: tasksList.String()}, }, }, nil, nil } type AddTaskParams struct { TaskContent string `json:"taskContent"` } func addTask(ctx context.Context, req *mcp.CallToolRequest, params *AddTaskParams) (*mcp.CallToolResult, any, error) { tasksList := getTasksList(*todoFilePath) newTask, err := todo.ParseTask(params.TaskContent) if err != nil { log.Printf("Error on parsing task %s", params.TaskContent) return &mcp.CallToolResult{ IsError: true, }, nil, nil } else { tasksList.AddTask(newTask) tasksList.WriteToPath(*todoFilePath) log.Printf("New task added: %s", newTask.String()) return &mcp.CallToolResult{ Content: []mcp.Content{ &mcp.TextContent{Text: "New tasks added"}, }, }, nil, nil } } type CheckTaskParams struct { TaskIndex int `json:"taskIndex"` } func checkTask(ctx context.Context, req *mcp.CallToolRequest, params *CheckTaskParams) (*mcp.CallToolResult, any, error) { tasksList := getTasksList(*todoFilePath) tasksList[params.TaskIndex].Complete() tasksList.WriteToPath(*todoFilePath) return &mcp.CallToolResult{ Content: []mcp.Content{ &mcp.TextContent{Text: "Task checked"}, }, }, nil, nil }