Skip to main content
Glama
by cristip73

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

NameRequiredDescriptionDefault
attachment_gidYesThe attachment GID to download
output_dirNoDirectory 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

  • 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) }], }; }
  • 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"] } };
  • Imports the downloadAttachmentTool schema for registration in the tools list.
    getAttachmentsForObjectTool, uploadAttachmentForObjectTool, downloadAttachmentTool } from './tools/attachment-tools.js';
  • 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 }; }

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