@hiai-gg/docsmint 2.1.4 → 2.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -38,6 +38,7 @@ __export(exports_schema, {
38
38
  documentVisibilityEnum: () => documentVisibilityEnum,
39
39
  documents: () => documents,
40
40
  embeddingStatusEnum: () => embeddingStatusEnum,
41
+ folderCreateOperations: () => folderCreateOperations,
41
42
  folderRelations: () => folderRelations,
42
43
  folders: () => folders,
43
44
  guestAccess: () => guestAccess,
@@ -686,6 +687,18 @@ var documentCreateOperations = pgTable("document_create_operations", {
686
687
  uniqueIndex("document_create_operations_workspace_actor_key_idx").on(table.workspaceId, table.actorUserId, table.idempotencyKey),
687
688
  uniqueIndex("document_create_operations_document_idx").on(table.documentId)
688
689
  ]);
690
+ var folderCreateOperations = pgTable("folder_create_operations", {
691
+ id: uuid("id").primaryKey().defaultRandom(),
692
+ workspaceId: text("workspace_id").notNull(),
693
+ actorUserId: uuid("actor_user_id").notNull().references(() => users.id, { onDelete: "cascade" }),
694
+ idempotencyKey: text("idempotency_key").notNull(),
695
+ folderId: uuid("folder_id").notNull(),
696
+ requestFingerprint: text("request_fingerprint").notNull(),
697
+ createdAt: timestamp("created_at").defaultNow().notNull()
698
+ }, (table) => [
699
+ uniqueIndex("folder_create_operations_workspace_actor_key_unique").on(table.workspaceId, table.actorUserId, table.idempotencyKey),
700
+ uniqueIndex("folder_create_operations_folder_idx").on(table.folderId)
701
+ ]);
689
702
  var versionRelations = relations(versions, ({ one }) => ({
690
703
  document: one(documents, {
691
704
  fields: [versions.documentId],
@@ -38,6 +38,7 @@ __export(exports_schema, {
38
38
  documentVisibilityEnum: () => documentVisibilityEnum,
39
39
  documents: () => documents,
40
40
  embeddingStatusEnum: () => embeddingStatusEnum,
41
+ folderCreateOperations: () => folderCreateOperations,
41
42
  folderRelations: () => folderRelations,
42
43
  folders: () => folders,
43
44
  guestAccess: () => guestAccess,
@@ -686,6 +687,18 @@ var documentCreateOperations = pgTable("document_create_operations", {
686
687
  uniqueIndex("document_create_operations_workspace_actor_key_idx").on(table.workspaceId, table.actorUserId, table.idempotencyKey),
687
688
  uniqueIndex("document_create_operations_document_idx").on(table.documentId)
688
689
  ]);
690
+ var folderCreateOperations = pgTable("folder_create_operations", {
691
+ id: uuid("id").primaryKey().defaultRandom(),
692
+ workspaceId: text("workspace_id").notNull(),
693
+ actorUserId: uuid("actor_user_id").notNull().references(() => users.id, { onDelete: "cascade" }),
694
+ idempotencyKey: text("idempotency_key").notNull(),
695
+ folderId: uuid("folder_id").notNull(),
696
+ requestFingerprint: text("request_fingerprint").notNull(),
697
+ createdAt: timestamp("created_at").defaultNow().notNull()
698
+ }, (table) => [
699
+ uniqueIndex("folder_create_operations_workspace_actor_key_unique").on(table.workspaceId, table.actorUserId, table.idempotencyKey),
700
+ uniqueIndex("folder_create_operations_folder_idx").on(table.folderId)
701
+ ]);
689
702
  var versionRelations = relations(versions, ({ one }) => ({
690
703
  document: one(documents, {
691
704
  fields: [versions.documentId],
@@ -38,6 +38,7 @@ __export(exports_schema, {
38
38
  documentVisibilityEnum: () => documentVisibilityEnum,
39
39
  documents: () => documents,
40
40
  embeddingStatusEnum: () => embeddingStatusEnum,
41
+ folderCreateOperations: () => folderCreateOperations,
41
42
  folderRelations: () => folderRelations,
42
43
  folders: () => folders,
43
44
  guestAccess: () => guestAccess,
@@ -686,6 +687,18 @@ var documentCreateOperations = pgTable("document_create_operations", {
686
687
  uniqueIndex("document_create_operations_workspace_actor_key_idx").on(table.workspaceId, table.actorUserId, table.idempotencyKey),
687
688
  uniqueIndex("document_create_operations_document_idx").on(table.documentId)
688
689
  ]);
690
+ var folderCreateOperations = pgTable("folder_create_operations", {
691
+ id: uuid("id").primaryKey().defaultRandom(),
692
+ workspaceId: text("workspace_id").notNull(),
693
+ actorUserId: uuid("actor_user_id").notNull().references(() => users.id, { onDelete: "cascade" }),
694
+ idempotencyKey: text("idempotency_key").notNull(),
695
+ folderId: uuid("folder_id").notNull(),
696
+ requestFingerprint: text("request_fingerprint").notNull(),
697
+ createdAt: timestamp("created_at").defaultNow().notNull()
698
+ }, (table) => [
699
+ uniqueIndex("folder_create_operations_workspace_actor_key_unique").on(table.workspaceId, table.actorUserId, table.idempotencyKey),
700
+ uniqueIndex("folder_create_operations_folder_idx").on(table.folderId)
701
+ ]);
689
702
  var versionRelations = relations(versions, ({ one }) => ({
690
703
  document: one(documents, {
691
704
  fields: [versions.documentId],
package/dist/client.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  * failures (502 / 503 / 504 / timeout / network reset) are retried
8
8
  * with exponential backoff up to `config.retries` attempts.
9
9
  */
10
- import type { DocsApiKeyCreated, DocsApiKeyListResponse, DocsAttachment, DocsAttachmentConfirmInput, DocsAttachmentListResponse, DocsAttachmentPresignInput, DocsAttachmentPresignResponse, DocsCategory, DocsCategoryListItem, DocsCategoryInput, DocsCategoryUpdate, DocsDocument, DocsDocumentCreateInput, DocsDocumentCursorPage, DocsDocumentIndexRefresh, DocsDocumentIndexStatus, DocsDocumentKnowledgeSummary, DocsDocumentListResponse, DocsDocumentPipeline, DocsPipelineWarningRetry, DocsDocumentUpdateInput, DocsFolder, DocsFolderCreateInput, DocsFolderUpdateInput, DocsGraphEntitiesResponse, DocsGraphRelatedResponse, DocsGraphSearchResponse, DocsHealthResponse, DocsRequestContext, DocsSearchOptions, DocsSearchResponse, DocsSearchSuggestItem, DocsSharedContent, DocsShareLink, DocsShareListResponse, DocsShareRole, DocsTag, DocsTrashResponse, DocsVersion, DocsVersionDiff } from "./types.js";
10
+ import type { DocsApiKeyCreated, DocsApiKeyListResponse, DocsAttachment, DocsAttachmentConfirmInput, DocsAttachmentListResponse, DocsAttachmentPresignInput, DocsAttachmentPresignResponse, DocsCategory, DocsCategoryListItem, DocsCategoryInput, DocsCategoryUpdate, DocsDocument, DocsDocumentCreateInput, DocsDocumentCursorPage, DocsCatalogCursorPage, DocsDocumentIndexRefresh, DocsDocumentIndexStatus, DocsDocumentKnowledgeSummary, DocsDocumentListResponse, DocsDocumentPipeline, DocsPipelineWarningRetry, DocsDocumentUpdateInput, DocsFolder, DocsFolderCreateInput, DocsFolderUpdateInput, DocsGraphEntitiesResponse, DocsGraphRelatedResponse, DocsGraphSearchResponse, DocsHealthResponse, DocsRequestContext, DocsSearchOptions, DocsSearchResponse, DocsSearchSuggestItem, DocsSharedContent, DocsShareLink, DocsShareListResponse, DocsShareRole, DocsTag, DocsTrashResponse, DocsVersion, DocsVersionDiff } from "./types.js";
11
11
  export interface DocsClientConfig {
12
12
  /** Explicit API prefix. Existing clients keep /api; no endpoint probing is performed. */
13
13
  apiPrefix?: "/api" | "/api/v1";
@@ -81,9 +81,12 @@ export declare class DocsClient {
81
81
  categoryId?: string;
82
82
  cursor?: string;
83
83
  limit?: number;
84
+ includeTotal?: boolean;
84
85
  sortBy?: import("./types").DocsDocumentSortField;
85
86
  sortOrder?: import("./types").DocsSortOrder;
86
87
  }, context?: DocsRequestContext): Promise<DocsDocumentCursorPage>;
88
+ listCatalogDocuments(options?: Parameters<DocsClient["listDocuments"]>[0], context?: DocsRequestContext): Promise<DocsCatalogCursorPage>;
89
+ private listDocumentCursor;
87
90
  duplicateDoc(id: string, context?: DocsRequestContext): Promise<DocsDocument>;
88
91
  getDocumentPipeline(id: string, context?: DocsRequestContext): Promise<DocsDocumentPipeline>;
89
92
  retryDocumentPipelineWarnings(id: string, context?: DocsRequestContext): Promise<DocsPipelineWarningRetry>;
@@ -203,6 +206,8 @@ export declare class DocsClient {
203
206
  presignAttachment(documentId: string, input: DocsAttachmentPresignInput, context?: DocsRequestContext): Promise<DocsAttachmentPresignResponse>;
204
207
  confirmAttachment(documentId: string, input: DocsAttachmentConfirmInput, context?: DocsRequestContext): Promise<DocsAttachment>;
205
208
  listAttachments(documentId: string, context?: DocsRequestContext): Promise<DocsAttachmentListResponse>;
209
+ /** Fetch an authorized attachment without exposing its storage URL. */
210
+ fetchAttachment(id: string, context?: DocsRequestContext): Promise<Response>;
206
211
  deleteAttachment(id: string, context?: DocsRequestContext): Promise<void>;
207
212
  listVersions(documentId: string, options?: {
208
213
  onlySnapshots?: boolean;
package/dist/client.js CHANGED
@@ -151,6 +151,12 @@ export class DocsClient {
151
151
  * bound by the server to the authenticated workspace and category scope.
152
152
  */
153
153
  async listDocuments(options = {}, context) {
154
+ return this.listDocumentCursor(options, context);
155
+ }
156
+ async listCatalogDocuments(options = {}, context) {
157
+ return this.listDocumentCursor(options, context, "catalog");
158
+ }
159
+ async listDocumentCursor(options, context, view) {
154
160
  return this.request("GET", "/api/documents/cursor", {
155
161
  query: this.cleanQuery({
156
162
  categoryId: options.categoryId,
@@ -165,6 +171,8 @@ export class DocsClient {
165
171
  updatedTo: options.updatedTo,
166
172
  cursor: options.cursor,
167
173
  limit: options.limit,
174
+ view,
175
+ includeTotal: options.includeTotal === undefined ? undefined : String(options.includeTotal),
168
176
  sortBy: options.sortBy,
169
177
  sortOrder: options.sortOrder,
170
178
  }),
@@ -409,6 +417,13 @@ export class DocsClient {
409
417
  async listAttachments(documentId, context) {
410
418
  return this.request("GET", `/api/documents/${encodeURIComponent(documentId)}/attachments`, undefined, context);
411
419
  }
420
+ /** Fetch an authorized attachment without exposing its storage URL. */
421
+ async fetchAttachment(id, context) {
422
+ const response = await this.fetchRaw("GET", `/api/attachments/${encodeURIComponent(id)}/raw`, {}, context);
423
+ if (!response.ok)
424
+ throw await this.toApiError(response);
425
+ return response;
426
+ }
412
427
  async deleteAttachment(id, context) {
413
428
  await this.request("DELETE", `/api/attachments/${encodeURIComponent(id)}`, undefined, context);
414
429
  }
@@ -37535,6 +37535,7 @@ __export(exports_schema, {
37535
37535
  documentVisibilityEnum: () => documentVisibilityEnum,
37536
37536
  documents: () => documents,
37537
37537
  embeddingStatusEnum: () => embeddingStatusEnum,
37538
+ folderCreateOperations: () => folderCreateOperations,
37538
37539
  folderRelations: () => folderRelations,
37539
37540
  folders: () => folders,
37540
37541
  guestAccess: () => guestAccess,
@@ -38195,6 +38196,18 @@ var documentCreateOperations = pgTable("document_create_operations", {
38195
38196
  uniqueIndex("document_create_operations_workspace_actor_key_idx").on(table.workspaceId, table.actorUserId, table.idempotencyKey),
38196
38197
  uniqueIndex("document_create_operations_document_idx").on(table.documentId)
38197
38198
  ]);
38199
+ var folderCreateOperations = pgTable("folder_create_operations", {
38200
+ id: uuid("id").primaryKey().defaultRandom(),
38201
+ workspaceId: text("workspace_id").notNull(),
38202
+ actorUserId: uuid("actor_user_id").notNull().references(() => users.id, { onDelete: "cascade" }),
38203
+ idempotencyKey: text("idempotency_key").notNull(),
38204
+ folderId: uuid("folder_id").notNull(),
38205
+ requestFingerprint: text("request_fingerprint").notNull(),
38206
+ createdAt: timestamp("created_at").defaultNow().notNull()
38207
+ }, (table) => [
38208
+ uniqueIndex("folder_create_operations_workspace_actor_key_unique").on(table.workspaceId, table.actorUserId, table.idempotencyKey),
38209
+ uniqueIndex("folder_create_operations_folder_idx").on(table.folderId)
38210
+ ]);
38198
38211
  var versionRelations = relations(versions, ({ one }) => ({
38199
38212
  document: one(documents, {
38200
38213
  fields: [versions.documentId],
package/dist/mcp-cli.js CHANGED
@@ -305,6 +305,12 @@ class DocsClient {
305
305
  }, context);
306
306
  }
307
307
  async listDocuments(options = {}, context) {
308
+ return this.listDocumentCursor(options, context);
309
+ }
310
+ async listCatalogDocuments(options = {}, context) {
311
+ return this.listDocumentCursor(options, context, "catalog");
312
+ }
313
+ async listDocumentCursor(options, context, view) {
308
314
  return this.request("GET", "/api/documents/cursor", {
309
315
  query: this.cleanQuery({
310
316
  categoryId: options.categoryId,
@@ -319,6 +325,8 @@ class DocsClient {
319
325
  updatedTo: options.updatedTo,
320
326
  cursor: options.cursor,
321
327
  limit: options.limit,
328
+ view,
329
+ includeTotal: options.includeTotal === undefined ? undefined : String(options.includeTotal),
322
330
  sortBy: options.sortBy,
323
331
  sortOrder: options.sortOrder
324
332
  })
@@ -529,6 +537,12 @@ class DocsClient {
529
537
  async listAttachments(documentId, context) {
530
538
  return this.request("GET", `/api/documents/${encodeURIComponent(documentId)}/attachments`, undefined, context);
531
539
  }
540
+ async fetchAttachment(id, context) {
541
+ const response = await this.fetchRaw("GET", `/api/attachments/${encodeURIComponent(id)}/raw`, {}, context);
542
+ if (!response.ok)
543
+ throw await this.toApiError(response);
544
+ return response;
545
+ }
532
546
  async deleteAttachment(id, context) {
533
547
  await this.request("DELETE", `/api/attachments/${encodeURIComponent(id)}`, undefined, context);
534
548
  }
@@ -1030,6 +1044,13 @@ var operationOutputSchemas = {
1030
1044
  permanently_delete_document: deleteAcknowledgmentSchema
1031
1045
  };
1032
1046
  var variant = (operation, result) => z.object({ operation: z.literal(operation), result });
1047
+ var attachment = z.object({
1048
+ id: z.string().uuid(),
1049
+ filename: z.string(),
1050
+ mimeType: z.string(),
1051
+ size: z.number().int().nonnegative(),
1052
+ url: z.string()
1053
+ });
1033
1054
  var singleToolOutputSchemas = {
1034
1055
  delete_document: operationOutputSchemas.delete_document,
1035
1056
  delete_folder: operationOutputSchemas.delete_folder,
@@ -1051,6 +1072,11 @@ var singleToolOutputSchemas = {
1051
1072
  variant("markdown", operationOutputSchemas.export_document),
1052
1073
  variant("versions", operationOutputSchemas.get_version_history)
1053
1074
  ]),
1075
+ upload_document_image: attachment,
1076
+ check_document_attachments: z.strictObject({
1077
+ items: z.array(attachment),
1078
+ verifiedAttachmentId: z.string().uuid().optional()
1079
+ }),
1054
1080
  save_document: z.union([
1055
1081
  variant("create", operationOutputSchemas.create_document),
1056
1082
  variant("update", operationOutputSchemas.update_document)
@@ -1159,6 +1185,40 @@ function sanitizeMcpRequestContext(context) {
1159
1185
  function createMcpDocsClient(docsClient, requestContext) {
1160
1186
  const context = sanitizeMcpRequestContext(requestContext);
1161
1187
  return {
1188
+ uploadDocumentImage: async (id, filename, mimeType, bytes) => {
1189
+ const descriptor = { filename, contentType: mimeType, size: bytes.byteLength };
1190
+ const upload = await docsClient.presignAttachment(id, descriptor, context);
1191
+ const response = await fetch(upload.url, {
1192
+ method: "PUT",
1193
+ body: new Blob([Uint8Array.from(bytes)], { type: mimeType }),
1194
+ redirect: "error",
1195
+ signal: context?.signal
1196
+ }).catch(() => {
1197
+ throw new Error("Could not send image bytes to DocsMint storage.");
1198
+ });
1199
+ await response.body?.cancel();
1200
+ if (!response.ok)
1201
+ throw new Error(`DocsMint storage rejected the image (${response.status}).`);
1202
+ return docsClient.confirmAttachment(id, {
1203
+ ...descriptor,
1204
+ key: upload.key,
1205
+ uploadToken: upload.uploadToken,
1206
+ quotaReservationId: upload.quotaReservationId
1207
+ }, context);
1208
+ },
1209
+ listAttachments: (id) => docsClient.listAttachments(id, context),
1210
+ verifyAttachment: async (id) => {
1211
+ const response = await docsClient.fetchAttachment(id, context);
1212
+ const reader = response.body?.getReader();
1213
+ if (!reader)
1214
+ throw new Error("The attachment response has no body.");
1215
+ try {
1216
+ if (!(await reader.read()).value?.byteLength)
1217
+ throw new Error("The attachment is empty.");
1218
+ } finally {
1219
+ await reader.cancel();
1220
+ }
1221
+ },
1162
1222
  getFolder: (id) => docsClient.getFolder(id, context),
1163
1223
  createTag: (input) => docsClient.createTag(input, context),
1164
1224
  updateTag: (id, input) => docsClient.updateTag(id, input, context),
@@ -1424,6 +1484,18 @@ var content = z4.string().describe("Markdown document content; an empty string c
1424
1484
  var read = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false };
1425
1485
  var write = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false };
1426
1486
  var destructive = { ...write, destructiveHint: true };
1487
+ function matchesImageType(bytes, mimeType) {
1488
+ switch (mimeType) {
1489
+ case "image/png":
1490
+ return bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]));
1491
+ case "image/jpeg":
1492
+ return bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255;
1493
+ case "image/webp":
1494
+ return bytes.toString("ascii", 0, 4) === "RIFF" && bytes.toString("ascii", 8, 12) === "WEBP";
1495
+ default:
1496
+ return false;
1497
+ }
1498
+ }
1427
1499
  function required2(value, name) {
1428
1500
  if (!value)
1429
1501
  throw new Error(`The injected legacy MCP client does not support ${name}; use a public DocsClient.`);
@@ -1459,6 +1531,32 @@ function registerCompactCapabilities(server, client, wrap) {
1459
1531
  const { action: _action, id, ...data } = input;
1460
1532
  return { operation: "update", result: await client.updateDocument(id, data) };
1461
1533
  });
1534
+ const maxImageBytes = 2 * 1024 * 1024;
1535
+ register("upload_document_image", "Upload one PNG, JPEG or WebP image to an existing editable document. Send the file bytes as base64, up to 2 MiB before encoding. Insert the returned url as an image using save_document. If the result is lost, check attachments before uploading again.", z4.strictObject({
1536
+ documentId: uuid2,
1537
+ filename: z4.string().min(1).max(255).regex(/^[^/\\\u0000-\u001f\u007f]+$/).describe("Image file name with extension and without path segments."),
1538
+ mimeType: z4.enum(["image/png", "image/jpeg", "image/webp"]).describe("MIME type of the source image."),
1539
+ contentBase64: z4.base64().min(4).max(Math.ceil(maxImageBytes / 3) * 4).describe("Base64 file bytes without a data: prefix.")
1540
+ }), write, async ({ documentId, filename, mimeType, contentBase64 }) => {
1541
+ const bytes = Buffer.from(contentBase64, "base64");
1542
+ if (!bytes.length || bytes.length > maxImageBytes)
1543
+ throw new Error("Image must be between 1 byte and 2 MiB.");
1544
+ if (!matchesImageType(bytes, mimeType))
1545
+ throw new Error("Image bytes do not match the declared MIME type.");
1546
+ return required2(client.uploadDocumentImage, "upload_document_image")(documentId, filename, mimeType, bytes);
1547
+ });
1548
+ register("check_document_attachments", "List attachments on a readable document. Supply attachmentId to verify that this attachment belongs to the document and that its stored bytes can be opened with the current access.", z4.strictObject({
1549
+ documentId: uuid2,
1550
+ attachmentId: uuid2.optional()
1551
+ }), read, async ({ documentId, attachmentId }) => {
1552
+ const { items } = await required2(client.listAttachments, "check_document_attachments")(documentId);
1553
+ if (!attachmentId)
1554
+ return { items };
1555
+ if (!items.some((item) => item.id === attachmentId))
1556
+ throw new Error("Attachment not found in this document.");
1557
+ await required2(client.verifyAttachment, "check_document_attachments")(attachmentId);
1558
+ return { items, verifiedAttachmentId: attachmentId };
1559
+ });
1462
1560
  register("delete_document", "Move one document to trash without purging content or versions. Use batch_documents(action=trash) for multiple explicit IDs. Requires write access and an explicit delete request; permanently_delete_document is a separate irreversible action.", z4.strictObject({ id: uuid2 }), destructive, async ({ id }) => {
1463
1561
  await required2(client.deleteDocument, "delete_document")(id);
1464
1562
  return { id, deleted: true };
@@ -1687,7 +1785,7 @@ function registerDocsmintMcpCapabilities(server, client, workspaceRouting, decor
1687
1785
  registerPromptsAndResources(server, client);
1688
1786
  }
1689
1787
  function createDocsmintMcpServer(options = {}) {
1690
- const server = new DocsMintMcpServer({ name: "docsmint", version: "2.1.4" });
1788
+ const server = new DocsMintMcpServer({ name: "docsmint", version: "2.1.9" });
1691
1789
  const client = options.docsClient ? createMcpDocsClient(options.docsClient, options.requestContext) : options.client ?? createMcpDocsClient(createDefaultDocsClient(), options.requestContext);
1692
1790
  registerDocsmintMcpCapabilities(server, client, options.workspaceRouting, options.decorateResult);
1693
1791
  return server;
@@ -300,6 +300,12 @@ class DocsClient {
300
300
  }, context);
301
301
  }
302
302
  async listDocuments(options = {}, context) {
303
+ return this.listDocumentCursor(options, context);
304
+ }
305
+ async listCatalogDocuments(options = {}, context) {
306
+ return this.listDocumentCursor(options, context, "catalog");
307
+ }
308
+ async listDocumentCursor(options, context, view) {
303
309
  return this.request("GET", "/api/documents/cursor", {
304
310
  query: this.cleanQuery({
305
311
  categoryId: options.categoryId,
@@ -314,6 +320,8 @@ class DocsClient {
314
320
  updatedTo: options.updatedTo,
315
321
  cursor: options.cursor,
316
322
  limit: options.limit,
323
+ view,
324
+ includeTotal: options.includeTotal === undefined ? undefined : String(options.includeTotal),
317
325
  sortBy: options.sortBy,
318
326
  sortOrder: options.sortOrder
319
327
  })
@@ -524,6 +532,12 @@ class DocsClient {
524
532
  async listAttachments(documentId, context) {
525
533
  return this.request("GET", `/api/documents/${encodeURIComponent(documentId)}/attachments`, undefined, context);
526
534
  }
535
+ async fetchAttachment(id, context) {
536
+ const response = await this.fetchRaw("GET", `/api/attachments/${encodeURIComponent(id)}/raw`, {}, context);
537
+ if (!response.ok)
538
+ throw await this.toApiError(response);
539
+ return response;
540
+ }
527
541
  async deleteAttachment(id, context) {
528
542
  await this.request("DELETE", `/api/attachments/${encodeURIComponent(id)}`, undefined, context);
529
543
  }
@@ -1025,6 +1039,13 @@ var operationOutputSchemas = {
1025
1039
  permanently_delete_document: deleteAcknowledgmentSchema
1026
1040
  };
1027
1041
  var variant = (operation, result) => z.object({ operation: z.literal(operation), result });
1042
+ var attachment = z.object({
1043
+ id: z.string().uuid(),
1044
+ filename: z.string(),
1045
+ mimeType: z.string(),
1046
+ size: z.number().int().nonnegative(),
1047
+ url: z.string()
1048
+ });
1028
1049
  var singleToolOutputSchemas = {
1029
1050
  delete_document: operationOutputSchemas.delete_document,
1030
1051
  delete_folder: operationOutputSchemas.delete_folder,
@@ -1046,6 +1067,11 @@ var singleToolOutputSchemas = {
1046
1067
  variant("markdown", operationOutputSchemas.export_document),
1047
1068
  variant("versions", operationOutputSchemas.get_version_history)
1048
1069
  ]),
1070
+ upload_document_image: attachment,
1071
+ check_document_attachments: z.strictObject({
1072
+ items: z.array(attachment),
1073
+ verifiedAttachmentId: z.string().uuid().optional()
1074
+ }),
1049
1075
  save_document: z.union([
1050
1076
  variant("create", operationOutputSchemas.create_document),
1051
1077
  variant("update", operationOutputSchemas.update_document)
@@ -1157,6 +1183,40 @@ function sanitizeMcpRequestContext(context) {
1157
1183
  function createMcpDocsClient(docsClient, requestContext) {
1158
1184
  const context = sanitizeMcpRequestContext(requestContext);
1159
1185
  return {
1186
+ uploadDocumentImage: async (id, filename, mimeType, bytes) => {
1187
+ const descriptor = { filename, contentType: mimeType, size: bytes.byteLength };
1188
+ const upload = await docsClient.presignAttachment(id, descriptor, context);
1189
+ const response = await fetch(upload.url, {
1190
+ method: "PUT",
1191
+ body: new Blob([Uint8Array.from(bytes)], { type: mimeType }),
1192
+ redirect: "error",
1193
+ signal: context?.signal
1194
+ }).catch(() => {
1195
+ throw new Error("Could not send image bytes to DocsMint storage.");
1196
+ });
1197
+ await response.body?.cancel();
1198
+ if (!response.ok)
1199
+ throw new Error(`DocsMint storage rejected the image (${response.status}).`);
1200
+ return docsClient.confirmAttachment(id, {
1201
+ ...descriptor,
1202
+ key: upload.key,
1203
+ uploadToken: upload.uploadToken,
1204
+ quotaReservationId: upload.quotaReservationId
1205
+ }, context);
1206
+ },
1207
+ listAttachments: (id) => docsClient.listAttachments(id, context),
1208
+ verifyAttachment: async (id) => {
1209
+ const response = await docsClient.fetchAttachment(id, context);
1210
+ const reader = response.body?.getReader();
1211
+ if (!reader)
1212
+ throw new Error("The attachment response has no body.");
1213
+ try {
1214
+ if (!(await reader.read()).value?.byteLength)
1215
+ throw new Error("The attachment is empty.");
1216
+ } finally {
1217
+ await reader.cancel();
1218
+ }
1219
+ },
1160
1220
  getFolder: (id) => docsClient.getFolder(id, context),
1161
1221
  createTag: (input) => docsClient.createTag(input, context),
1162
1222
  updateTag: (id, input) => docsClient.updateTag(id, input, context),
@@ -1422,6 +1482,18 @@ var content = z4.string().describe("Markdown document content; an empty string c
1422
1482
  var read = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false };
1423
1483
  var write = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false };
1424
1484
  var destructive = { ...write, destructiveHint: true };
1485
+ function matchesImageType(bytes, mimeType) {
1486
+ switch (mimeType) {
1487
+ case "image/png":
1488
+ return bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]));
1489
+ case "image/jpeg":
1490
+ return bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255;
1491
+ case "image/webp":
1492
+ return bytes.toString("ascii", 0, 4) === "RIFF" && bytes.toString("ascii", 8, 12) === "WEBP";
1493
+ default:
1494
+ return false;
1495
+ }
1496
+ }
1425
1497
  function required2(value, name) {
1426
1498
  if (!value)
1427
1499
  throw new Error(`The injected legacy MCP client does not support ${name}; use a public DocsClient.`);
@@ -1457,6 +1529,32 @@ function registerCompactCapabilities(server, client, wrap) {
1457
1529
  const { action: _action, id, ...data } = input;
1458
1530
  return { operation: "update", result: await client.updateDocument(id, data) };
1459
1531
  });
1532
+ const maxImageBytes = 2 * 1024 * 1024;
1533
+ register("upload_document_image", "Upload one PNG, JPEG or WebP image to an existing editable document. Send the file bytes as base64, up to 2 MiB before encoding. Insert the returned url as an image using save_document. If the result is lost, check attachments before uploading again.", z4.strictObject({
1534
+ documentId: uuid2,
1535
+ filename: z4.string().min(1).max(255).regex(/^[^/\\\u0000-\u001f\u007f]+$/).describe("Image file name with extension and without path segments."),
1536
+ mimeType: z4.enum(["image/png", "image/jpeg", "image/webp"]).describe("MIME type of the source image."),
1537
+ contentBase64: z4.base64().min(4).max(Math.ceil(maxImageBytes / 3) * 4).describe("Base64 file bytes without a data: prefix.")
1538
+ }), write, async ({ documentId, filename, mimeType, contentBase64 }) => {
1539
+ const bytes = Buffer.from(contentBase64, "base64");
1540
+ if (!bytes.length || bytes.length > maxImageBytes)
1541
+ throw new Error("Image must be between 1 byte and 2 MiB.");
1542
+ if (!matchesImageType(bytes, mimeType))
1543
+ throw new Error("Image bytes do not match the declared MIME type.");
1544
+ return required2(client.uploadDocumentImage, "upload_document_image")(documentId, filename, mimeType, bytes);
1545
+ });
1546
+ register("check_document_attachments", "List attachments on a readable document. Supply attachmentId to verify that this attachment belongs to the document and that its stored bytes can be opened with the current access.", z4.strictObject({
1547
+ documentId: uuid2,
1548
+ attachmentId: uuid2.optional()
1549
+ }), read, async ({ documentId, attachmentId }) => {
1550
+ const { items } = await required2(client.listAttachments, "check_document_attachments")(documentId);
1551
+ if (!attachmentId)
1552
+ return { items };
1553
+ if (!items.some((item) => item.id === attachmentId))
1554
+ throw new Error("Attachment not found in this document.");
1555
+ await required2(client.verifyAttachment, "check_document_attachments")(attachmentId);
1556
+ return { items, verifiedAttachmentId: attachmentId };
1557
+ });
1460
1558
  register("delete_document", "Move one document to trash without purging content or versions. Use batch_documents(action=trash) for multiple explicit IDs. Requires write access and an explicit delete request; permanently_delete_document is a separate irreversible action.", z4.strictObject({ id: uuid2 }), destructive, async ({ id }) => {
1461
1559
  await required2(client.deleteDocument, "delete_document")(id);
1462
1560
  return { id, deleted: true };
@@ -1624,6 +1722,8 @@ var capabilityCatalog = {
1624
1722
  "find_documents",
1625
1723
  "read_document",
1626
1724
  "save_document",
1725
+ "upload_document_image",
1726
+ "check_document_attachments",
1627
1727
  "delete_document",
1628
1728
  "list_workspace_structure",
1629
1729
  "save_folder",
@@ -1676,6 +1776,8 @@ function example(schema) {
1676
1776
  if (schema.type === "object" || schema.properties) {
1677
1777
  return Object.fromEntries(Object.entries(object2(schema.properties)).filter(([name]) => Array.isArray(schema.required) && schema.required.includes(name) || name === "title" || name === "name").map(([name, value]) => [name, example(object2(value))]));
1678
1778
  }
1779
+ if (schema.contentEncoding === "base64" || schema.format === "base64")
1780
+ return "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aCdwAAAAASUVORK5CYII=";
1679
1781
  if (schema.format === "uuid")
1680
1782
  return "11111111-1111-4111-8111-111111111111";
1681
1783
  if (schema.format === "date-time")
@@ -1885,7 +1987,7 @@ function registerDocsmintMcpCapabilities(server, client, workspaceRouting, decor
1885
1987
  registerPromptsAndResources(server, client);
1886
1988
  }
1887
1989
  function createDocsmintMcpServer(options = {}) {
1888
- const server = new DocsMintMcpServer({ name: "docsmint", version: "2.1.4" });
1990
+ const server = new DocsMintMcpServer({ name: "docsmint", version: "2.1.9" });
1889
1991
  const client = options.docsClient ? createMcpDocsClient(options.docsClient, options.requestContext) : options.client ?? createMcpDocsClient(createDefaultDocsClient(), options.requestContext);
1890
1992
  registerDocsmintMcpCapabilities(server, client, options.workspaceRouting, options.decorateResult);
1891
1993
  return server;
package/dist/types.d.ts CHANGED
@@ -83,6 +83,17 @@ export interface DocsDocumentCursorPage {
83
83
  items: DocsDocumentListItem[];
84
84
  nextCursor: string | null;
85
85
  }
86
+ export interface DocsCatalogCursorPage {
87
+ total?: number;
88
+ items: {
89
+ id: string;
90
+ title: string;
91
+ preview: string;
92
+ folderId: string | null;
93
+ folderName: string | null;
94
+ }[];
95
+ nextCursor: string | null;
96
+ }
86
97
  export type DocsDocumentSortField = "title" | "category" | "folder" | "updated" | "updatedAt" | "createdAt";
87
98
  export type DocsSortOrder = "asc" | "desc";
88
99
  export interface DocsFolder {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hiai-gg/docsmint",
3
3
  "mcpName": "io.github.HiAi-gg/docsmint",
4
- "version": "2.1.4",
4
+ "version": "2.1.9",
5
5
  "type": "module",
6
6
  "browser": {
7
7
  "./dist/backend-launcher.js": false,
@@ -25,7 +25,7 @@ import { registerSearch } from './commands/search.js';
25
25
  import { registerSnapshot } from './commands/snapshot.js';
26
26
  import { registerUpdate } from './commands/update.js';
27
27
 
28
- const VERSION = '2.1.4';
28
+ const VERSION = '2.1.9';
29
29
 
30
30
  const program = new Command();
31
31
  program.name('docsmint').description('CLI for the DocsMint knowledge workspace').version(VERSION);
@@ -998,6 +998,25 @@ export const documentCreateOperations = pgTable(
998
998
  ],
999
999
  );
1000
1000
 
1001
+ export const folderCreateOperations = pgTable(
1002
+ "folder_create_operations",
1003
+ {
1004
+ id: uuid("id").primaryKey().defaultRandom(),
1005
+ workspaceId: text("workspace_id").notNull(),
1006
+ actorUserId: uuid("actor_user_id").notNull().references(() => users.id, { onDelete: "cascade" }),
1007
+ idempotencyKey: text("idempotency_key").notNull(),
1008
+ folderId: uuid("folder_id").notNull(),
1009
+ requestFingerprint: text("request_fingerprint").notNull(),
1010
+ createdAt: timestamp("created_at").defaultNow().notNull(),
1011
+ },
1012
+ (table) => [
1013
+ uniqueIndex("folder_create_operations_workspace_actor_key_unique").on(
1014
+ table.workspaceId, table.actorUserId, table.idempotencyKey,
1015
+ ),
1016
+ uniqueIndex("folder_create_operations_folder_idx").on(table.folderId),
1017
+ ],
1018
+ );
1019
+
1001
1020
  export const versionRelations = relations(versions, ({ one }) => ({
1002
1021
  document: one(documents, {
1003
1022
  fields: [versions.documentId],
package/server.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "id": "1249550690",
11
11
  "subfolder": "packages/mcp-server"
12
12
  },
13
- "version": "2.1.4",
13
+ "version": "2.1.9",
14
14
  "icons": [
15
15
  {
16
16
  "src": "https://raw.githubusercontent.com/HiAi-gg/docsmint/main/frontend/static/logo-dark.png",
@@ -34,7 +34,7 @@
34
34
  "registryType": "npm",
35
35
  "registryBaseUrl": "https://registry.npmjs.org",
36
36
  "identifier": "@hiai-gg/docsmint",
37
- "version": "2.1.4",
37
+ "version": "2.1.9",
38
38
  "runtimeHint": "npx",
39
39
  "transport": {
40
40
  "type": "stdio"
@@ -87,7 +87,7 @@
87
87
  "licenseFile": "https://github.com/HiAi-gg/docsmint/blob/main/LICENSE",
88
88
  "documentationUrl": "https://docsmint.com/mcp/connect?source=mcp_registry",
89
89
  "catalog": {
90
- "tools": 22,
90
+ "tools": 24,
91
91
  "prompts": 2,
92
92
  "resources": 3
93
93
  }
@@ -31,4 +31,11 @@ Use this skill when an agent must create, organize, edit, or research documents
31
31
  5. Use `create_snapshot` before a substantial rewrite; choose a version through `read_document(view=versions)` before `restore_document_version`.
32
32
  6. Treat `delete_document`, `restore_trashed_document`, and `permanently_delete_document` as distinct lifecycle actions. Purge only on an explicit request.
33
33
 
34
+ ## Image attachments
35
+
36
+ 1. Read the document with `read_document(view=detail)`. Check existing files with `check_document_attachments` before retrying a previous upload.
37
+ 2. Call `upload_document_image` with `documentId`, `filename`, `mimeType`, and `contentBase64`. The document requires edit access. Supply PNG, JPEG or WebP bytes up to 2 MiB, without a data URL prefix.
38
+ 3. Insert the returned `url` as a Markdown image with descriptive alt text via `save_document(action=update)`, preserving the existing content.
39
+ 4. Reread the document and use `check_document_attachments` with the returned `attachmentId` to confirm the bytes open with the current access.
40
+
34
41
  DocsMint owns chunking, embeddings, multilingual hybrid retrieval, cross-encoder rerank, entity extraction, and GraphRAG indexing. Agents must use the MCP tools and never write those persistence layers directly.