Skip to main content
Glama

addTask

Add a new task to your current plan with dependencies and reasoning. Specify where to insert it in the task sequence.

Instructions

向当前计划中动态添加一个新任务。

Args: name (str): 新任务的名称,应确保唯一性。 dependencies (List[int]): 新任务所依赖的任务ID的整数列表 (从0开始)。 reasoning (str): 解释为何要添加此任务的字符串。 after_task_id (int, optional): 一个任务ID,新任务将被插入到该任务之后。如果省略,则添加到列表末尾。

Returns: ToolResponse[TaskOutput]: 包含新创建任务的响应对象。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
dependenciesYes
reasoningYes
after_task_idNo

Implementation Reference

  • The primary handler for the MCP 'addTask' tool. Decorated with @mcp.tool() for automatic registration and schema generation from signature/docstring. Delegates execution to PlanManager instance.
    @mcp.tool()
    def addTask(name: str, dependencies: List[int], reasoning: str, after_task_id: Optional[int] = None) -> ToolResponse[TaskOutput]:
        """
        向当前计划中动态添加一个新任务。
    
        Args:
            name (str): 新任务的名称,应确保唯一性。
            dependencies (List[int]): 新任务所依赖的任务ID的整数列表 (从0开始)。
            reasoning (str): 解释为何要添加此任务的字符串。
            after_task_id (int, optional): 一个任务ID,新任务将被插入到该任务之后。如果省略,则添加到列表末尾。
            
        Returns:
            ToolResponse[TaskOutput]: 包含新创建任务的响应对象。
        """
        return plan_manager.addTask(name, dependencies, reasoning, after_task_id)
  • Core business logic implementation for adding a new task to the plan. Performs dependency validation, circular dependency detection, task creation, insertion at specified position or append, and state updates.
    def addTask(self, name: str, dependencies: List[int], reasoning: str, 
                after_task_id: Optional[int] = None) -> Dict:
        """添加新任务到计划中"""
        # 验证依赖任务存在
        for dep_id in dependencies:
            if not self._find_task_by_id(dep_id):
                return {"success": False, "message": f"Dependency task {dep_id} not found"}
        
        new_id = self._get_next_task_id()
        
        # 检测循环依赖
        if self._detect_circular_dependency(new_id, dependencies):
            return {"success": False, "message": "Circular dependency detected"}
            
        new_task = {
            "id": new_id,
            "name": name,
            "status": "pending",
            "dependencies": dependencies,
            "reasoning": reasoning,
            "result": None
        }
        
        # 插入任务
        if after_task_id is not None:
            try:
                # 寻找插入位置
                insert_index = next(i for i, task in enumerate(self.plan_data["tasks"]) if task["id"] == after_task_id) + 1
                self.plan_data["tasks"].insert(insert_index, new_task)
            except StopIteration:
                return {"success": False, "message": f"Task with id {after_task_id} not found"}
        else:
            self.plan_data["tasks"].append(new_task)
            
        self._update_timestamp()
        
        return {
            "success": True,
            "data": new_task,
            "message": "Task added successfully"
        }
  • Pydantic model defining the structure of a TaskOutput, which is the 'data' field in the ToolResponse returned by addTask.
    class TaskOutput(BaseModel):
        """
        用于工具函数返回任务信息时,定义单个任务输出的Pydantic模型。
        """
        id: int
        name: str
        status: str
        dependencies: List[int]
        reasoning: str
        result: Optional[str] = None
  • Generic Pydantic response wrapper used by addTask and all other tools: ToolResponse[TaskOutput]
    class ToolResponse(BaseModel, Generic[T]):
        """
        一个通用的工具响应模型,用于标准化所有工具的返回结构。
        """
        success: bool = Field(True, description="操作是否成功。")
        message: Optional[str] = Field(None, description="关于操作结果的可读消息。")
        data: Optional[T] = Field(None, description="操作返回的主要数据负载。")
Behavior2/5

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

With no annotations provided, the description carries full burden but lacks critical behavioral details. It doesn't disclose whether this operation is idempotent, what happens if dependencies don't exist, if there are rate limits, or what authentication/permissions are required. The description covers basic functionality but misses important behavioral traits for a mutation tool.

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

Conciseness4/5

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

The description is well-structured with a clear opening sentence followed by organized Args and Returns sections. While efficient, the Returns section could be more concise since there's no output schema, but overall it's appropriately sized with minimal waste.

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

Completeness3/5

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

For a mutation tool with no annotations and no output schema, the description provides adequate parameter semantics but lacks behavioral context. It covers what the tool does and parameter meanings, but doesn't address error conditions, side effects, or return format details. Given the complexity of task management, more behavioral transparency would be beneficial.

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

Parameters5/5

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

With 0% schema description coverage, the description fully compensates by providing clear semantic explanations for all 4 parameters. It explains name uniqueness, dependency format (list of task IDs starting from 0), reasoning purpose, and the optional positioning parameter with default behavior. This adds substantial value beyond the bare schema.

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 verb ('add') and resource ('new task') with specific context ('to current plan'). It distinguishes from siblings like 'editDependencies' or 'completeTask' by focusing on creation rather than modification or completion.

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

Usage Guidelines3/5

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

The description implies usage when needing to add a task to the current plan, but doesn't explicitly state when to use this vs alternatives like 'initializePlan' (for starting) or 'editDependencies' (for modifying). It mentions the optional 'after_task_id' parameter for positioning, which provides some contextual guidance.

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

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/donway19/MCPlanManager'

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