asana_reorder_sections
Change the position of sections within Asana projects by moving them before or after other sections to organize project structure.
Instructions
Reorder a section within a project by specifying its position relative to another section
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | The project ID containing the sections to reorder | |
| section_id | Yes | The section GID to reorder | |
| before_section_id | No | Insert the section before this section GID. Use null for first position. | |
| after_section_id | No | Insert the section after this section GID. Use null for last position. |
Input Schema (JSON Schema)
{
"properties": {
"after_section_id": {
"description": "Insert the section after this section GID. Use null for last position.",
"type": "string"
},
"before_section_id": {
"description": "Insert the section before this section GID. Use null for first position.",
"type": "string"
},
"project_id": {
"description": "The project ID containing the sections to reorder",
"type": "string"
},
"section_id": {
"description": "The section GID to reorder",
"type": "string"
}
},
"required": [
"project_id",
"section_id"
],
"type": "object"
}
Implementation Reference
- src/tool-handler.ts:510-516 (handler)The main handler case in the tool switch statement that destructures input arguments and delegates to AsanaClientWrapper.reorderSections method, then returns the JSON stringified response.case "asana_reorder_sections": { const { project_id, section_id, before_section_id, after_section_id } = args; const response = await asanaClient.reorderSections(project_id, section_id, before_section_id, after_section_id); return { content: [{ type: "text", text: JSON.stringify(response) }], }; }
- src/tools/project-tools.ts:338-363 (schema)Defines the Tool object with name, description, and inputSchema for validating parameters: project_id, section_id, before_section_id, after_section_id.export const reorderSectionsTool: Tool = { name: "asana_reorder_sections", description: "Reorder a section within a project by specifying its position relative to another section", inputSchema: { type: "object", properties: { project_id: { type: "string", description: "The project ID containing the sections to reorder" }, section_id: { type: "string", description: "The section GID to reorder" }, before_section_id: { type: "string", description: "Insert the section before this section GID. Use null for first position." }, after_section_id: { type: "string", description: "Insert the section after this section GID. Use null for last position." } }, required: ["project_id", "section_id"] } };
- src/tool-handler.ts:70-70 (registration)Registers the tool by including reorderSectionsTool in the exported tools array used by the MCP server.reorderSectionsTool,
- Core implementation in AsanaClientWrapper that validates parameters, constructs the API request body, calls Asana SectionsApi.insertSectionForProject to reorder the section, and provides fallback API call if needed.async reorderSections(projectId: string, sectionId: string, beforeSectionId?: string | null, afterSectionId?: string | null) { try { if (!sectionId) { throw new Error("Section ID cannot be empty"); } // Nu putem specifica atât before_section cât și after_section simultan if (beforeSectionId !== undefined && beforeSectionId !== null && afterSectionId !== undefined && afterSectionId !== null) { throw new Error("Cannot specify both before_section and after_section. Choose one."); } const body: any = { data: { section: sectionId } }; // Adăugăm before_section sau after_section la body, dacă sunt specificate if (beforeSectionId !== undefined) { body.data.before_section = beforeSectionId === null ? null : beforeSectionId; } else if (afterSectionId !== undefined) { body.data.after_section = afterSectionId === null ? null : afterSectionId; } else { throw new Error("Must specify either before_section_id or after_section_id"); } // Apelăm API-ul Asana pentru a muta secțiunea const response = await this.sections.insertSectionForProject(projectId, body); return { project_id: projectId, section_id: sectionId, status: "success", before_section: beforeSectionId, after_section: afterSectionId, result: response.data }; } catch (error) { console.error(`Error reordering section for project: ${error}`); // Dacă metoda standard eșuează, încercăm metoda alternativă cu callApi direct try { const client = Asana.ApiClient.instance; const body: any = { data: { section: sectionId } }; // Adăugăm before_section sau after_section la body, dacă sunt specificate if (beforeSectionId !== undefined) { body.data.before_section = beforeSectionId === null ? null : beforeSectionId; } else if (afterSectionId !== undefined) { body.data.after_section = afterSectionId === null ? null : afterSectionId; } const response = await client.callApi( `/projects/${projectId}/sections/insert`, 'POST', { project_gid: projectId }, {}, {}, {}, body, ['token'], ['application/json'], ['application/json'], 'Blob' ); return { project_id: projectId, section_id: sectionId, status: "success (fallback method)", before_section: beforeSectionId, after_section: afterSectionId, result: response.data }; } catch (fallbackError) { console.error("Error in fallback method:", fallbackError); throw error; // Aruncăm eroarea originală } } }