asana_upload_attachment_for_object
Upload local files as attachments to Asana objects like tasks or projects using file paths and optional custom names.
Instructions
Upload a local file as attachment to an object
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| object_gid | Yes | The object GID to attach the file to | |
| file_path | Yes | Path to the local file | |
| file_name | No | Optional custom file name | |
| file_type | No | Optional MIME type for the uploaded file |
Implementation Reference
- src/asana-client-wrapper.ts:1500-1530 (handler)Core handler function that reads the local file using fs, creates FormData, and uploads it to Asana's attachments endpoint using fetch with Bearer token authentication.async uploadAttachmentForObject(objectId: string, filePath: string, fileName?: string, fileType?: string) { const fs = await import('fs'); const path = await import('path'); if (!fs.existsSync(filePath)) { throw new Error(`File not found: ${filePath}`); } const form = new FormData(); const name = fileName || path.basename(filePath); const buffer = await fs.promises.readFile(filePath); const file = new File([buffer], name, { type: fileType || 'application/octet-stream' }); form.append('parent', objectId); form.append('file', file); const token = Asana.ApiClient.instance.authentications['token'].accessToken; const response = await fetch('https://app.asana.com/api/1.0/attachments', { method: 'POST', headers: { Authorization: `Bearer ${token}` }, body: form as any }); if (!response.ok) { throw new Error(`Upload failed: ${response.status} ${await response.text()}`); } const result = await response.json(); // Am adăugat tipare explicită pentru a rezolva avertismentul TypeScript const typedResult = result as { data: any }; return typedResult.data; }
- src/tool-handler.ts:534-540 (handler)MCP tool dispatch handler case that extracts parameters and delegates execution to AsanaClientWrapper's uploadAttachmentForObject method.case "asana_upload_attachment_for_object": { const { object_gid, file_path, file_name, file_type } = args; const response = await asanaClient.uploadAttachmentForObject(object_gid, file_path, file_name, file_type); return { content: [{ type: "text", text: JSON.stringify(response) }], }; }
- src/tools/attachment-tools.ts:32-57 (schema)Tool definition including name, description, and input schema for parameter validation.export const uploadAttachmentForObjectTool: Tool = { name: "asana_upload_attachment_for_object", description: "Upload a local file as attachment to an object", inputSchema: { type: "object", properties: { object_gid: { type: "string", description: "The object GID to attach the file to" }, file_path: { type: "string", description: "Path to the local file" }, file_name: { type: "string", description: "Optional custom file name" }, file_type: { type: "string", description: "Optional MIME type for the uploaded file" } }, required: ["object_gid", "file_path"] } };
- src/tool-handler.ts:100-102 (registration)Registration of the tool in the main tools array exported for MCP server.getAttachmentsForObjectTool, uploadAttachmentForObjectTool, downloadAttachmentTool