todoist_get_labels
Retrieve all labels from Todoist with pagination support to manage tasks, projects, and sections efficiently. Adjust the limit or cursor for precise control over label retrieval.
Instructions
Get all labels. Supports pagination.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cursor | No | Pagination cursor for next page (optional). | |
| limit | No | Maximum number of labels to return (default: 50) (optional). |
Implementation Reference
- src/index.ts:1565-1588 (handler)The handler logic for the 'todoist_get_labels' tool. It validates input arguments using isGetLabelsArgs, calls todoistClient.getLabels with optional pagination parameters (cursor, limit), formats the labels using formatLabel, includes pagination info, and returns formatted text response.if (name === "todoist_get_labels") { if (!isGetLabelsArgs(args)) { return { content: [{ type: "text", text: "Invalid arguments for get_labels. This tool takes an optional cursor and limit." }], isError: true }; } try { const params: any = {}; if (args.cursor) params.cursor = args.cursor; if (args.limit) params.limit = args.limit; const labelsResponse = await todoistClient.getLabels(params); const labelList = labelsResponse.results?.map(formatLabel).join('\n\n') || 'No labels found'; const nextCursor = labelsResponse.nextCursor ? `\n\nNext cursor for more labels: ${labelsResponse.nextCursor}` : ''; return { content: [{ type: "text", text: `Labels:\n${labelList}${nextCursor}` }], isError: false }; } catch (error: any) { return { content: [{ type: "text", text: `Error getting labels: ${error.message}` }], isError: true }; } }
- src/index.ts:317-333 (schema)The Tool object definition for 'todoist_get_labels', including name, description, and inputSchema for optional cursor and limit parameters.const GET_LABELS_TOOL: Tool = { name: "todoist_get_labels", description: "Get all labels. Supports pagination.", inputSchema: { type: "object", properties: { cursor: { type: "string", description: "Pagination cursor for next page (optional)." }, limit: { type: "number", description: "Maximum number of labels to return (default: 50) (optional)." } } } };
- src/index.ts:1108-1114 (registration)Registration of the todoist_get_labels tool (as GET_LABELS_TOOL) in the list of tools returned by ListToolsRequestHandler.// Label tools CREATE_LABEL_TOOL, GET_LABEL_TOOL, GET_LABELS_TOOL, UPDATE_LABEL_TOOL, DELETE_LABEL_TOOL, // Comment tools
- src/index.ts:727-729 (helper)Helper function formatLabel used in the handler to format label objects for output.function formatLabel(label: any): string { return `- ${label.name} (ID: ${label.id})${label.color ? `\n Color: ${label.color}` : ''}${label.isFavorite ? `\n Favorite: Yes` : ''}${label.order ? `\n Order: ${label.order}`: ''}`; }
- src/index.ts:994-999 (helper)Type guard helper isGetLabelsArgs used in the handler to validate input arguments.function isGetLabelsArgs(args: unknown): args is { cursor?: string; limit?: number; } { return typeof args === "object" && args !== null; }