asana_upload_attachment_for_object
Upload local files as attachments to Asana objects like tasks or projects. Attach documents, images, or other files directly from your device to keep project materials organized.
Instructions
Upload a local file as attachment to an object
Input 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 |
Input Schema (JSON Schema)
{
"properties": {
"file_name": {
"description": "Optional custom file name",
"type": "string"
},
"file_path": {
"description": "Path to the local file",
"type": "string"
},
"file_type": {
"description": "Optional MIME type for the uploaded file",
"type": "string"
},
"object_gid": {
"description": "The object GID to attach the file to",
"type": "string"
}
},
"required": [
"object_gid",
"file_path"
],
"type": "object"
}
Implementation Reference
- src/tool-handler.ts:534-540 (handler)MCP tool handler switch case that destructures arguments and calls the Asana client wrapper's uploadAttachmentForObject method, returning the JSON response.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) }], }; }
- Core implementation of the attachment upload: reads local file, creates FormData with parent object_gid and file, POSTs to Asana attachments endpoint using fetch.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/tools/attachment-tools.ts:32-57 (schema)MCP Tool definition including name, description, and inputSchema 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.getAttachmentsForObjectTool, uploadAttachmentForObjectTool, downloadAttachmentTool
- src/utils/validation.ts:367-373 (helper)Parameter validation logic for object_gid (GID format) and file_path (required string).case 'asana_upload_attachment_for_object': result = validateGid(params.object_gid, 'object_gid'); if (!result.valid) errors.push(...result.errors); result = validateString(params.file_path, 'file_path', false); if (!result.valid) errors.push(...result.errors); break;