todoist_get_sections
Retrieve sections from a Todoist account to organize tasks by project. Filter sections by project ID for targeted task management and improved workflow efficiency.
Instructions
Get all sections from the user's Todoist account
Args: project_id: Filter sections by project ID (optional)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | No |
Implementation Reference
- src/sections.py:10-38 (handler)The handler function that retrieves all sections from Todoist, optionally filtered by project_id, using batched pagination and returns them as formatted JSON or error message.def todoist_get_sections(ctx: Context, project_id: Optional[str] = None) -> str: """Get all sections from the user's Todoist account Args: project_id: Filter sections by project ID (optional) """ todoist_client = ctx.request_context.lifespan_context.todoist_client try: logger.info(f"Getting sections{' for project ID: ' + project_id if project_id else ''}") # Use same pagination pattern as projects for consistency sections_iterator = todoist_client.get_sections(project_id=project_id) all_sections = [] for section_batch in sections_iterator: all_sections.extend(section_batch) if len(section_batch) < 200: break if not all_sections: logger.info("No sections found") return "No sections found" + (f" in project ID: {project_id}" if project_id else "") logger.info(f"Retrieved {len(all_sections)} sections") return json.dumps([section.to_dict() for section in all_sections], indent=2, default=str) except Exception as error: logger.error(f"Error getting sections: {error}") return f"Error getting sections: {str(error)}"
- src/main.py:78-78 (registration)Registers the todoist_get_sections tool with the MCP server using the FastMCP decorator.mcp.tool()(todoist_get_sections)