MCPcopy Create free account
hub / github.com/alecthomas/devtodo2 / handleAdd

Method handleAdd

mcp/server.go:204–240  ·  view source on GitHub ↗
(text, priority, parent string)

Source from the content-addressed store, hash-verified

202}
203
204func (s *Server) handleAdd(text, priority, parent string) (*mcp.CallToolResult, any, error) {
205 if text == "" {
206 return nil, nil, fmt.Errorf("text is required")
207 }
208
209 tasks, err := s.load()
210 if err != nil {
211 return nil, nil, fmt.Errorf("load tasks: %w", err)
212 }
213 if tasks == nil {
214 tasks = devtodo2.NewTaskList()
215 }
216
217 var graft devtodo2.TaskNode = tasks
218 if parent != "" {
219 graft = tasks.Find(parent)
220 if graft == nil {
221 return nil, nil, fmt.Errorf("parent task %q not found", parent)
222 }
223 }
224
225 p := devtodo2.MEDIUM
226 if priority != "" {
227 p = devtodo2.PriorityFromString(priority)
228 }
229
230 task := graft.Create(text, p)
231 if err := s.save(tasks); err != nil {
232 return nil, nil, fmt.Errorf("save: %w", err)
233 }
234
235 result := AddResult{
236 Index: taskIndex(task),
237 Task: taskToInfo(task),
238 }
239 return jsonResult(result)
240}
241
242func (s *Server) handleDone(indices []string) (*mcp.CallToolResult, any, error) {
243 if len(indices) == 0 {

Callers 1

registerToolsMethod · 0.95

Calls 9

loadMethod · 0.95
CreateMethod · 0.95
saveMethod · 0.95
NewTaskListFunction · 0.92
PriorityFromStringFunction · 0.92
taskIndexFunction · 0.85
taskToInfoFunction · 0.85
jsonResultFunction · 0.85
FindMethod · 0.65

Tested by

no test coverage detected