ado_add_attachment
Add attachments to Azure DevOps work items by uploading new files or linking existing ones to track documentation and related assets.
Instructions
Agrega un adjunto a un Work Item existente. Puede subir un archivo nuevo o vincular uno ya subido.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workItemId | Yes | ID del Work Item | |
| filePath | No | Ruta del archivo a subir (opcional si se usa attachmentUrl) | |
| attachmentUrl | No | URL de un adjunto ya subido (opcional si se usa filePath) | |
| comment | No | Comentario para el adjunto |
Implementation Reference
- src/index.ts:812-870 (handler)Implementation of the 'ado_add_attachment' tool in src/index.ts, handling both raw file uploads and linking pre-existing attachment URLs to Azure DevOps Work Items.
server.tool( "ado_add_attachment", "Agrega un adjunto a un Work Item existente. Puede subir un archivo nuevo o vincular uno ya subido.", { workItemId: z.number().describe("ID del Work Item"), filePath: z.string().optional().describe("Ruta del archivo a subir (opcional si se usa attachmentUrl)"), attachmentUrl: z.string().optional().describe("URL de un adjunto ya subido (opcional si se usa filePath)"), comment: z.string().optional().describe("Comentario para el adjunto"), }, async ({ workItemId, filePath, attachmentUrl, comment }) => { const api = await getWitApi(); let url = attachmentUrl; // Si se proporciona un archivo, subirlo primero usando REST API if (filePath) { if (!currentPat || !currentOrg) { throw new Error("No hay conexión configurada. Usa ado_configure primero."); } if (!fs.existsSync(filePath)) { throw new Error(`El archivo no existe: ${filePath}`); } const fileName = path.basename(filePath); const attachment = await uploadAttachmentRest(filePath, fileName); url = attachment.url; } if (!url) { throw new Error("Debe proporcionar filePath o attachmentUrl"); } // Vincular el adjunto al Work Item const patchDocument: VSSInterfaces.JsonPatchOperation[] = [ { op: VSSInterfaces.Operation.Add, path: "/relations/-", value: { rel: "AttachedFile", url: url, attributes: { comment: comment || "", }, }, }, ]; await api.updateWorkItem(null, patchDocument, workItemId); return { content: [ { type: "text", text: `Adjunto agregado exitosamente al Work Item #${workItemId}\n- URL: ${url}`, }, ], }; }