Skip to main content
Glama
cristip73

MCP Server for Asana

by cristip73

asana_create_section_for_project

Create a new section within an Asana project to organize tasks and improve project structure.

Instructions

Create a new section in a project

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYesThe project ID to create the section in
nameYesName of the section to create
opt_fieldsNoComma-separated list of optional fields to include

Implementation Reference

  • The main handler logic for the tool in the switch statement. It destructures the required parameters (project_id, name) and optional opts from the arguments, calls the Asana client wrapper method, and returns the JSON-stringified response.
    case "asana_create_section_for_project": {
      const { project_id, name, ...opts } = args;
      const response = await asanaClient.createSectionForProject(project_id, name, opts);
      return {
        content: [{ type: "text", text: JSON.stringify(response) }],
      };
    }
  • Defines the tool's metadata including name, description, and input schema with required fields project_id and name, and optional opt_fields.
    export const createSectionForProjectTool: Tool = {
      name: "asana_create_section_for_project",
      description: "Create a new section in a project",
      inputSchema: {
        type: "object",
        properties: {
          project_id: {
            type: "string",
            description: "The project ID to create the section in"
          },
          name: {
            type: "string",
            description: "Name of the section to create"
          },
          opt_fields: {
            type: "string",
            description: "Comma-separated list of optional fields to include"
          }
        },
        required: ["project_id", "name"]
      }
    };
  • Registers the tool by including createSectionForProjectTool in the exported tools array used for MCP tool handling.
    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
    ];
  • Core helper method in AsanaClientWrapper that performs the actual API call to create a section using Asana SectionsApi, with error handling and fallback to direct API call.
    async createSectionForProject(projectId: string, name: string, opts: any = {}) {
      try {
        const body = {
          data: {
            name
          }
        };
        // Schimbăm ordinea parametrilor conform documentației Asana
        const response = await this.sections.createSectionForProject(projectId, body, opts);
        return response.data;
      } catch (error) {
        console.error(`Error creating section for project: ${error}`);
        // Dacă obținem eroare, încercăm metoda alternativă folosind callApi direct
        try {
          const client = Asana.ApiClient.instance;
          const response = await client.callApi(
            `/projects/${projectId}/sections`,
            'POST',
            { project_gid: projectId },
            {},
            {},
            {},
            { data: { name } },
            ['token'],
            ['application/json'],
            ['application/json'],
            'Blob'
          );
          return response.data;
        } catch (fallbackError) {
          console.error("Error in fallback method:", fallbackError);
          throw fallbackError;
        }
      }
    }
  • Validates the input parameters for the tool: project_id as GID and name as required string.
    case 'asana_create_section_for_project':
      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);
      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