asana_download_attachment
Download Asana attachments to your local directory using attachment GID for offline access and file management.
Instructions
Download an attachment locally
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| attachment_gid | Yes | The attachment GID to download | |
| output_dir | No | Directory to save the file (defaults to ~/downloads) |
Input Schema (JSON Schema)
{
"properties": {
"attachment_gid": {
"description": "The attachment GID to download",
"type": "string"
},
"output_dir": {
"description": "Directory to save the file (defaults to ~/downloads)",
"type": "string"
}
},
"required": [
"attachment_gid"
],
"type": "object"
}
Implementation Reference
- src/tool-handler.ts:542-548 (handler)Handler case in the main tool dispatcher that extracts parameters (attachment_gid, output_dir) and delegates to AsanaClientWrapper.downloadAttachment, returning the JSON response.case "asana_download_attachment": { const { attachment_gid, output_dir } = args; const response = await asanaClient.downloadAttachment(attachment_gid, output_dir); return { content: [{ type: "text", text: JSON.stringify(response) }], }; }
- src/tools/attachment-tools.ts:59-76 (schema)Tool schema definition specifying input parameters: attachment_gid (required string), output_dir (optional string).export const downloadAttachmentTool: Tool = { name: "asana_download_attachment", description: "Download an attachment locally", inputSchema: { type: "object", properties: { attachment_gid: { type: "string", description: "The attachment GID to download" }, output_dir: { type: "string", description: "Directory to save the file (defaults to ~/downloads)" } }, required: ["attachment_gid"] } };
- src/tool-handler.ts:56-60 (registration)Imports the downloadAttachmentTool schema for registration in the tools list.getAttachmentsForObjectTool, uploadAttachmentForObjectTool, downloadAttachmentTool } from './tools/attachment-tools.js';
- src/tool-handler.ts:100-102 (registration)Adds downloadAttachmentTool to the exported tools array used for MCP tool registration.getAttachmentsForObjectTool, uploadAttachmentForObjectTool, downloadAttachmentTool
- Core implementation in AsanaClientWrapper: retrieves attachment details, downloads file from download_url using fetch, saves to output_dir (defaults to ~/downloads), handles filename/extension, returns saved file info.async downloadAttachment(attachmentId: string, outputDir?: string) { const fs = await import('fs'); const path = await import('path'); const os = await import('os'); const { pipeline } = await import('stream/promises'); outputDir = outputDir || path.join(os.homedir(), 'downloads'); const attachment = await this.getAttachment(attachmentId); const downloadUrl = attachment.download_url || attachment.downloadUrl; if (!downloadUrl) { throw new Error('Attachment does not have a download_url'); } await fs.promises.mkdir(outputDir, { recursive: true }); const res = await fetch(downloadUrl); if (!res.ok || !res.body) { throw new Error(`Failed to download attachment: ${res.status}`); } let filename: string = attachment.name || attachment.gid; const contentType = res.headers.get('content-type') || attachment.mime_type; if (!path.extname(filename) && contentType) { filename += this.extensionForMime(contentType); } const filePath = path.join(outputDir, filename); const fileStream = fs.createWriteStream(filePath); await pipeline(res.body, fileStream); return { attachment_id: attachmentId, file_path: filePath, mime_type: contentType }; }