create-todo-list.tsโข5.91 kB
/**
* Create TODO List Tool for Goldfish MCP
*
* Creates new TODO lists for tracking tasks and projects
*/
import { Storage } from '../core/storage.js';
import { TodoList, ToolResponse } from '../types/index.js';
import { validateCommonArgs, validateStringParam, createErrorResponse, createSuccessResponse, normalizeWorkspaceName } from '../core/workspace-utils.js';
export interface CreateTodoListArgs {
title: string;
items: string[];
tags?: string[];
description?: string; // NEW - For context/handoff data
metadata?: Record<string, any>; // NEW - Flexible data storage
status?: 'active' | 'completed' | 'archived'; // NEW - Lifecycle status
ttlHours?: number; // NEW - Optional expiration
workspace?: string; // NEW - Optional workspace (path or name)
format?: import('../core/output-utils.js').OutputMode;
}
/**
* Handle create TODO list
*/
export async function handleCreateTodoList(storage: Storage, args: CreateTodoListArgs): Promise<ToolResponse> {
// Validate input
const validation = validateCommonArgs(args);
if (!validation.isValid) {
return createErrorResponse(validation.error!, 'create_todo_list', args.format);
}
// Validate title with examples
const titleValidation = validateStringParam(args.title, 'TODO list title', {
required: true,
minLength: 1,
maxLength: 100,
examples: ['"Sprint Tasks"', '"Bug Fixes"', '"Feature Implementation"']
});
if (!titleValidation.isValid) {
return createErrorResponse(titleValidation.error!, 'create_todo_list', args.format);
}
// Validate items array
if (!args.items) {
return createErrorResponse('๐ Items array is required. Examples: ["Implement user login", "Write unit tests", "Update documentation"]', 'create_todo_list', args.format);
}
if (!Array.isArray(args.items)) {
return createErrorResponse('๐ Items must be an array of strings. Example: ["task 1", "task 2"]', 'create_todo_list', args.format);
}
if (args.items.length === 0) {
return createErrorResponse('๐ Please provide at least one task item. Examples: ["Implement user login", "Write unit tests", "Update documentation"]', 'create_todo_list', args.format);
}
if (args.items.length > 20) {
return createErrorResponse('๐ Too many items. Maximum 20 items per list to keep it manageable. Consider breaking large lists into smaller focused ones.', 'create_todo_list', args.format);
}
// Validate each item
for (let i = 0; i < args.items.length; i++) {
const itemValidation = validateStringParam(args.items[i], `Item ${i + 1}`, {
required: true,
minLength: 1,
maxLength: 200,
examples: ['"Implement user authentication"', '"Write unit tests"']
});
if (!itemValidation.isValid) {
return createErrorResponse(itemValidation.error!, 'create_todo_list', args.format);
}
}
const { title, items, tags, description, metadata, status, ttlHours, workspace } = args;
// Determine target workspace - normalize if provided, otherwise use current
const targetWorkspace = workspace ? normalizeWorkspaceName(workspace) : storage.getCurrentWorkspace();
const todoList: TodoList = {
id: storage.generateChronologicalFilename().replace('.json', ''),
title,
description, // NEW - Optional description
metadata, // NEW - Optional metadata
workspace: targetWorkspace,
items: items.map((task: string, index: number) => ({
id: `${index + 1}`,
task,
status: 'pending' as const,
createdAt: new Date()
})),
createdAt: new Date(),
updatedAt: new Date(),
status: status || 'active', // NEW - Default to 'active'
ttlHours, // NEW - Optional TTL
tags
};
await storage.saveTodoList(todoList);
return createSuccessResponse(
`๐ Created TODO list "${title}" with ${items.length} items (ID: ${todoList.id})`,
'create-todo-list',
{ id: todoList.id, title, items: todoList.items.length, workspace: targetWorkspace },
args.format || 'emoji'
);
}
/**
* Get tool schema for create_todo_list tool
*/
export function getCreateTodoListToolSchema() {
return {
name: 'create_todo_list',
description: 'Create TODO list tied to current session. Use when user mentions multiple tasks or planning work.',
inputSchema: {
type: 'object',
properties: {
title: {
type: 'string',
description: 'Title for the TODO list'
},
items: {
type: 'array',
items: { type: 'string' },
description: 'Array of task items to add'
},
tags: {
type: 'array',
items: { type: 'string' },
description: 'Optional tags for categorization'
},
description: {
type: 'string',
description: 'Optional description providing context for the TODO list'
},
metadata: {
type: 'object',
description: 'Optional metadata for flexible data storage (e.g., agent handoff data)'
},
status: {
type: 'string',
enum: ['active', 'completed', 'archived'],
description: 'Lifecycle status (defaults to active)'
},
ttlHours: {
type: 'number',
description: 'Time-to-live in hours for automatic expiration'
},
workspace: {
type: 'string',
description: 'Workspace name or path (e.g., "coa-goldfish-mcp" or "C:\\source\\COA Goldfish MCP"). Will be normalized automatically. Defaults to current workspace.'
},
format: {
type: 'string',
enum: ['plain', 'emoji', 'json', 'dual'],
description: 'Output format override (defaults to env GOLDFISH_OUTPUT_MODE or dual)'
}
},
required: ['title', 'items']
}
};
}