document-mcp 1.5.108 → 2.0.0

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.
package/dist/bin.js CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import { serveStdio } from "@modelcontextprotocol/server/stdio";
3
3
  import { McpServer } from "@modelcontextprotocol/server";
4
- import { DocumentFormatSchema, OdbReportNotSpecifiedError, OdmUnresolvedSectionError, UnrecognizedDocumentSchemaError, base64ToBytes, buildDocumentBytes, bytesToBase64, createLocalDocumentConverter, decodeOdbPackage, decodePackage, describeFontFace, documentFromJson, documentSchemaKindOf, evaluateSelect, extractSourceFontsForFormat, layoutDocumentWithSchema, odbReportToDocx, odbReportToOdt, odbReportToPdf, odbToCsv, odbToXlsx, odmToPdf, parseSelect, readDocumentMetadata, readDocxExtras, readOdbForms, readOdbInventory, readOdbReportContent, readOdbReports, readOdbTables, readPdf, setDocumentMetadata } from "documents.js";
4
+ import { DocumentFormatSchema, OdbReportNotSpecifiedError, OdmUnresolvedSectionError, UnrecognizedDocumentSchemaError, base64ToBytes, buildDocumentBytes, bytesToBase64, createLocalDocumentConverter, decodeOdbPackage, decodePackage, describeFontFace, documentFromJson, documentSchemaKindOf, evaluateSelect, extractSourceFontsForFormat, odbReportToDocx, odbReportToOdt, odbReportToPdf, odbToCsv, odbToXlsx, odmToPdf, parseSelect, readDocumentMetadata, readDocxExtras, readOdbForms, readOdbInventory, readOdbReportContent, readOdbReports, readOdbTables, readPdf, setDocumentMetadata } from "documents.js";
5
5
  import { z } from "zod";
6
6
  import { readFile, writeFile } from "node:fs/promises";
7
7
  import { existsSync, readFileSync } from "node:fs";
8
8
  import { basename, join } from "node:path";
9
9
  //#region package.json
10
- var version = "1.5.108";
10
+ var version = "2.0.0";
11
11
  //#endregion
12
12
  //#region src/io/document-input.ts
13
13
  const EXTENSION_TO_FORMAT = {
@@ -319,12 +319,8 @@ function errorResult(message) {
319
319
  isError: true
320
320
  };
321
321
  }
322
- function isRecord(value) {
323
- return typeof value === "object" && value !== null && !Array.isArray(value);
324
- }
325
- function isLegacyPackageDump(value) {
326
- if (!isRecord(value) || documentSchemaKindOf(value) !== "DocumentPackage") return false;
327
- return value.formatVersion === 1 || "layout" in value && value.formatVersion !== 2;
322
+ function isNamedError(error, name) {
323
+ return error instanceof Error && error.name === name;
328
324
  }
329
325
  function registerFromPackageTools(server) {
330
326
  server.registerTool("from_package", {
@@ -357,7 +353,8 @@ function registerFromPackageTools(server) {
357
353
  };
358
354
  } catch (error) {
359
355
  if (error instanceof UnrecognizedDocumentSchemaError) return errorResult("'source' has no recognised $schema -- only a file carrying a real DocumentPackage (e.g. written by a caller's own --dump-package-equivalent step) can be read back by this tool");
360
- if (error instanceof z.ZodError && isLegacyPackageDump(parsed)) return errorResult("'source' is a DocumentPackage dump in the old formatVersion 1 shape: a 'layout' half beside 'content'. documents.js 2.0.0 fused the two into formatVersion 2 ('content' + 'pages', with per-node 'frames' carrying the layout positions) and no longer parses the old shape -- regenerate the dump with a current documents.js (e.g. re-run the conversion whose package dump produced it) and read that back instead");
356
+ if (isNamedError(error, "SchemaVersionMismatchError")) return errorResult(error.message);
357
+ if (isNamedError(error, "LayoutSchemaDemotedError")) return errorResult(error.message);
361
358
  if (error instanceof z.ZodError) return errorResult(`'source' failed ${documentSchemaKindOf(parsed) ?? "document schema"} validation: ${error.message}`);
362
359
  return errorResult(error instanceof Error ? error.message : String(error));
363
360
  }
@@ -790,7 +787,7 @@ function countImagesByFormat(images) {
790
787
  function registerPdfInspectTools(server) {
791
788
  server.registerTool("pdf_inspect", {
792
789
  title: "Inspect PDF",
793
- description: "Parses a PDF (documents.js's readPdf) and reports a summary: page count, each page's own size and item-kind histogram, document metadata, and embedded image formats. Pass full: true to return the entire parsed LayoutDocument (tagged with its own $schema) instead of a summary.",
790
+ description: "Parses a PDF (documents.js's readPdf) and reports a summary: page count, each page's own size and item-kind histogram, document metadata, and embedded image formats. Pass full: true to return the entire parsed LayoutDocument instead of a summary.",
794
791
  inputSchema: z.object({
795
792
  source: DocumentInputSchema.describe("The PDF document to inspect."),
796
793
  full: z.boolean().optional().describe("When true, return the entire parsed LayoutDocument instead of a summary. Defaults to false.")
@@ -800,16 +797,13 @@ function registerPdfInspectTools(server) {
800
797
  const { bytes, format } = await resolveDocumentInput(source, { signal });
801
798
  if (format !== "pdf") throw new Error(`pdf_inspect requires a PDF document, received a "${format}" document instead.`);
802
799
  const layout = readPdf(bytes, { signal });
803
- if (full === true) {
804
- const tagged = layoutDocumentWithSchema(layout);
805
- return {
806
- content: [{
807
- type: "text",
808
- text: JSON.stringify(tagged)
809
- }],
810
- structuredContent: tagged
811
- };
812
- }
800
+ if (full === true) return {
801
+ content: [{
802
+ type: "text",
803
+ text: JSON.stringify(layout)
804
+ }],
805
+ structuredContent: layout
806
+ };
813
807
  const summary = {
814
808
  pageCount: layout.pages.length,
815
809
  pages: layout.pages.map((page) => ({
package/dist/index.cjs CHANGED
@@ -6,7 +6,7 @@ let node_fs_promises = require("node:fs/promises");
6
6
  let node_fs = require("node:fs");
7
7
  let node_path = require("node:path");
8
8
  //#region package.json
9
- var version = "1.5.108";
9
+ var version = "2.0.0";
10
10
  //#endregion
11
11
  //#region src/io/document-input.ts
12
12
  const EXTENSION_TO_FORMAT = {
@@ -318,12 +318,8 @@ function errorResult(message) {
318
318
  isError: true
319
319
  };
320
320
  }
321
- function isRecord(value) {
322
- return typeof value === "object" && value !== null && !Array.isArray(value);
323
- }
324
- function isLegacyPackageDump(value) {
325
- if (!isRecord(value) || (0, documents_js.documentSchemaKindOf)(value) !== "DocumentPackage") return false;
326
- return value.formatVersion === 1 || "layout" in value && value.formatVersion !== 2;
321
+ function isNamedError(error, name) {
322
+ return error instanceof Error && error.name === name;
327
323
  }
328
324
  function registerFromPackageTools(server) {
329
325
  server.registerTool("from_package", {
@@ -356,7 +352,8 @@ function registerFromPackageTools(server) {
356
352
  };
357
353
  } catch (error) {
358
354
  if (error instanceof documents_js.UnrecognizedDocumentSchemaError) return errorResult("'source' has no recognised $schema -- only a file carrying a real DocumentPackage (e.g. written by a caller's own --dump-package-equivalent step) can be read back by this tool");
359
- if (error instanceof zod.z.ZodError && isLegacyPackageDump(parsed)) return errorResult("'source' is a DocumentPackage dump in the old formatVersion 1 shape: a 'layout' half beside 'content'. documents.js 2.0.0 fused the two into formatVersion 2 ('content' + 'pages', with per-node 'frames' carrying the layout positions) and no longer parses the old shape -- regenerate the dump with a current documents.js (e.g. re-run the conversion whose package dump produced it) and read that back instead");
355
+ if (isNamedError(error, "SchemaVersionMismatchError")) return errorResult(error.message);
356
+ if (isNamedError(error, "LayoutSchemaDemotedError")) return errorResult(error.message);
360
357
  if (error instanceof zod.z.ZodError) return errorResult(`'source' failed ${(0, documents_js.documentSchemaKindOf)(parsed) ?? "document schema"} validation: ${error.message}`);
361
358
  return errorResult(error instanceof Error ? error.message : String(error));
362
359
  }
@@ -789,7 +786,7 @@ function countImagesByFormat(images) {
789
786
  function registerPdfInspectTools(server) {
790
787
  server.registerTool("pdf_inspect", {
791
788
  title: "Inspect PDF",
792
- description: "Parses a PDF (documents.js's readPdf) and reports a summary: page count, each page's own size and item-kind histogram, document metadata, and embedded image formats. Pass full: true to return the entire parsed LayoutDocument (tagged with its own $schema) instead of a summary.",
789
+ description: "Parses a PDF (documents.js's readPdf) and reports a summary: page count, each page's own size and item-kind histogram, document metadata, and embedded image formats. Pass full: true to return the entire parsed LayoutDocument instead of a summary.",
793
790
  inputSchema: zod.z.object({
794
791
  source: DocumentInputSchema.describe("The PDF document to inspect."),
795
792
  full: zod.z.boolean().optional().describe("When true, return the entire parsed LayoutDocument instead of a summary. Defaults to false.")
@@ -799,16 +796,13 @@ function registerPdfInspectTools(server) {
799
796
  const { bytes, format } = await resolveDocumentInput(source, { signal });
800
797
  if (format !== "pdf") throw new Error(`pdf_inspect requires a PDF document, received a "${format}" document instead.`);
801
798
  const layout = (0, documents_js.readPdf)(bytes, { signal });
802
- if (full === true) {
803
- const tagged = (0, documents_js.layoutDocumentWithSchema)(layout);
804
- return {
805
- content: [{
806
- type: "text",
807
- text: JSON.stringify(tagged)
808
- }],
809
- structuredContent: tagged
810
- };
811
- }
799
+ if (full === true) return {
800
+ content: [{
801
+ type: "text",
802
+ text: JSON.stringify(layout)
803
+ }],
804
+ structuredContent: layout
805
+ };
812
806
  const summary = {
813
807
  pageCount: layout.pages.length,
814
808
  pages: layout.pages.map((page) => ({
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { McpServer } from "@modelcontextprotocol/server";
2
- import { DocumentFormatSchema, OdbReportNotSpecifiedError, OdmUnresolvedSectionError, UnrecognizedDocumentSchemaError, base64ToBytes, buildDocumentBytes, bytesToBase64, createLocalDocumentConverter, decodeOdbPackage, decodePackage, describeFontFace, documentFromJson, documentSchemaKindOf, evaluateSelect, extractSourceFontsForFormat, layoutDocumentWithSchema, odbReportToDocx, odbReportToOdt, odbReportToPdf, odbToCsv, odbToXlsx, odmToPdf, parseSelect, readDocumentMetadata, readDocxExtras, readOdbForms, readOdbInventory, readOdbReportContent, readOdbReports, readOdbTables, readPdf, setDocumentMetadata } from "documents.js";
2
+ import { DocumentFormatSchema, OdbReportNotSpecifiedError, OdmUnresolvedSectionError, UnrecognizedDocumentSchemaError, base64ToBytes, buildDocumentBytes, bytesToBase64, createLocalDocumentConverter, decodeOdbPackage, decodePackage, describeFontFace, documentFromJson, documentSchemaKindOf, evaluateSelect, extractSourceFontsForFormat, odbReportToDocx, odbReportToOdt, odbReportToPdf, odbToCsv, odbToXlsx, odmToPdf, parseSelect, readDocumentMetadata, readDocxExtras, readOdbForms, readOdbInventory, readOdbReportContent, readOdbReports, readOdbTables, readPdf, setDocumentMetadata } from "documents.js";
3
3
  import { z } from "zod";
4
4
  import { readFile, writeFile } from "node:fs/promises";
5
5
  import { existsSync, readFileSync } from "node:fs";
6
6
  import { basename, join } from "node:path";
7
7
  //#region package.json
8
- var version = "1.5.108";
8
+ var version = "2.0.0";
9
9
  //#endregion
10
10
  //#region src/io/document-input.ts
11
11
  const EXTENSION_TO_FORMAT = {
@@ -317,12 +317,8 @@ function errorResult(message) {
317
317
  isError: true
318
318
  };
319
319
  }
320
- function isRecord(value) {
321
- return typeof value === "object" && value !== null && !Array.isArray(value);
322
- }
323
- function isLegacyPackageDump(value) {
324
- if (!isRecord(value) || documentSchemaKindOf(value) !== "DocumentPackage") return false;
325
- return value.formatVersion === 1 || "layout" in value && value.formatVersion !== 2;
320
+ function isNamedError(error, name) {
321
+ return error instanceof Error && error.name === name;
326
322
  }
327
323
  function registerFromPackageTools(server) {
328
324
  server.registerTool("from_package", {
@@ -355,7 +351,8 @@ function registerFromPackageTools(server) {
355
351
  };
356
352
  } catch (error) {
357
353
  if (error instanceof UnrecognizedDocumentSchemaError) return errorResult("'source' has no recognised $schema -- only a file carrying a real DocumentPackage (e.g. written by a caller's own --dump-package-equivalent step) can be read back by this tool");
358
- if (error instanceof z.ZodError && isLegacyPackageDump(parsed)) return errorResult("'source' is a DocumentPackage dump in the old formatVersion 1 shape: a 'layout' half beside 'content'. documents.js 2.0.0 fused the two into formatVersion 2 ('content' + 'pages', with per-node 'frames' carrying the layout positions) and no longer parses the old shape -- regenerate the dump with a current documents.js (e.g. re-run the conversion whose package dump produced it) and read that back instead");
354
+ if (isNamedError(error, "SchemaVersionMismatchError")) return errorResult(error.message);
355
+ if (isNamedError(error, "LayoutSchemaDemotedError")) return errorResult(error.message);
359
356
  if (error instanceof z.ZodError) return errorResult(`'source' failed ${documentSchemaKindOf(parsed) ?? "document schema"} validation: ${error.message}`);
360
357
  return errorResult(error instanceof Error ? error.message : String(error));
361
358
  }
@@ -788,7 +785,7 @@ function countImagesByFormat(images) {
788
785
  function registerPdfInspectTools(server) {
789
786
  server.registerTool("pdf_inspect", {
790
787
  title: "Inspect PDF",
791
- description: "Parses a PDF (documents.js's readPdf) and reports a summary: page count, each page's own size and item-kind histogram, document metadata, and embedded image formats. Pass full: true to return the entire parsed LayoutDocument (tagged with its own $schema) instead of a summary.",
788
+ description: "Parses a PDF (documents.js's readPdf) and reports a summary: page count, each page's own size and item-kind histogram, document metadata, and embedded image formats. Pass full: true to return the entire parsed LayoutDocument instead of a summary.",
792
789
  inputSchema: z.object({
793
790
  source: DocumentInputSchema.describe("The PDF document to inspect."),
794
791
  full: z.boolean().optional().describe("When true, return the entire parsed LayoutDocument instead of a summary. Defaults to false.")
@@ -798,16 +795,13 @@ function registerPdfInspectTools(server) {
798
795
  const { bytes, format } = await resolveDocumentInput(source, { signal });
799
796
  if (format !== "pdf") throw new Error(`pdf_inspect requires a PDF document, received a "${format}" document instead.`);
800
797
  const layout = readPdf(bytes, { signal });
801
- if (full === true) {
802
- const tagged = layoutDocumentWithSchema(layout);
803
- return {
804
- content: [{
805
- type: "text",
806
- text: JSON.stringify(tagged)
807
- }],
808
- structuredContent: tagged
809
- };
810
- }
798
+ if (full === true) return {
799
+ content: [{
800
+ type: "text",
801
+ text: JSON.stringify(layout)
802
+ }],
803
+ structuredContent: layout
804
+ };
811
805
  const summary = {
812
806
  pageCount: layout.pages.length,
813
807
  pages: layout.pages.map((page) => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-mcp",
3
- "version": "1.5.108",
3
+ "version": "2.0.0",
4
4
  "description": "MCP (Model Context Protocol) server exposing documents.js's document-conversion, .odb, metadata, and font tooling as MCP tools.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -85,7 +85,7 @@
85
85
  "packageManager": "pnpm@11.6.0",
86
86
  "dependencies": {
87
87
  "@modelcontextprotocol/server": "^2.0.0",
88
- "documents.js": "^2.3.2",
88
+ "documents.js": "^3.0.1",
89
89
  "zod": "^4.2.0"
90
90
  },
91
91
  "devDependencies": {