Skip to main content
Glama
mikemc

Todoist MCP Server

by mikemc

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
NameRequiredDescriptionDefault
project_idNo

Implementation Reference

  • 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)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mikemc/todoist-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server