Skip to main content
Glama

create_task

Create new tasks with unique IDs, descriptions, and dependency tracking for coordinated workflow management.

Instructions

Create a new task

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesUnique identifier for the task
descriptionYesDescription of the task
dependenciesNoIDs of tasks that must be completed first

Implementation Reference

  • The core handler logic for the 'create_task' tool. It extracts arguments, checks if task ID exists, validates dependencies exist, creates a new pending Task, saves to persistent storage, and returns the task as JSON text.
    case "create_task": {
      const { id, description, dependencies } = request.params.arguments as {
        id: string;
        description: string;
        dependencies?: string[];
      };
    
      debug(`Creating task ${id}: ${description}`);
    
      if (tasks[id]) {
        throw new McpError(ErrorCode.InvalidRequest, `Task ${id} already exists`);
      }
    
      // Verify dependencies exist
      if (dependencies) {
        for (const depId of dependencies) {
          if (!tasks[depId]) {
            throw new McpError(ErrorCode.InvalidRequest, `Dependency task ${depId} not found`);
          }
        }
      }
    
      const task: Task = {
        id,
        description,
        status: 'pending',
        dependencies
      };
    
      tasks[id] = task;
      saveTasks();
      debug(`Created task ${id}`);
    
      return {
        content: [{
          type: "text",
          text: JSON.stringify(task, null, 2)
        }]
      };
    }
  • The input schema and metadata for the 'create_task' tool, defined in the ListToolsRequestSchema response. Specifies required id and description, optional dependencies array.
    {
      name: "create_task",
      description: "Create a new task",
      inputSchema: {
        type: "object",
        properties: {
          id: {
            type: "string",
            description: "Unique identifier for the task"
          },
          description: {
            type: "string",
            description: "Description of the task"
          },
          dependencies: {
            type: "array",
            items: {
              type: "string"
            },
            description: "IDs of tasks that must be completed first"
          }
        },
        required: ["id", "description"]
      }
    },
  • TypeScript interface defining the structure of a Task object used throughout the task management tools, including create_task.
    interface Task {
      id: string;
      description: string;
      status: 'pending' | 'in_progress' | 'completed';
      assignedTo?: string;
      result?: string;
      dependencies?: string[];
    }
  • Helper function to persist the tasks object to tasks.json file. Called after creating, updating, or completing tasks to ensure durability.
    function saveTasks() {
      try {
        // Create data directory if it doesn't exist
        const dataDir = dirname(TASKS_FILE);
        if (!existsSync(dataDir)) {
          const { mkdirSync } = require('fs');
          mkdirSync(dataDir, { recursive: true });
        }
        writeFileSync(TASKS_FILE, JSON.stringify(tasks, null, 2));
        debug('Saved tasks to file');
      } catch (error) {
        console.error('Error saving tasks:', error);
      }
    }

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/mokafari/orchestrator-server'

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