Skip to main content
Glama
cristip73

MCP Server for Asana

by cristip73

asana_add_task_to_section

Add a task to a specific section in an Asana project to organize project workflows and maintain task structure.

Instructions

Add a task to a specific section in a project

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
section_idYesThe section ID to add the task to
task_idYesThe task ID to add to the section
opt_fieldsNoComma-separated list of optional fields to include

Implementation Reference

  • MCP tool handler case that destructures input parameters (section_id, task_id, opts) and delegates execution to AsanaClientWrapper.addTaskToSection method.
    case "asana_add_task_to_section": {
      const { section_id, task_id, ...opts } = args;
      const response = await asanaClient.addTaskToSection(section_id, task_id, opts);
      return {
        content: [{ type: "text", text: JSON.stringify(response) }],
      };
    }
  • Core execution logic: constructs request data with task GID and insert_before:null, calls Asana SectionsApi.addTaskForSection or fallback direct HTTP POST to /sections/{sectionId}/addTask endpoint.
    async addTaskToSection(sectionId: string, taskId: string, opts: any = {}) {
      const data = {
        data: {
          task: taskId,
          insert_before: null
        }
      };
      try {
        const response = await this.sections.addTaskForSection(sectionId, data, opts);
        return response.data;
      } catch (error) {
        console.error("Error in addTaskToSection:", error);
        // Dacă obținem eroare, încercăm metoda alternativă folosind callApi direct
        try {
          const client = Asana.ApiClient.instance;
          const response = await client.callApi(
            `/sections/${sectionId}/addTask`,
            'POST',
            { section_gid: sectionId },
            {},
            {},
            {},
            { data: { task: taskId, insert_before: null } },
            ['token'],
            ['application/json'],
            ['application/json'],
            'Blob'
          );
          return response.data;
        } catch (fallbackError) {
          console.error("Error in fallback method:", fallbackError);
          throw fallbackError;
        }
      }
    }
  • Tool schema definition including name, description, and inputSchema specifying required section_id and task_id parameters.
    export const addTaskToSectionTool: Tool = {
      name: "asana_add_task_to_section",
      description: "Add a task to a specific section in a project",
      inputSchema: {
        type: "object",
        properties: {
          section_id: {
            type: "string",
            description: "The section ID to add the task to"
          },
          task_id: {
            type: "string",
            description: "The task ID to add to the section"
          },
          opt_fields: {
            type: "string",
            description: "Comma-separated list of optional fields to include"
          }
        },
        required: ["section_id", "task_id"]
      }
    };
  • Tool registration: imports addTaskToSectionTool from task-tools.ts (line 33) and includes it in the exported tools array used for MCP tool registration.
    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 helper: ensures task_id and section_id are valid Asana GIDs in validateSectionParameters.
    case 'asana_add_task_to_section':
      result = validateGid(params.task_id, 'task_id');
      if (!result.valid) errors.push(...result.errors);
      
      result = validateGid(params.section_id, 'section_id');
      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