@shuji-bonji/pdf-writer-mcp 0.6.0 → 0.7.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/CHANGELOG.md +43 -0
- package/dist/config.d.ts +12 -0
- package/dist/config.js +21 -0
- package/dist/config.js.map +1 -1
- package/dist/constants.d.ts +5 -0
- package/dist/constants.js +5 -0
- package/dist/constants.js.map +1 -1
- package/dist/errors.d.ts +64 -0
- package/dist/errors.js +76 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +9 -35
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +6 -0
- package/dist/server.js +45 -0
- package/dist/server.js.map +1 -0
- package/dist/services/builder.js +2 -1
- package/dist/services/builder.js.map +1 -1
- package/dist/services/editor.d.ts +11 -8
- package/dist/services/editor.js +33 -135
- package/dist/services/editor.js.map +1 -1
- package/dist/services/font-manager.js +8 -9
- package/dist/services/font-manager.js.map +1 -1
- package/dist/services/output.js +5 -4
- package/dist/services/output.js.map +1 -1
- package/dist/services/page-ops.d.ts +15 -0
- package/dist/services/page-ops.js +136 -0
- package/dist/services/page-ops.js.map +1 -0
- package/dist/services/renderers/text.js +2 -3
- package/dist/services/renderers/text.js.map +1 -1
- package/dist/services/xmp.js +5 -2
- package/dist/services/xmp.js.map +1 -1
- package/dist/tools/definitions.d.ts +25 -797
- package/dist/tools/definitions.js +67 -427
- package/dist/tools/definitions.js.map +1 -1
- package/dist/tools/handlers.d.ts +6 -3
- package/dist/tools/handlers.js +49 -45
- package/dist/tools/handlers.js.map +1 -1
- package/dist/utils/page-spec.js +6 -5
- package/dist/utils/page-spec.js.map +1 -1
- package/dist/utils/stdout-guard.d.ts +12 -0
- package/dist/utils/stdout-guard.js +16 -0
- package/dist/utils/stdout-guard.js.map +1 -0
- package/dist/utils/validation.d.ts +515 -27
- package/dist/utils/validation.js +387 -391
- package/dist/utils/validation.js.map +1 -1
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,49 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.7.0] - 2026-07-17
|
|
6
|
+
|
|
7
|
+
コードレビュー(2026-07-17)と TASKS.md E 系(コード衛生・family 整合)への
|
|
8
|
+
一括対応。**ツール名・必須フィールド・成功時の出力形式は不変**。エラー応答の
|
|
9
|
+
形式のみ family 契約に揃えて変わった(minor バンプの理由)。
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- **McpServer + Zod へ移行(E-5)** — 低レベル `Server` + 手書き JSON Schema
|
|
14
|
+
(definitions.ts 553 行)+ asserts 検査(validation.ts 502 行)の二重管理を解消。
|
|
15
|
+
Zod スキーマ(validation.ts)が公開スキーマと実行時検証の単一情報源になった。
|
|
16
|
+
reader / verify と同じ `registerTool` パターン。`server.ts` の `buildServer()`
|
|
17
|
+
はテストから `InMemoryTransport` で検証され、`registry.test.ts` が 17 ツールの
|
|
18
|
+
名前・必須フィールド・annotations を外部仕様スナップショットとして固定する。
|
|
19
|
+
- **構造化エラー(E-2)** — `{error: message}` から reader v0.6.0 と同じ
|
|
20
|
+
`code` / `hint` / `next_actions` / `retryable` 形式へ。writer 固有のガードは
|
|
21
|
+
すべて「解除フラグ付きで再試行可能」として表現される:
|
|
22
|
+
`SIGNED_PDF` (allowBreakingSignatures) / `TAGGED_PDF` (allowBreakingTags) /
|
|
23
|
+
`FONT_REQUIRED` (fontPath) / `MISSING_GLYPH` (onMissingGlyph)。ほかに
|
|
24
|
+
`DOC_NOT_FOUND` / `FILE_TOO_LARGE` / `ENCRYPTED_PDF` / `INVALID_PDF` /
|
|
25
|
+
`UNSUPPORTED_PDF_FEATURE` (XFA) / `FONT_NOT_FOUND` / `INVALID_ARGUMENT`。
|
|
26
|
+
- **ページ操作を page-ops.ts へ分離** — merge / split / extract / delete /
|
|
27
|
+
reorder / rotate を editor.ts(20.6kB → 16.1kB)から切り出し。mergePdfs が
|
|
28
|
+
文書情報の引き継ぎのために先頭ファイルを二重読込していた無駄も解消。
|
|
29
|
+
|
|
30
|
+
### Added
|
|
31
|
+
|
|
32
|
+
- **パス検査の強化(E-1)** — すべてのパス引数(inputPath / inputPaths[] /
|
|
33
|
+
outputPath / outputDir / fontPath / attachmentPath)に絶対パスを強制し、
|
|
34
|
+
`..` セグメントを拒否。入力 PDF に 100MB のサイズ上限を新設
|
|
35
|
+
(verify の `MAX_FILE_SIZE` と同水準)。
|
|
36
|
+
- **stdout ガード(E-3)** — `marked` / `subset-font` 等の依存が `console.log`
|
|
37
|
+
を吐いても stdio の JSON-RPC を汚染しないよう、side-effect-first の
|
|
38
|
+
`stdout-guard.ts` を導入(reader / verify と同パターン)。
|
|
39
|
+
- **tool annotations(E-4)** — 全 17 ツールに `readOnlyHint` /
|
|
40
|
+
`destructiveHint` / `idempotentHint` / `openWorldHint` を付与。
|
|
41
|
+
`destructiveHint: true` は情報が失われる `delete_pages` と `flatten_form` のみ。
|
|
42
|
+
- **決定論的出力(E-6)** — 環境変数 `SOURCE_DATE_EPOCH`(UNIX 秒、
|
|
43
|
+
reproducible-builds.org の慣習)設定時に CreationDate / ModificationDate /
|
|
44
|
+
XMP の日時を固定し、同一入力 → 同一バイト列を保証。学習データ工場の
|
|
45
|
+
差分検証・キャッシュ・再現テスト用。不正値は黙殺せずエラー。
|
|
46
|
+
- 依存に `zod ^4.4.3` を追加。
|
|
47
|
+
|
|
5
48
|
## [0.6.0] - 2026-07-16
|
|
6
49
|
|
|
7
50
|
### Added
|
package/dist/config.d.ts
CHANGED
|
@@ -15,7 +15,19 @@ export declare const PACKAGE_INFO: {
|
|
|
15
15
|
export declare const ENV_KEYS: {
|
|
16
16
|
/** デフォルトで埋め込むフォントファイルのパス(.ttf / .otf) */
|
|
17
17
|
readonly DEFAULT_FONT: 'PDF_WRITER_FONT';
|
|
18
|
+
/**
|
|
19
|
+
* 決定論的出力(E-6): reproducible-builds.org の慣習に従う UNIX 秒。
|
|
20
|
+
* 設定時は CreationDate / ModificationDate / XMP の各日時に固定値を使い、
|
|
21
|
+
* 同一入力 → 同一バイト列を保証する(学習データ工場の差分検証・キャッシュ用)。
|
|
22
|
+
*/
|
|
23
|
+
readonly SOURCE_DATE_EPOCH: 'SOURCE_DATE_EPOCH';
|
|
18
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* 出力に焼き込む「現在時刻」。SOURCE_DATE_EPOCH が設定されていれば固定値を返す。
|
|
27
|
+
* 値が不正(数値でない・負)な場合は黙って現在時刻に落とさずエラーにする —
|
|
28
|
+
* 再現性を期待した呼び出し側が黙って非決定的な出力を得るのが最悪のケースのため。
|
|
29
|
+
*/
|
|
30
|
+
export declare function outputDate(): Date;
|
|
19
31
|
/**
|
|
20
32
|
* PDF 生成のデフォルト値
|
|
21
33
|
* 単位はすべて pt(1pt = 1/72 inch)
|
package/dist/config.js
CHANGED
|
@@ -18,7 +18,28 @@ export const PACKAGE_INFO = {
|
|
|
18
18
|
export const ENV_KEYS = {
|
|
19
19
|
/** デフォルトで埋め込むフォントファイルのパス(.ttf / .otf) */
|
|
20
20
|
DEFAULT_FONT: 'PDF_WRITER_FONT',
|
|
21
|
+
/**
|
|
22
|
+
* 決定論的出力(E-6): reproducible-builds.org の慣習に従う UNIX 秒。
|
|
23
|
+
* 設定時は CreationDate / ModificationDate / XMP の各日時に固定値を使い、
|
|
24
|
+
* 同一入力 → 同一バイト列を保証する(学習データ工場の差分検証・キャッシュ用)。
|
|
25
|
+
*/
|
|
26
|
+
SOURCE_DATE_EPOCH: 'SOURCE_DATE_EPOCH',
|
|
21
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* 出力に焼き込む「現在時刻」。SOURCE_DATE_EPOCH が設定されていれば固定値を返す。
|
|
30
|
+
* 値が不正(数値でない・負)な場合は黙って現在時刻に落とさずエラーにする —
|
|
31
|
+
* 再現性を期待した呼び出し側が黙って非決定的な出力を得るのが最悪のケースのため。
|
|
32
|
+
*/
|
|
33
|
+
export function outputDate() {
|
|
34
|
+
const raw = process.env[ENV_KEYS.SOURCE_DATE_EPOCH];
|
|
35
|
+
if (raw === undefined || raw === '')
|
|
36
|
+
return new Date();
|
|
37
|
+
const epoch = Number(raw);
|
|
38
|
+
if (!Number.isFinite(epoch) || epoch < 0) {
|
|
39
|
+
throw new Error(`${ENV_KEYS.SOURCE_DATE_EPOCH} must be a non-negative number of seconds, got "${raw}"`);
|
|
40
|
+
}
|
|
41
|
+
return new Date(epoch * 1000);
|
|
42
|
+
}
|
|
22
43
|
/**
|
|
23
44
|
* PDF 生成のデフォルト値
|
|
24
45
|
* 単位はすべて pt(1pt = 1/72 inch)
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAG5C,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,WAAW,CAAC,IAAI;IACtB,OAAO,EAAE,WAAW,CAAC,OAAO;CACpB,CAAC;AAEX;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,yCAAyC;IACzC,YAAY,EAAE,iBAAiB;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAG5C,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,WAAW,CAAC,IAAI;IACtB,OAAO,EAAE,WAAW,CAAC,OAAO;CACpB,CAAC;AAEX;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,yCAAyC;IACzC,YAAY,EAAE,iBAAiB;IAC/B;;;;OAIG;IACH,iBAAiB,EAAE,mBAAmB;CAC9B,CAAC;AAEX;;;;GAIG;AACH,MAAM,UAAU,UAAU;IACxB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IACpD,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,EAAE;QAAE,OAAO,IAAI,IAAI,EAAE,CAAC;IACvD,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,KAAK,CACb,GAAG,QAAQ,CAAC,iBAAiB,mDAAmD,GAAG,GAAG,CACvF,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;AAChC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,cAAc;IACd,QAAQ,EAAE,IAAI;IACd,eAAe;IACf,MAAM,EAAE,EAAE,EAAE,SAAS;IACrB,gBAAgB;IAChB,QAAQ,EAAE,EAAE;IACZ,wDAAwD;IACxD,UAAU,EAAE,IAAI;IAChB,eAAe;IACf,YAAY,EAAE,CAAC;CACP,CAAC"}
|
package/dist/constants.d.ts
CHANGED
|
@@ -38,6 +38,11 @@ export declare const LIMITS: {
|
|
|
38
38
|
readonly BOOKMARK_MAX_DEPTH: 8;
|
|
39
39
|
/** 埋め込みファイルの最大サイズ(バイト)。PDF 全体がメモリに載るため上限を設ける */
|
|
40
40
|
readonly ATTACHMENT_MAX_BYTES: number;
|
|
41
|
+
/**
|
|
42
|
+
* 入力 PDF の最大サイズ(バイト)。pdf-lib は全体をメモリに載せるため、
|
|
43
|
+
* verify(MAX_FILE_SIZE = 100MB)と同水準の上限を設ける。
|
|
44
|
+
*/
|
|
45
|
+
readonly INPUT_PDF_MAX_BYTES: number;
|
|
41
46
|
};
|
|
42
47
|
/** stamp_page_numbers の配置 */
|
|
43
48
|
export declare const STAMP_POSITIONS: readonly ['bottom-left', 'bottom-center', 'bottom-right', 'top-left', 'top-center', 'top-right'];
|
package/dist/constants.js
CHANGED
|
@@ -37,6 +37,11 @@ export const LIMITS = {
|
|
|
37
37
|
BOOKMARK_MAX_DEPTH: 8,
|
|
38
38
|
/** 埋め込みファイルの最大サイズ(バイト)。PDF 全体がメモリに載るため上限を設ける */
|
|
39
39
|
ATTACHMENT_MAX_BYTES: 100 * 1024 * 1024,
|
|
40
|
+
/**
|
|
41
|
+
* 入力 PDF の最大サイズ(バイト)。pdf-lib は全体をメモリに載せるため、
|
|
42
|
+
* verify(MAX_FILE_SIZE = 100MB)と同水準の上限を設ける。
|
|
43
|
+
*/
|
|
44
|
+
INPUT_PDF_MAX_BYTES: 100 * 1024 * 1024,
|
|
40
45
|
};
|
|
41
46
|
/** stamp_page_numbers の配置 */
|
|
42
47
|
export const STAMP_POSITIONS = [
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;IACpB,EAAE,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;IACrB,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,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AAG,CAAU,CAAC;AAEvD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,eAAe,CAAC;AAExD;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,mCAAmC;IACnC,GAAG,EAAE,MAAM;CACH,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* family-compatible 構造化エラー応答(E-2) — pdf-writer-mcp 実装
|
|
3
|
+
*
|
|
4
|
+
* 設計指針:
|
|
5
|
+
* - pdf-reader-mcp v0.6.0 の error contract に準拠(`code` 文字列を共有)
|
|
6
|
+
* - 共通パッケージ依存を持たない独立実装
|
|
7
|
+
* - writer 固有のコード(SIGNED_PDF / TAGGED_PDF / FONT_REQUIRED /
|
|
8
|
+
* MISSING_GLYPH)を追加。いずれも「明示フラグや引数の追加で再試行できる」
|
|
9
|
+
* ガード系で、`retryable: true` + `next_actions` により出力パイプライン
|
|
10
|
+
* Skill / LLM エージェントが自律的に分岐できる。
|
|
11
|
+
*
|
|
12
|
+
* family contract 仕様:
|
|
13
|
+
* @see https://github.com/shuji-bonji/houki-research-skill/blob/main/docs/ERROR-CODES.md
|
|
14
|
+
*/
|
|
15
|
+
/** family 共通コードの部分集合 + writer 固有拡張 */
|
|
16
|
+
export type WriterErrorCode = 'INVALID_ARGUMENT' | 'DOC_NOT_FOUND' | 'FONT_NOT_FOUND' | 'INVALID_PDF' | 'ENCRYPTED_PDF' | 'UNSUPPORTED_PDF_FEATURE' | 'FILE_TOO_LARGE' | 'SIGNED_PDF' | 'TAGGED_PDF' | 'FONT_REQUIRED' | 'MISSING_GLYPH' | 'INTERNAL_ERROR';
|
|
17
|
+
/** 次に取るべきアクションの提案。LLM が読んで自律的に再試行することを想定 */
|
|
18
|
+
export interface NextAction {
|
|
19
|
+
/** 推奨アクション(tool 名 or 自然言語) */
|
|
20
|
+
action: string;
|
|
21
|
+
/** どんなときに有効か */
|
|
22
|
+
reason: string;
|
|
23
|
+
/** 具体的な引数例(任意) */
|
|
24
|
+
example?: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
/** family-compatible 共通エラー応答 */
|
|
27
|
+
export interface WriterServiceError {
|
|
28
|
+
/** 1文の人間可読メッセージ(LLM もここを読む) */
|
|
29
|
+
error: string;
|
|
30
|
+
/** プログラム判定用の安定したコード */
|
|
31
|
+
code: WriterErrorCode;
|
|
32
|
+
/** 追加情報(任意) */
|
|
33
|
+
hint?: string;
|
|
34
|
+
/** LLM が次に取るべき手段の候補 */
|
|
35
|
+
next_actions?: NextAction[];
|
|
36
|
+
/** フラグや引数を変えれば再試行できるか */
|
|
37
|
+
retryable?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** コード・ヒント・next_actions を運ぶ writer 固有の Error */
|
|
40
|
+
export declare class PdfWriterError extends Error {
|
|
41
|
+
readonly code: WriterErrorCode;
|
|
42
|
+
readonly options: {
|
|
43
|
+
hint?: string;
|
|
44
|
+
next_actions?: NextAction[];
|
|
45
|
+
retryable?: boolean;
|
|
46
|
+
};
|
|
47
|
+
constructor(message: string, code: WriterErrorCode, options?: {
|
|
48
|
+
hint?: string;
|
|
49
|
+
next_actions?: NextAction[];
|
|
50
|
+
retryable?: boolean;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** 引数エラーの短縮形(validation.ts / page-spec.ts の大量の検査で使う) */
|
|
54
|
+
export declare function invalidArg(message: string): PdfWriterError;
|
|
55
|
+
/** 投げられた値を family 形式のエラー応答へ変換する */
|
|
56
|
+
export declare function toStructuredError(error: unknown): WriterServiceError;
|
|
57
|
+
/** よく使う next_actions のプリセット(writer のガード解除フラグ群) */
|
|
58
|
+
export declare const NEXT_ACTIONS: {
|
|
59
|
+
readonly allowBreakingSignatures: () => NextAction;
|
|
60
|
+
readonly allowBreakingTags: () => NextAction;
|
|
61
|
+
readonly provideFontPath: () => NextAction;
|
|
62
|
+
readonly changeMissingGlyphPolicy: () => NextAction;
|
|
63
|
+
readonly checkFilePath: (path?: string) => NextAction;
|
|
64
|
+
};
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* family-compatible 構造化エラー応答(E-2) — pdf-writer-mcp 実装
|
|
3
|
+
*
|
|
4
|
+
* 設計指針:
|
|
5
|
+
* - pdf-reader-mcp v0.6.0 の error contract に準拠(`code` 文字列を共有)
|
|
6
|
+
* - 共通パッケージ依存を持たない独立実装
|
|
7
|
+
* - writer 固有のコード(SIGNED_PDF / TAGGED_PDF / FONT_REQUIRED /
|
|
8
|
+
* MISSING_GLYPH)を追加。いずれも「明示フラグや引数の追加で再試行できる」
|
|
9
|
+
* ガード系で、`retryable: true` + `next_actions` により出力パイプライン
|
|
10
|
+
* Skill / LLM エージェントが自律的に分岐できる。
|
|
11
|
+
*
|
|
12
|
+
* family contract 仕様:
|
|
13
|
+
* @see https://github.com/shuji-bonji/houki-research-skill/blob/main/docs/ERROR-CODES.md
|
|
14
|
+
*/
|
|
15
|
+
/** コード・ヒント・next_actions を運ぶ writer 固有の Error */
|
|
16
|
+
export class PdfWriterError extends Error {
|
|
17
|
+
code;
|
|
18
|
+
options;
|
|
19
|
+
constructor(message, code, options = {}) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.code = code;
|
|
22
|
+
this.options = options;
|
|
23
|
+
this.name = 'PdfWriterError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** 引数エラーの短縮形(validation.ts / page-spec.ts の大量の検査で使う) */
|
|
27
|
+
export function invalidArg(message) {
|
|
28
|
+
return new PdfWriterError(message, 'INVALID_ARGUMENT');
|
|
29
|
+
}
|
|
30
|
+
/** 投げられた値を family 形式のエラー応答へ変換する */
|
|
31
|
+
export function toStructuredError(error) {
|
|
32
|
+
if (error instanceof PdfWriterError) {
|
|
33
|
+
const out = { error: error.message, code: error.code };
|
|
34
|
+
if (error.options.hint)
|
|
35
|
+
out.hint = error.options.hint;
|
|
36
|
+
if (error.options.next_actions && error.options.next_actions.length > 0) {
|
|
37
|
+
out.next_actions = error.options.next_actions;
|
|
38
|
+
}
|
|
39
|
+
if (error.options.retryable !== undefined)
|
|
40
|
+
out.retryable = error.options.retryable;
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
if (error instanceof Error) {
|
|
44
|
+
return { error: error.message, code: 'INTERNAL_ERROR' };
|
|
45
|
+
}
|
|
46
|
+
return { error: String(error), code: 'INTERNAL_ERROR' };
|
|
47
|
+
}
|
|
48
|
+
/** よく使う next_actions のプリセット(writer のガード解除フラグ群) */
|
|
49
|
+
export const NEXT_ACTIONS = {
|
|
50
|
+
allowBreakingSignatures: () => ({
|
|
51
|
+
action: 'retry_with_allowBreakingSignatures',
|
|
52
|
+
reason: '署名を無効化してよい場合のみ、同じ引数に "allowBreakingSignatures": true を足して再試行してください',
|
|
53
|
+
example: { allowBreakingSignatures: true },
|
|
54
|
+
}),
|
|
55
|
+
allowBreakingTags: () => ({
|
|
56
|
+
action: 'retry_with_allowBreakingTags',
|
|
57
|
+
reason: 'PDF/UA 適合を壊してよい場合のみ、"allowBreakingTags": true を足して再試行してください',
|
|
58
|
+
example: { allowBreakingTags: true },
|
|
59
|
+
}),
|
|
60
|
+
provideFontPath: () => ({
|
|
61
|
+
action: 'retry_with_fontPath',
|
|
62
|
+
reason: '非 Latin 文字(日本語等)には埋め込みフォントが必要です。"fontPath" に .ttf/.otf を指定するか、環境変数 PDF_WRITER_FONT を設定してください',
|
|
63
|
+
example: { fontPath: '/path/to/NotoSansJP-Regular.otf' },
|
|
64
|
+
}),
|
|
65
|
+
changeMissingGlyphPolicy: () => ({
|
|
66
|
+
action: 'retry_with_onMissingGlyph',
|
|
67
|
+
reason: 'フォントに無い文字が本文に含まれます。別のフォントを指定するか、"onMissingGlyph": "replace"(豆腐で置換)/ "ignore"(黙って除去)を指定してください',
|
|
68
|
+
example: { onMissingGlyph: 'replace' },
|
|
69
|
+
}),
|
|
70
|
+
checkFilePath: (path) => ({
|
|
71
|
+
action: 'verify_file_path',
|
|
72
|
+
reason: 'ファイルパスが正しいか、絶対パスで指定されているか確認してください',
|
|
73
|
+
example: path ? { inputPath: path } : undefined,
|
|
74
|
+
}),
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AA8CH,gDAAgD;AAChD,MAAM,OAAO,cAAe,SAAQ,KAAK;IAGrB,IAAI;IACJ,OAAO;IAHzB,YACE,OAAe,EACC,IAAqB,EACrB,OAAO,GAInB,EAAE;QAEN,KAAK,CAAC,OAAO,CAAC,CAAC;oBAPC,IAAI;uBACJ,OAAO;QAOvB,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED,wDAAwD;AACxD,MAAM,UAAU,UAAU,CAAC,OAAe;IACxC,OAAO,IAAI,cAAc,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;AACzD,CAAC;AAED,mCAAmC;AACnC,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC9C,IAAI,KAAK,YAAY,cAAc,EAAE,CAAC;QACpC,MAAM,GAAG,GAAuB,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;QAC3E,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI;YAAE,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QACtD,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxE,GAAG,CAAC,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC;QAChD,CAAC;QACD,IAAI,KAAK,CAAC,OAAO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IAAI,EAAE,CAAC,CAAC,CAAC,SAAS;KAChD,CAAC;CACM,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
3
|
* pdf-writer-mcp — MCP server entry
|
|
4
|
-
* テキスト / Markdown / 表データから PDF
|
|
4
|
+
* テキスト / Markdown / 表データから PDF を生成し、既存 PDF を編集する。
|
|
5
|
+
*
|
|
6
|
+
* E-5: reader / verify と同じ McpServer + registerTool + Zod 構成。
|
|
7
|
+
* ツール定義(説明・スキーマ・annotations)は tools/definitions.ts の
|
|
8
|
+
* レジストリ、実装は tools/handlers.ts、スキーマは utils/validation.ts。
|
|
5
9
|
*/
|
|
6
|
-
|
|
10
|
+
import './utils/stdout-guard.js';
|
package/dist/index.js
CHANGED
|
@@ -1,46 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
3
|
* pdf-writer-mcp — MCP server entry
|
|
4
|
-
* テキスト / Markdown / 表データから PDF
|
|
4
|
+
* テキスト / Markdown / 表データから PDF を生成し、既存 PDF を編集する。
|
|
5
|
+
*
|
|
6
|
+
* E-5: reader / verify と同じ McpServer + registerTool + Zod 構成。
|
|
7
|
+
* ツール定義(説明・スキーマ・annotations)は tools/definitions.ts の
|
|
8
|
+
* レジストリ、実装は tools/handlers.ts、スキーマは utils/validation.ts。
|
|
5
9
|
*/
|
|
6
|
-
|
|
10
|
+
// stdout ガードは他のあらゆる import より先(side-effect first)
|
|
11
|
+
import './utils/stdout-guard.js';
|
|
7
12
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
8
|
-
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
9
13
|
import { PACKAGE_INFO } from './config.js';
|
|
10
|
-
import {
|
|
11
|
-
import { toolHandlers } from './tools/handlers.js';
|
|
14
|
+
import { buildServer } from './server.js';
|
|
12
15
|
import { logger } from './utils/logger.js';
|
|
13
|
-
const server = new Server({
|
|
14
|
-
name: PACKAGE_INFO.name,
|
|
15
|
-
version: PACKAGE_INFO.version,
|
|
16
|
-
}, {
|
|
17
|
-
capabilities: { tools: {} },
|
|
18
|
-
});
|
|
19
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
20
|
-
tools,
|
|
21
|
-
}));
|
|
22
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
23
|
-
const { name, arguments: args } = request.params;
|
|
24
|
-
try {
|
|
25
|
-
const handler = toolHandlers[name];
|
|
26
|
-
if (!handler) {
|
|
27
|
-
throw new Error(`Unknown tool: ${name}`);
|
|
28
|
-
}
|
|
29
|
-
const result = await handler(args);
|
|
30
|
-
return {
|
|
31
|
-
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
36
|
-
logger.error(name, message, error instanceof Error ? error : undefined);
|
|
37
|
-
return {
|
|
38
|
-
content: [{ type: 'text', text: JSON.stringify({ error: message }, null, 2) }],
|
|
39
|
-
isError: true,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
16
|
async function main() {
|
|
17
|
+
const server = buildServer();
|
|
44
18
|
const transport = new StdioServerTransport();
|
|
45
19
|
await server.connect(transport);
|
|
46
20
|
logger.info(PACKAGE_INFO.name, `v${PACKAGE_INFO.version} started (stdio)`);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;GAOG;AAEH,kDAAkD;AAClD,OAAO,yBAAyB,CAAC;AAEjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,YAAY,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAC7E,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,wBAAwB,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAC9F,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/server.d.ts
ADDED
package/dist/server.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* McpServer の構築(E-5)。
|
|
3
|
+
* index.ts(stdio 接続)とテスト(InMemoryTransport)の両方から使う。
|
|
4
|
+
*/
|
|
5
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
6
|
+
import { PACKAGE_INFO } from './config.js';
|
|
7
|
+
import { toStructuredError } from './errors.js';
|
|
8
|
+
import { tools } from './tools/definitions.js';
|
|
9
|
+
import { toolHandlers } from './tools/handlers.js';
|
|
10
|
+
import { logger } from './utils/logger.js';
|
|
11
|
+
export function buildServer() {
|
|
12
|
+
const server = new McpServer({
|
|
13
|
+
name: PACKAGE_INFO.name,
|
|
14
|
+
version: PACKAGE_INFO.version,
|
|
15
|
+
});
|
|
16
|
+
for (const tool of tools) {
|
|
17
|
+
const handler = toolHandlers[tool.name];
|
|
18
|
+
if (!handler) {
|
|
19
|
+
throw new Error(`No handler registered for tool: ${tool.name}`);
|
|
20
|
+
}
|
|
21
|
+
server.registerTool(tool.name, {
|
|
22
|
+
title: tool.title,
|
|
23
|
+
description: tool.description,
|
|
24
|
+
inputSchema: tool.shape,
|
|
25
|
+
annotations: tool.annotations,
|
|
26
|
+
}, async (args) => {
|
|
27
|
+
try {
|
|
28
|
+
const result = await handler(args);
|
|
29
|
+
return {
|
|
30
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
const structured = toStructuredError(error);
|
|
35
|
+
logger.error(tool.name, structured.error, error instanceof Error ? error : undefined);
|
|
36
|
+
return {
|
|
37
|
+
content: [{ type: 'text', text: JSON.stringify(structured, null, 2) }],
|
|
38
|
+
isError: true,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return server;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,MAAM,UAAU,WAAW;IACzB,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;QAC3B,IAAI,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;iBACd,CAAC;YACJ,CAAC;QACH,CAAC,CACF,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/services/builder.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { PDFDocument, rgb } from 'pdf-lib';
|
|
10
10
|
import { DEFAULTS } from '../config.js';
|
|
11
11
|
import { PAGE_SIZES, RENDERER_GENERATED_CHARS } from '../constants.js';
|
|
12
|
+
import { invalidArg } from '../errors.js';
|
|
12
13
|
import { inferLang } from '../utils/lang.js';
|
|
13
14
|
import { applyMissingGlyphPolicy, embedFontFor, openFont, } from './font-manager.js';
|
|
14
15
|
import { LayoutEngine } from './layout.js';
|
|
@@ -43,7 +44,7 @@ export async function buildPdf(opts, inputTexts, render) {
|
|
|
43
44
|
let lang;
|
|
44
45
|
if (opts.tagged) {
|
|
45
46
|
if (!title) {
|
|
46
|
-
throw
|
|
47
|
+
throw invalidArg('tagged: true requires "title" — PDF/UA (ISO 14289-1, 7.1) mandates a document title.');
|
|
47
48
|
}
|
|
48
49
|
lang = opts.lang;
|
|
49
50
|
if (!lang) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../../src/services/builder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,UAAU,EAAqB,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../../src/services/builder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,UAAU,EAAqB,wBA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
|
1
1
|
/**
|
|
2
2
|
* Editor
|
|
3
|
-
* 既存 PDF
|
|
3
|
+
* 既存 PDF の編集の共通基盤(loadForEdit / saveEdited)と、ページ操作以外の
|
|
4
|
+
* 編集ツール(メタデータ・しおり・注釈・添付・スタンプ・透かし・フォーム)。
|
|
5
|
+
* ページ単位の操作(merge / split / extract / delete / reorder / rotate)は
|
|
6
|
+
* page-ops.ts に分離した。
|
|
4
7
|
*
|
|
5
8
|
* create 系(builder → font → layout → renderer)とはフローが異なり、
|
|
6
9
|
* 読込(loadForEdit: 署名ガード込み)→ 操作 → 保存(saveEdited)
|
|
@@ -12,15 +15,16 @@
|
|
|
12
15
|
* allowBreakingSignatures: true があるときのみ続行する。
|
|
13
16
|
* 署名を保持する増分更新(incremental_save)は Tier C の課題。
|
|
14
17
|
*/
|
|
15
|
-
import
|
|
18
|
+
import { PDFDocument } from 'pdf-lib';
|
|
19
|
+
import type { AddAnnotationArgs, AddBookmarksArgs, AddWatermarkArgs, AttachFileArgs, AttachResult, CommonEditOptions, EditResult, FillFormArgs, FlattenFormArgs, FormResult, SetMetadataArgs, StampPageNumbersArgs, StampResult, WatermarkResult } from '../types/index.js';
|
|
16
20
|
/** 入力バイト列に電子署名(/ByteRange)が含まれるかの軽量検査 */
|
|
17
21
|
export declare function containsSignature(bytes: Uint8Array): boolean;
|
|
22
|
+
/** PDF を読み込み、署名ガード・サイズ上限を通す(page-ops.ts と共用) */
|
|
23
|
+
export declare function loadForEdit(filePath: string, opts: CommonEditOptions): Promise<{
|
|
24
|
+
doc: PDFDocument;
|
|
25
|
+
absPath: string;
|
|
26
|
+
}>;
|
|
18
27
|
export declare function setMetadata(args: SetMetadataArgs): Promise<EditResult>;
|
|
19
|
-
export declare function mergePdfs(inputPaths: string[], opts: CommonEditOptions): Promise<EditResult>;
|
|
20
|
-
export declare function extractPages(inputPath: string, pages: string, opts: CommonEditOptions): Promise<EditResult>;
|
|
21
|
-
export declare function deletePages(inputPath: string, pages: string, opts: CommonEditOptions): Promise<EditResult>;
|
|
22
|
-
export declare function reorderPages(inputPath: string, order: number[], opts: CommonEditOptions): Promise<EditResult>;
|
|
23
|
-
export declare function rotatePages(inputPath: string, rotation: number, pages: string | undefined, opts: CommonEditOptions): Promise<EditResult>;
|
|
24
28
|
export declare function addBookmarks(args: AddBookmarksArgs): Promise<EditResult>;
|
|
25
29
|
export declare function addAnnotation(args: AddAnnotationArgs): Promise<EditResult>;
|
|
26
30
|
export declare function attachFileToPdf(args: AttachFileArgs): Promise<AttachResult>;
|
|
@@ -28,4 +32,3 @@ export declare function stampPageNumbers(args: StampPageNumbersArgs): Promise<St
|
|
|
28
32
|
export declare function addWatermark(args: AddWatermarkArgs): Promise<WatermarkResult>;
|
|
29
33
|
export declare function fillForm(args: FillFormArgs): Promise<FormResult>;
|
|
30
34
|
export declare function flattenForm(args: FlattenFormArgs): Promise<FormResult>;
|
|
31
|
-
export declare function splitPdf(inputPath: string, ranges: string[], outputDir: string, prefix: string | undefined, opts: CommonEditOptions): Promise<SplitResult>;
|