Skip to main content
Glama
by cristip73

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

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

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

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

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