Skip to main content
Glama
cristip73
by cristip73

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
NameRequiredDescriptionDefault
object_gidYesThe object GID to attach the file to
file_pathYesPath to the local file
file_nameNoOptional custom file name
file_typeNoOptional MIME type for the uploaded file

Implementation Reference

  • 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; }
  • 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) }], }; }
  • 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"] } };
  • Registration of the tool in the main tools array exported for MCP server.
    getAttachmentsForObjectTool, uploadAttachmentForObjectTool, downloadAttachmentTool

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