create_todo
Add a task with a title, priority level, optional description, and tags for categorization. Validates input to ensure data consistency and proper task management.
Instructions
Create a new todo item with validation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | No | Optional description (max 1000 characters) | |
| priority | No | Priority level | medium |
| tags | No | Tags for categorization | |
| title | Yes | Title of the todo (1-200 characters) |
Implementation Reference
- src/handlers/toolHandlers.ts:62-92 (handler)The MCP tool handler for 'create_todo' that sanitizes and validates input, calls the todo service to create the todo, and returns a formatted success or error response.private async handleCreateTodo(request: CallToolRequest): Promise<CallToolResult> { try { const sanitizedArgs = sanitizeInput(request.params.arguments); const validatedRequest = validateData(CreateTodoSchema, sanitizedArgs); const todo = this.todoService.createTodo({ ...validatedRequest, priority: validatedRequest.priority || "medium", tags: validatedRequest.tags || [], }); return { content: [ { type: "text", text: `✅ Todo criado com sucesso!\n\n${JSON.stringify(todo, null, 2)}`, }, ], }; } catch (error) { const errorResponse = createErrorResponse(error, "criar todo"); return { content: [ { type: "text", text: `❌ ${errorResponse.error}\n${errorResponse.details || ""}`, }, ], }; } }
- src/schemas/todo.schemas.ts:19-24 (schema)Zod schema defining the input validation for the create_todo tool parameters: title (required), description (optional), priority, tags.export const CreateTodoSchema = z.object({ title: NonEmptyStringSchema.max(200, 'Título não pode exceder 200 caracteres'), description: z.string().max(500, 'Descrição não pode exceder 500 caracteres').optional(), priority: z.enum(['low', 'medium', 'high']).default('medium'), tags: z.array(z.string().min(1).max(50)).max(10).default([]) });
- src/config/toolDefinitions.ts:2-35 (registration)Tool definition object for 'create_todo' exported in TOOL_DEFINITIONS array, used for MCP tool registration including name, description, and input schema.{ name: "create_todo", description: "Create a new todo item with validation", inputSchema: { type: "object", properties: { title: { type: "string", description: "Title of the todo (1-200 characters)", minLength: 1, maxLength: 200, }, description: { type: "string", description: "Optional description (max 1000 characters)", maxLength: 1000, }, priority: { type: "string", enum: ["low", "medium", "high"], description: "Priority level", default: "medium", }, tags: { type: "array", items: { type: "string", minLength: 1, maxLength: 50 }, maxItems: 10, description: "Tags for categorization", default: [], }, }, required: ["title"], }, },
- Core service method in TodoService that validates the request, generates a new UUID, creates a Todo object with defaults, stores it in the in-memory Map, and returns it.createTodo(request: CreateTodoRequest): Todo { // Validar entrada const validatedRequest = validateData(CreateTodoSchema, request); const todo: Todo = { id: randomUUID(), title: validatedRequest.title, description: validatedRequest.description, completed: false, createdAt: new Date(), priority: validatedRequest.priority || 'medium', tags: validatedRequest.tags || [] }; this.todos.set(todo.id, todo); return todo; }