Closedloop.ai
MCP Server

Attachments

List, upload, download, and delete files attached to a document

Overview

Attachment tools manage the files attached to a document: a PRD (PRD-*), an implementation plan (PLN-*), an issue (ISS-*; legacy FEA-* slugs still resolve), or an organization-level document (DOC-*). Every tool takes the document as entityId, which accepts a UUID or a slug; pass the user's slug verbatim and the API resolves it.

An attachment has a purpose:

PurposeMeaning
contextA file attached to the document as supporting material. This is the default.
inlineAn image referenced from the document body with an attachment://<attachmentId> URL. Inline attachments must be images.
ToolScope
list-attachmentsread
download-attachmentread
upload-attachmentwrite
create-inline-image-attachmentwrite
delete-attachmentdelete

A tool is offered to a session only when the session's credential carries its scope. When a call fails, the tool returns an isError result whose text gives the error title, a description, and, when the API sent them, the error code, message, and timestamp.

Allowed file types and sizes

The API accepts these MIME types for upload-attachment:

KindMIME typesSize limit
Mediavideo/quicktime, video/mp4, audio/mpeg524,288,000 bytes (500 MiB)
Imagesimage/jpeg, image/png, image/gif, image/webp10,485,760 bytes (10 MiB)
Other filesapplication/pdf, text/csv, application/json, text/plain, text/markdown, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet10,485,760 bytes (10 MiB)

create-inline-image-attachment accepts only the four image types, up to 524,288 bytes (512 KiB) of decoded image data.


List Attachments

Tool: list-attachments Scope: read Underlying API: GET /documents/{entityId}/attachments (with ?purpose=<value> when purpose is given)

NameTypeRequiredDescription
entityIdstringYesDocument UUID or slug (e.g. PRD-7, PLN-12, ISS-42). Blank values, ., and .. are rejected.
purpose"context" | "inline" | "all"NoWhich attachments to list. When omitted, the API lists context attachments only.
limitintegerNoPage size, 1–100. Default 25.
offsetintegerNoStarting offset, minimum 0. Default 0.

The API returns at most 200 attachments for a document, newest first. The tool pages over that list locally with limit and offset.

Returns

A paginated envelope:

{
  "total": 2,
  "offset": 0,
  "limit": 25,
  "returned": 2,
  "hasMore": false,
  "nextOffset": null,
  "items": [
    {
      "id": "6f1c2d3e-...",
      "artifactId": "0b9a8c7d-...",
      "filename": "architecture.png",
      "mimeType": "image/png",
      "sizeBytes": 48213,
      "purpose": "context",
      "createdAt": "2026-10-01T12:00:00.000Z",
      "createdById": "a1b2c3d4-...",
      "previewUrl": "https://..."
    }
  ]
}

previewUrl is a signed URL that is present only for image attachments, and is omitted when the URL could not be signed. Call again with offset: nextOffset while hasMore is true.

Errors

  • The document does not exist in your organization: Document not found (404).
  • An unrecognized purpose value is rejected by input validation.

Example

list-attachments(entityId: "PRD-7", purpose: "all")

Upload an Attachment

Tool: upload-attachment Scope: write Underlying API: POST /documents/{entityId}/attachments

The tool does not take file bytes. It asks the API for a presigned upload URL; you then upload the bytes yourself with an HTTP PUT to that URL, using exactly the mimeType and sizeBytes you declared. After the upload, call list-attachments to see the attachment.

NameTypeRequiredDescription
entityIdstringYesDocument UUID or slug.
filenamestringYesOriginal filename to store. 1–255 characters (the 255 limit is enforced by the API).
mimeTypestringYesThe MIME type the PUT must use. Must be one of the allowed types.
sizeBytesintegerYesDeclared byte size the PUT must match. Positive; at most 524,288,000 for media types and 10,485,760 for every other type.
purpose"context" | "inline"NoDefaults to context. inline requires an image MIME type.

Returns

The API response, as JSON:

{
  "attachmentId": "6f1c2d3e-...",
  "uploadUrl": "https://...",
  "key": "...",
  "expiresAt": "2026-10-01T12:15:00.000Z"
}

The upload URL is signed for 15 minutes; use it right away. expiresAt may be absent when the API predates it. The response may also carry an operationReceipt object recording the write.

Errors

  • The document does not exist in your organization: Document not found (404).
  • A MIME type outside the allowed list, a filename over 255 characters, or a non-media file over 10,485,760 bytes: a 400 validation error.
  • purpose: "inline" with a non-image MIME type: a 400 (inline attachments must use one of: image/jpeg, image/png, image/gif, image/webp).
  • Too many uploads: a 429 with code attachment_upload_rate_limited and retryAfterSeconds in the details.

Example

upload-attachment(entityId: "PLN-12", filename: "spec.pdf", mimeType: "application/pdf", sizeBytes: 182044)

Create an Inline Image Attachment

Tool: create-inline-image-attachment Scope: write Underlying API: POST /documents/{entityId}/attachments/images

Stores an image from base64 bytes in one call and returns a reference you can put in the document's Markdown. Use this when you have the image bytes in hand and want to embed the image in a document body; to put the reference in the document, append a new version with create-document-version.

NameTypeRequiredDescription
entityIdstringYesDocument UUID or slug. The document must already exist.
filenamestringYesImage filename to store. 1–255 characters (the 255 limit is enforced by the API).
mimeType"image/jpeg" | "image/png" | "image/gif" | "image/webp"YesMIME type of the bytes. The API checks that the bytes match it.
dataBase64stringYesRaw base64 image bytes, with no data: URL prefix. 1–699,052 characters (512 KiB of image data).
altTextstringNoAlt text for the returned Markdown snippet. When omitted or blank, the filename is used.

Returns

The tool returns the result both as text and as structured content:

{
  "attachmentId": "6f1c2d3e-...",
  "attachmentRef": "attachment://6f1c2d3e-...",
  "markdownImage": "![Login screen](attachment://6f1c2d3e-...)",
  "attachment": {
    "id": "6f1c2d3e-...",
    "artifactId": "0b9a8c7d-...",
    "filename": "login.png",
    "mimeType": "image/png",
    "sizeBytes": 48213,
    "purpose": "inline",
    "createdAt": "2026-10-01T12:00:00.000Z",
    "createdById": "a1b2c3d4-...",
    "previewUrl": "https://..."
  }
}

The submitted bytes and the storage key are never returned. previewUrl is omitted when the API does not return one. The response may also carry an operationReceipt object.

Errors

CodeStatusCause
document_not_found404The document does not exist in your organization.
invalid_inline_image_base64400dataBase64 is not raw canonical base64.
inline_image_mime_mismatch400The bytes do not match the declared mimeType.
unsupported_image_mime_type400The MIME type is not a supported image type.
inline_image_too_large413The image, or the request body (768 KiB limit), is too large.
attachment_upload_rate_limited429Too many uploads; retry after retryAfterSeconds.
file_attachments_storage_unconfigured503File storage is not configured on the server.
attachment_storage_write_failed502Storing the image failed.
attachment_persistence_failed500Recording the attachment failed.

Example

create-inline-image-attachment(entityId: "ISS-42", filename: "login.png", mimeType: "image/png", dataBase64: "iVBORw0KGgo...", altText: "Login screen")

Download an Attachment

Tool: download-attachment Scope: read Underlying API: GET /documents/{entityId}/attachments/{attachmentId}

NameTypeRequiredDescription
entityIdstringYesUUID or slug of the document the attachment belongs to. The attachment is looked up only on that document in your organization.
attachmentIdstringYesAttachment UUID, from list-attachments.

Returns

{
  "downloadUrl": "https://..."
}

The URL is signed for one hour and asks the browser to download the file under its stored filename. Download the file soon after the call.

Errors

  • The document does not exist in your organization: Document not found (404).
  • No attachment with that id on that document: Attachment not found (404).

Example

download-attachment(entityId: "PRD-7", attachmentId: "6f1c2d3e-...")

Delete an Attachment

Tool: delete-attachment Scope: delete Underlying API: DELETE /documents/{entityId}/attachments/{attachmentId}

Removes one attachment from a document. Over MCP you can delete only attachments that you created: the MCP server calls the API with your API key, and for API-key requests the API deletes an attachment only when its creator is the authenticated user.

NameTypeRequiredDescription
entityIdstringYesUUID or slug of the document the attachment belongs to.
attachmentIdstringYesAttachment UUID, from list-attachments.

Returns

The API's delete acknowledgement, for example:

{
  "deleted": true
}

The response may also carry an operationReceipt object.

Errors

  • The document does not exist in your organization: Document not found (404).
  • No attachment with that id on that document, or the attachment was created by someone else: Attachment not found (404). The two cases return the same error.

Example

delete-attachment(entityId: "PRD-7", attachmentId: "6f1c2d3e-...")

On this page