Skip to main content
Glama
cristip73

MCP Server for Asana

by cristip73

asana_create_task

Create a new task in Asana projects with details like name, description, due date, assignee, and custom fields to organize work and track progress.

Instructions

Create a new task in a project

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYesThe project to create the task in
nameYesName of the task
notesNoDescription of the task
html_notesNoHTML-like formatted description of the task. Does not support ALL HTML tags. Only a subset. The only allowed TAG in the HTML are: <body> <h1> <h2> <ol> <ul> <li> <strong> <em> <u> <s> <code> <pre> <blockquote> <a data-asana-type="" data-asana-gid=""> <hr> <img> <table> <tr> <td>. No other tags are allowed. Use the \n to create a newline. Do not use \n after <body>. Example: <body><h1>Motivation</h1> A customer called in to complain <h1>Goal</h1> Fix the problem</body>
due_onNoDue date in YYYY-MM-DD format
assigneeNoAssignee (can be 'me' or a user ID)
followersNoArray of user IDs to add as followers
parentNoThe parent task ID to set this task under
projectsNoArray of project IDs to add this task to
resource_subtypeNoThe type of the task. Can be one of 'default_task' or 'milestone'
custom_fieldsNoObject mapping custom field GID strings to their values. For enum fields use the enum option GID as the value.

Implementation Reference

  • Main handler case for 'asana_create_task' that destructures input parameters and delegates to AsanaClientWrapper.createTask method.
    case "asana_create_task": {
      const { project_id, ...taskData } = args;
      const response = await asanaClient.createTask(project_id, taskData);
      return {
        content: [{ type: "text", text: JSON.stringify(response) }],
      };
    }
  • Tool schema definition including inputSchema with properties, descriptions, and required fields for 'asana_create_task'.
    export const createTaskTool: Tool = {
      name: "asana_create_task",
      description: "Create a new task in a project",
      inputSchema: {
        type: "object",
        properties: {
          project_id: {
            type: "string",
            description: "The project to create the task in"
          },
          name: {
            type: "string",
            description: "Name of the task"
          },
          notes: {
            type: "string",
            description: "Description of the task"
          },
          html_notes: {
            type: "string",
            description: "HTML-like formatted description of the task. Does not support ALL HTML tags. Only a subset. The only allowed TAG in the HTML are: <body> <h1> <h2> <ol> <ul> <li> <strong> <em> <u> <s> <code> <pre> <blockquote> <a data-asana-type=\"\" data-asana-gid=\"\"> <hr> <img> <table> <tr> <td>. No other tags are allowed. Use the \\n to create a newline. Do not use \\n after <body>. Example: <body><h1>Motivation</h1>\nA customer called in to complain\n<h1>Goal</h1>\nFix the problem</body>"
          },
          due_on: {
            type: "string",
            description: "Due date in YYYY-MM-DD format"
          },
          assignee: {
            type: "string",
            description: "Assignee (can be 'me' or a user ID)"
          },
          followers: {
            type: "array",
            items: {
              type: "string"
            },
            description: "Array of user IDs to add as followers"
          },
          parent: {
            type: "string",
            description: "The parent task ID to set this task under"
          },
          projects: {
            type: "array",
            items: {
              type: "string"
            },
            description: "Array of project IDs to add this task to"
          },
          resource_subtype: {
            type: "string",
            description: "The type of the task. Can be one of 'default_task' or 'milestone'"
          },
          custom_fields: {
            type: "object",
            description: "Object mapping custom field GID strings to their values. For enum fields use the enum option GID as the value."
          }
        },
        required: ["project_id", "name"]
      }
    };
  • Core implementation of task creation in AsanaClientWrapper, preparing data (ensuring project inclusion, defaults) and calling Asana SDK's createTask.
    async createTask(projectId: string, data: any) {
      try {
        // Ensure projects array includes the projectId
        const projects = data.projects || [];
        if (!projects.includes(projectId)) {
          projects.push(projectId);
        }
    
        const taskData = {
          data: {
            ...data,
            projects,
            // Handle resource_subtype if provided
            resource_subtype: data.resource_subtype || 'default_task',
            // Handle custom_fields if provided
            custom_fields: data.custom_fields || {},
            // Asigură-te că task-ul este adăugat la sfârșitul listei
            insert_before: null
          }
        };
        const response = await this.tasks.createTask(taskData);
        return response.data;
      } catch (error: any) {
        console.error(`Error creating task: ${error.message}`);
        // Add useful diagnostics information
        if (error.response && error.response.body) {
          console.error(`Response error details: ${JSON.stringify(error.response.body, null, 2)}`);
        }
        
        // Provide more context about the error
        if (error.message.includes("Missing input")) {
          throw new Error(`Failed to create task: Missing required parameters. ${error.message}`);
        }
        
        if (error.message.includes("Not a valid project")) {
          throw new Error(`Project ID ${projectId} is not valid or you don't have access to it.`);
        }
        
        throw error;
      }
    }
  • Registration of the 'asana_create_task' tool (imported as createTaskTool) in the main tools array exported for MCP server.
    export const tools: Tool[] = [
      listWorkspacesTool,
      searchProjectsTool,
      getProjectTool,
      getProjectTaskCountsTool,
      getProjectSectionsTool,
      createSectionForProjectTool,
      createProjectForWorkspaceTool,
      updateProjectTool,
      reorderSectionsTool,
      getProjectStatusTool,
      getProjectStatusesForProjectTool,
      createProjectStatusTool,
      deleteProjectStatusTool,
      searchTasksTool,
      getTaskTool,
      createTaskTool,
      updateTaskTool,
      createSubtaskTool,
      getMultipleTasksByGidTool,
      addTaskToSectionTool,
      getTasksForSectionTool,
      getProjectHierarchyTool,
      getSubtasksForTaskTool,
      getTasksForProjectTool,
      getTasksForTagTool,
      getTagsForWorkspaceTool,
      addTagsToTaskTool,
      addTaskDependenciesTool,
      addTaskDependentsTool,
      setParentForTaskTool,
      addFollowersToTaskTool,
      getStoriesForTaskTool,
      createTaskStoryTool,
      getTeamsForUserTool,
      getTeamsForWorkspaceTool,
      addMembersForProjectTool,
      addFollowersForProjectTool,
      getUsersForWorkspaceTool,
      getAttachmentsForObjectTool,
      uploadAttachmentForObjectTool,
      downloadAttachmentTool
    ];
  • Input validation logic specific to 'asana_create_task' parameters like project_id, name, due_on.
    case 'asana_create_task':
      result = validateGid(params.project_id, 'project_id');
      if (!result.valid) errors.push(...result.errors);
      
      result = validateString(params.name, 'name', false);
      if (!result.valid) errors.push(...result.errors);
      
      if (params.due_on) {
        result = validateDate(params.due_on, 'due_on');
        if (!result.valid) errors.push(...result.errors);
      }
      break;

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/cristip73/mcp-server-asana'

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