get_labels_list
Retrieve all personal labels from Todoist to organize tasks and manage projects effectively.
Instructions
Get all personal labels from Todoist
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/utils/handlers.ts:92-146 (handler)The core handler logic for the get_labels_list tool. This anonymous function is generated by createApiHandler and executes todoistApi.get('/labels', {}) since no parameters are required, retrieving the list of personal labels from Todoist REST API.const handler = async (args: z.infer<z.ZodObject<T>>): Promise<R> => { let finalPath = options.path; const pathParams: Record<string, string> = {}; // Extract path parameters (e.g., {id}) and replace them with actual values const pathParamRegex = /{([^}]+)}/g; let match; while ((match = pathParamRegex.exec(options.path)) !== null) { const fullMatch = match[0]; // e.g., "{id}" const paramName = match[1]; // e.g., "id" if (args[paramName] === undefined) { throw new Error(`Path parameter ${paramName} is required but not provided`); } // Validate and encode path parameter using the centralized security function const safeParamValue = validatePathParameter(args[paramName], paramName); finalPath = finalPath.replace(fullMatch, safeParamValue); pathParams[paramName] = String(args[paramName]); } // Collect non-path parameters for query string or request body const otherParams = Object.entries(args).reduce( (acc, [key, value]) => { if (value !== undefined && !pathParams[key]) { acc[key] = value; } return acc; }, {} as Record<string, any> ); // Apply custom parameter transformation if provided const finalParams = options.transformParams ? options.transformParams(args) : otherParams; // Execute the API request based on HTTP method let result; switch (options.method) { case 'GET': result = await todoistApi.get(finalPath, finalParams); break; case 'POST': log('POST', finalPath, finalParams); result = await todoistApi.post(finalPath, finalParams); break; case 'DELETE': result = await todoistApi.delete(finalPath); break; } // Apply result post-processing if provided return options.processResult ? options.processResult(result, args) : result; };
- src/tools/labels.ts:4-10 (registration)Tool registration for get_labels_list, specifying name, empty input schema, GET method, and '/labels' path which triggers the Todoist API call for listing labels.createApiHandler({ name: 'get_labels_list', description: 'Get all personal labels from Todoist', schemaShape: {}, method: 'GET', path: '/labels', });
- src/tools/labels.ts:7-7 (schema)Input schema for get_labels_list tool, which is empty object indicating no input parameters are required.schemaShape: {},
- src/utils/TodoistClient.ts:51-74 (helper)The TodoistClient.get method implementation that performs the actual HTTP GET request to https://api.todoist.com/rest/v2/labels for fetching the labels list.async get(endpoint: string, params: Record<string, string> = {}): Promise<any> { let url = `${API_BASE_URL}${endpoint}`; const queryParams = new URLSearchParams(); for (const [key, value] of Object.entries(params)) { if (value) { queryParams.append(key, value); } } const queryString = queryParams.toString(); if (queryString) { url += `?${queryString}`; } log(`Making GET request to: ${url}`); const response = await fetch(url, { method: 'GET', headers: this.getHeaders(), }); return this.handleResponse(response); }