todoist_label_create
Create custom labels in Todoist to organize tasks by adding names, colors, favorite status, and order positions.
Instructions
Create a new label in Todoist
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name of the label to create | |
| color | No | Color of the label (optional) - can be a Todoist color name or hex code | |
| is_favorite | No | Whether the label should be marked as favorite (optional) | |
| order | No | Order position of the label (optional) |
Implementation Reference
- src/handlers/label-handlers.ts:71-95 (handler)The core handler function that executes the todoist_label_create tool: validates input using validateLabelData, calls Todoist API's addLabel method, clears relevant caches, and returns a formatted success message.export async function handleCreateLabel( todoistClient: TodoistApi, args: CreateLabelArgs ): Promise<string> { const validatedData = validateLabelData(args); try { const label = await todoistClient.addLabel({ name: validatedData.name, color: validatedData.color, order: validatedData.order, isFavorite: validatedData.is_favorite, }); labelCache.clear(); labelStatsCache.clear(); return `Label "${label.name}" created successfully (ID: ${label.id})`; } catch (error) { throw new TodoistAPIError( "Failed to create label", error instanceof Error ? error : undefined ); } }
- src/tools/label-tools.ts:13-40 (schema)Defines the Tool object for todoist_label_create, including name, description, and detailed inputSchema with properties (name required, others optional).export const CREATE_LABEL_TOOL: Tool = { name: "todoist_label_create", description: "Create a new label in Todoist", inputSchema: { type: "object", properties: { name: { type: "string", description: "Name of the label to create", }, color: { type: "string", description: "Color of the label (optional) - can be a Todoist color name or hex code", }, is_favorite: { type: "boolean", description: "Whether the label should be marked as favorite (optional)", }, order: { type: "number", description: "Order position of the label (optional)", }, }, required: ["name"], }, };
- src/index.ts:261-266 (registration)Handler registration in the CallToolRequest switch statement: validates arguments using isCreateLabelArgs type guard and dispatches to handleCreateLabel.case "todoist_label_create": if (!isCreateLabelArgs(args)) { throw new Error("Invalid arguments for todoist_label_create"); } result = await handleCreateLabel(apiClient, args); break;
- src/tools/index.ts:62-69 (registration)Registers the todoist_label_create tool (via LABEL_TOOLS array from label-tools.ts) in the complete ALL_TOOLS list returned by ListToolsRequest.export const ALL_TOOLS = [ ...TASK_TOOLS, ...PROJECT_TOOLS, ...COMMENT_TOOLS, ...LABEL_TOOLS, ...SUBTASK_TOOLS, ...TEST_TOOLS, ];