Skip to main content
Glama
bsmi021

MCP Task Manager Server

by bsmi021

getNextTask

Retrieves the next actionable task for a specified project. Evaluates task status, dependencies, priority, and creation order to determine the task ready for execution. Returns task details or null if none are available.

Instructions

Identifies and returns the next actionable task within a specified project. A task is considered actionable if its status is 'todo' and all its dependencies (if any) have a status of 'done'. If multiple tasks are ready, the one with the highest priority ('high' > 'medium' > 'low') is chosen. If priorities are equal, the task created earliest is chosen. Returns the full details of the next task, or null if no task is currently ready.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYesThe unique identifier (UUID) of the project to find the next task for.

Implementation Reference

  • The handler function 'processRequest' that executes the core logic of the 'getNextTask' tool: validates input, calls TaskService.getNextTask(project_id), handles errors, and returns the task as JSON string or null.
    const processRequest = async (args: GetNextTaskArgs) => {
        logger.info(`[${TOOL_NAME}] Received request with args:`, args);
        try {
            // Call the service method to get the next task
            const nextTask = await taskService.getNextTask(args.project_id);
    
            // Format the successful response
            if (nextTask) {
                logger.info(`[${TOOL_NAME}] Next task found: ${nextTask.task_id} in project ${args.project_id}`);
            } else {
                logger.info(`[${TOOL_NAME}] No ready task found for project ${args.project_id}`);
            }
    
            return {
                content: [{
                    type: "text" as const,
                    // Return the full task object or null
                    text: JSON.stringify(nextTask)
                }]
            };
        } catch (error: unknown) {
            // Handle potential errors
            logger.error(`[${TOOL_NAME}] Error processing request:`, error);
    
            if (error instanceof NotFoundError) {
                // Project not found
                throw new McpError(ErrorCode.InvalidParams, error.message);
            } else {
                // Generic internal error
                const message = error instanceof Error ? error.message : 'An unknown error occurred while getting the next task.';
                throw new McpError(ErrorCode.InternalError, message);
            }
        }
    };
  • Schema definitions: TOOL_NAME, TOOL_DESCRIPTION, TOOL_PARAMS (Zod schema for project_id: UUID), and GetNextTaskArgs type.
    export const TOOL_NAME = "getNextTask";
    
    export const TOOL_DESCRIPTION = `
    Identifies and returns the next actionable task within a specified project.
    A task is considered actionable if its status is 'todo' and all its dependencies (if any) have a status of 'done'.
    If multiple tasks are ready, the one with the highest priority ('high' > 'medium' > 'low') is chosen.
    If priorities are equal, the task created earliest is chosen.
    Returns the full details of the next task, or null if no task is currently ready.
    `;
    
    // Zod schema for the parameters, matching FR-007 and getNextTaskTool.md spec
    export const TOOL_PARAMS = z.object({
        project_id: z.string()
            .uuid("The project_id must be a valid UUID.")
            .describe("The unique identifier (UUID) of the project to find the next task for."), // Required, UUID format
    });
    
    // Define the expected type for arguments based on the Zod schema
    export type GetNextTaskArgs = z.infer<typeof TOOL_PARAMS>;
  • Registration function getNextTaskTool that defines the handler and registers it with the MCP server using server.tool().
    export const getNextTaskTool = (server: McpServer, taskService: TaskService): void => {
    
        const processRequest = async (args: GetNextTaskArgs) => {
            logger.info(`[${TOOL_NAME}] Received request with args:`, args);
            try {
                // Call the service method to get the next task
                const nextTask = await taskService.getNextTask(args.project_id);
    
                // Format the successful response
                if (nextTask) {
                    logger.info(`[${TOOL_NAME}] Next task found: ${nextTask.task_id} in project ${args.project_id}`);
                } else {
                    logger.info(`[${TOOL_NAME}] No ready task found for project ${args.project_id}`);
                }
    
                return {
                    content: [{
                        type: "text" as const,
                        // Return the full task object or null
                        text: JSON.stringify(nextTask)
                    }]
                };
            } catch (error: unknown) {
                // Handle potential errors
                logger.error(`[${TOOL_NAME}] Error processing request:`, error);
    
                if (error instanceof NotFoundError) {
                    // Project not found
                    throw new McpError(ErrorCode.InvalidParams, error.message);
                } else {
                    // Generic internal error
                    const message = error instanceof Error ? error.message : 'An unknown error occurred while getting the next task.';
                    throw new McpError(ErrorCode.InternalError, message);
                }
            }
        };
    
        // Register the tool with the server
        server.tool(TOOL_NAME, TOOL_DESCRIPTION, TOOL_PARAMS.shape, processRequest);
    
        logger.info(`[${TOOL_NAME}] Tool registered successfully.`);
    };
  • Central registration point where getNextTaskTool is invoked during overall tool registration.
    getNextTaskTool(server, taskService);
  • TaskService.getNextTask: Finds the next ready task (todo status, deps done), prioritizes by priority then creation date, returns full task details or null.
    public async getNextTask(projectId: string): Promise<FullTaskData | null> {
        logger.info(`[TaskService] Attempting to get next task for project ${projectId}`);
    
        // 1. Validate Project Existence
        const projectExists = this.projectRepository.findById(projectId);
        if (!projectExists) {
            logger.warn(`[TaskService] Project not found: ${projectId}`);
            throw new NotFoundError(`Project with ID ${projectId} not found.`);
        }
    
        // 2. Find ready tasks using the repository method
        try {
            const readyTasks = this.taskRepository.findReadyTasks(projectId);
    
            if (readyTasks.length === 0) {
                logger.info(`[TaskService] No ready tasks found for project ${projectId}`);
                return null; // No task is ready
            }
    
            // 3. The first task in the list is the highest priority one due to repo ordering
            const nextTask = readyTasks[0];
            logger.info(`[TaskService] Next task identified: ${nextTask.task_id}`);
    
            // 4. Fetch full details (dependencies, subtasks) for the selected task
            // We could potentially optimize this if findReadyTasks returned more details,
            // but for separation of concerns, we call getTaskById logic (or similar).
            // Re-using getTaskById logic:
            return await this.getTaskById(projectId, nextTask.task_id);
    
        } catch (error) {
            logger.error(`[TaskService] Error getting next task for project ${projectId}:`, error);
            throw error; // Re-throw repository or other errors
        }
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It clearly describes the selection algorithm (status, dependencies, priority, creation order) and return behavior (full details or null), which are crucial for understanding how the tool operates. It does not mention error handling, performance, or side effects, but covers core behavior adequately.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the main purpose in the first sentence, followed by detailed selection criteria and return behavior in concise sentences. Each sentence adds necessary information without redundancy, making it efficient and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of the selection logic and no output schema, the description provides a complete explanation of how the next task is chosen and what is returned (full details or null). It lacks details on error cases or output format specifics, but for a tool with no annotations, it covers the essential context adequately.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the parameter 'project_id' documented as a UUID for the project. The description does not add any additional meaning beyond the schema, such as explaining what constitutes a valid project or how it relates to task selection. Baseline score of 3 is appropriate as the schema handles parameter documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('identifies and returns') and resource ('next actionable task within a specified project'), distinguishing it from siblings like listTasks (which lists all tasks) or showTask (which shows a specific task). It explains the selection logic, making the purpose explicit and distinct.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context by specifying that it finds the next task based on status, dependencies, priority, and creation time, suggesting it's for workflow management. However, it does not explicitly state when to use this tool versus alternatives like listTasks or setTaskStatus, nor does it mention prerequisites or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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/bsmi021/mcp-task-manager-server'

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