@first-ch/tools-mcp 0.34.1 → 0.37.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/server.mjs CHANGED
@@ -1,10 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  // First CH Tools MCP サーバー(stdio)
3
3
  // 導入例: npx -y @first-ch/tools-mcp
4
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
- import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
+ import { McpServer } from '@modelcontextprotocol/server';
5
+ import { serveStdio } from '@modelcontextprotocol/server/stdio';
6
6
  import { z } from 'zod';
7
- import { appendFile, writeFile } from 'node:fs/promises';
7
+ import { APP_TOOLS, callAppTool } from './apps.mjs';
8
+ import { appendFile } from 'node:fs/promises';
9
+ import { writeOutput } from './fs-safe.mjs';
8
10
  import { createRequire } from 'node:module';
9
11
  import { contrastCheck, countChars, buildLlmsTxt, buildJsonLd, analyzeEncoding, convertEncoding } from './lib.mjs';
10
12
  import { generateTestData, FIELDS, DEFAULT_FIELDS, PRESETS } from './testdata.mjs';
@@ -36,9 +38,58 @@ import { dateCalcTool } from './date-calc.mjs';
36
38
  import { htmlToMarkdownTool } from './html-md.mjs';
37
39
  import { warekiConvertTool } from './wareki.mjs';
38
40
  import { slugGenerateTool } from './slug.mjs';
41
+ import { htpasswdGenerateTool } from './htpasswd.mjs';
42
+ import { openApiDocGenerateTool } from './openapi-doc.mjs';
43
+ import { faqJsonldTool } from './faq-jsonld.mjs';
44
+ import { linesProcessTool } from './lines.mjs';
45
+ import { dpiCalcTool } from './dpi.mjs';
46
+ import { serpCheckTool } from './serp.mjs';
47
+ import { cssLayoutGenerateTool } from './css-layout.mjs';
39
48
 
40
49
  const { version } = createRequire(import.meta.url)('./package.json');
41
- const server = new McpServer({ name: 'firstch-tools', version });
50
+ // SDK v2 の serveStdio は接続ごとに factory から McpServer を1つ作る(旧仕様の initialize と
51
+ // 2026-07-28 仕様の server/discover の両方を、同じ登録内容で受ける)。ツールは下の registerTool で
52
+ // 一覧に積み、buildServer() が接続のたびに登録する。
53
+ const TOOLS = [];
54
+ function buildServer() {
55
+ const server = new McpServer({ name: 'firstch-tools', version }, { capabilities: { tools: {} } });
56
+ for (const { name, config, handler } of TOOLS) server.registerTool(name, config, handler);
57
+ return server;
58
+ }
59
+
60
+ // ---------------------------------------------------------------------------
61
+ // ツールの注釈(MCP の annotations)
62
+ // クライアントが「読むだけか・ファイルを書き換えうるか・外部と通信するか」を判断できるよう、
63
+ // 全ツールに付ける。ファイルを書き出す引数(outputPath / outputDir)を持つツールと、
64
+ // 常にファイルを書くツール(webp_convert・marp_render)は readOnlyHint: false・destructiveHint: true
65
+ // (overwrite: true を渡すと既存ファイルを上書きしうるため)。既定では上書きしない。
66
+ // それ以外は手元で計算する(または利用者が指定したファイルを読む)だけなので readOnlyHint: true。
67
+ // 外部と通信しうるのは marp_render の allowRemote: true のときと、apps.first-ch.com へ送る app_* ツール。
68
+ // ---------------------------------------------------------------------------
69
+ const ALWAYS_WRITES = new Set(['webp_convert', 'marp_render']);
70
+ const OPEN_WORLD = new Set(['marp_render']);
71
+
72
+ function toolAnnotations(name, inputSchema = {}) {
73
+ const writes = ALWAYS_WRITES.has(name) || 'outputPath' in inputSchema || 'outputDir' in inputSchema;
74
+ const openWorldHint = OPEN_WORLD.has(name);
75
+ if (!writes) return { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint };
76
+ return { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint };
77
+ }
78
+
79
+ const OVERWRITE_PARAM = z
80
+ .boolean()
81
+ .optional()
82
+ .describe('出力先に同名のファイルがあるとき上書きするか(既定 false=上書きせずエラーにする)');
83
+
84
+ function registerTool(name, config, handler) {
85
+ let inputSchema = config.inputSchema || {};
86
+ const annotations = { title: config.title, ...toolAnnotations(name, inputSchema) };
87
+ if (!annotations.readOnlyHint && !('overwrite' in inputSchema)) {
88
+ inputSchema = { ...inputSchema, overwrite: OVERWRITE_PARAM };
89
+ }
90
+ // v2 は Standard Schema を求めるため、引数の形(shape)を z.object で包んで渡す
91
+ TOOLS.push({ name, config: { ...config, inputSchema: z.object(inputSchema), annotations }, handler });
92
+ }
42
93
 
43
94
  const asText = (obj) => ({ content: [{ type: 'text', text: JSON.stringify(obj, null, 2) }] });
44
95
 
@@ -51,7 +102,27 @@ const logUsage = (tool) =>
51
102
  ? appendFile(USAGE_LOG, JSON.stringify({ ts: new Date().toISOString(), tool, source: 'mcp' }) + '\n').catch(() => {})
52
103
  : Promise.resolve();
53
104
 
54
- server.registerTool(
105
+ // ---------------------------------------------------------------------------
106
+ // apps.first-ch.com の API を呼ぶツール(app_*)。定義表と HTTP 呼び出しは apps.mjs に置き、
107
+ // ここではまとめて登録するだけにする。他のツールと違い入力を apps.first-ch.com へ送るので、
108
+ // openWorldHint: true を付ける(端末のファイルは書き換えないので readOnlyHint: true のまま)。
109
+ // ---------------------------------------------------------------------------
110
+ // 既定では登録しない(端末内で完結するツールだけを出す)。入力を外へ送るツールは、利用者が
111
+ // FIRSTCH_ENABLE_APPS=1 で明示的に有効にしたときだけ出す(「既定では外部へ通信しない」を崩さないため・2026-10-21)
112
+ const APPS_ENABLED = /^(1|true|yes|on)$/i.test(process.env.FIRSTCH_ENABLE_APPS ?? '');
113
+ for (const def of APPS_ENABLED ? APP_TOOLS : []) {
114
+ OPEN_WORLD.add(def.name);
115
+ registerTool(
116
+ def.name,
117
+ { title: def.title, description: def.description, inputSchema: def.inputSchema },
118
+ async (args) => {
119
+ await logUsage(def.name);
120
+ return asText(await callAppTool(def, args, { version }));
121
+ },
122
+ );
123
+ }
124
+
125
+ registerTool(
55
126
  'contrast_check',
56
127
  {
57
128
  title: 'WCAGコントラスト比チェック',
@@ -69,7 +140,7 @@ server.registerTool(
69
140
  },
70
141
  );
71
142
 
72
- server.registerTool(
143
+ registerTool(
73
144
  'count_chars',
74
145
  {
75
146
  title: '文字数カウント(Xウェイト対応)',
@@ -86,7 +157,7 @@ server.registerTool(
86
157
  },
87
158
  );
88
159
 
89
- server.registerTool(
160
+ registerTool(
90
161
  'webp_convert',
91
162
  {
92
163
  title: '画像→WebP変換',
@@ -100,14 +171,14 @@ server.registerTool(
100
171
  outputDir: z.string().optional().describe('出力先ディレクトリ(省略時は各入力と同じ場所)'),
101
172
  },
102
173
  },
103
- async ({ paths, quality, outputDir }) => {
174
+ async ({ paths, quality, outputDir, overwrite }) => {
104
175
  await logUsage('webp_convert');
105
176
  const { join, basename } = await import('node:path');
106
177
  const results = [];
107
178
  for (const p of paths) {
108
179
  try {
109
180
  const output = outputDir ? join(outputDir, basename(p).replace(/\.[^.]+$/, '') + '.webp') : undefined;
110
- results.push(await convertToWebp(p, { quality, output }));
181
+ results.push(await convertToWebp(p, { quality, output, overwrite }));
111
182
  } catch (e) {
112
183
  results.push({ input: p, error: String(e.message || e) });
113
184
  }
@@ -116,7 +187,7 @@ server.registerTool(
116
187
  },
117
188
  );
118
189
 
119
- server.registerTool(
190
+ registerTool(
120
191
  'jsonld_generate',
121
192
  {
122
193
  title: 'JSON-LD構造化データ生成',
@@ -166,7 +237,7 @@ server.registerTool(
166
237
  },
167
238
  );
168
239
 
169
- server.registerTool(
240
+ registerTool(
170
241
  'llmstxt_generate',
171
242
  {
172
243
  title: 'llms.txt 生成',
@@ -200,7 +271,7 @@ server.registerTool(
200
271
  },
201
272
  );
202
273
 
203
- server.registerTool(
274
+ registerTool(
204
275
  'encoding_convert',
205
276
  {
206
277
  title: '文字コード・改行コード変換',
@@ -210,7 +281,7 @@ server.registerTool(
210
281
  'リポジトリ内ファイルの改行コード事故(CRLFがLFに書き換わる等)の確認に使う。' +
211
282
  'mode=analyze なら判定のみ、mode=convert なら変換後のテキストとbase64を返す。',
212
283
  inputSchema: {
213
- base64: z.string().describe('対象ファイルの内容(base64)。テキストを直接渡す場合は text を使う'),
284
+ base64: z.string().optional().describe('対象ファイルの内容(base64)。テキストを直接渡す場合は text を使う(どちらか必須)'),
214
285
  text: z.string().optional().describe('base64の代わりにテキストを直接渡す場合(UTF-8として扱う)'),
215
286
  mode: z.enum(['analyze', 'convert']).optional().describe('既定 analyze。convert で変換結果を返す'),
216
287
  encoding: z.enum(['utf-8', 'shift_jis']).optional().describe('入力の文字コード。省略時は自動判定'),
@@ -230,17 +301,22 @@ server.registerTool(
230
301
  },
231
302
  );
232
303
 
233
- server.registerTool(
304
+ registerTool(
234
305
  'marp_render',
235
306
  {
236
307
  title: 'Marp Markdown→スライド レンダリング',
237
308
  description:
238
309
  'Marp Markdown をスライドへレンダリングし、HTML(テーマCSSをインラインした自己完結ファイル)や PDF を書き出す。' +
239
310
  'AIが生成したスライド用Markdownをそのまま渡せば描画まで完結する(社内の marp ビルドの定型化・顧客配布資料の生成に使う)。' +
240
- '和文テーマ firstch(firstch-design 準拠・紙/墨/朱・IBM Plex Sans JP)を同梱し、既定テーマにする。' +
311
+ '和文テーマ firstch(紙/墨/朱・IBM Plex Sans JP が入っていれば使う)を同梱し、既定テーマにする。' +
241
312
  'Markdown 側の Marp フロントマター(例: theme:/paginate:/size:/`<!-- _class: lead -->`)はそのまま効く。' +
242
313
  'PDF はローカルの Chrome/Chromium を headless で呼び出して生成する(未検出なら HTML のみ返し理由を添える。' +
243
- '環境変数 MARP_CHROME_PATH で実行ファイルを明示可)。完全ローカル処理・ネットワーク送信なし。',
314
+ '環境変数 MARP_CHROME_PATH で実行ファイルを明示可)。' +
315
+ '既定では外部へ通信しない(Webフォントを読まず、絵文字は文字のまま、組み込みテーマの外部フォント @import は取り除き、' +
316
+ 'PDF を作る Chrome も外部への通信を止めて起動する)。Markdown が参照する外部の画像・CSS を PDF に入れたいときだけ allowRemote: true を渡す。' +
317
+ '出力した HTML を利用者がブラウザで開いたときは、Markdown に書いた外部画像をそのブラウザが読み込む。' +
318
+ 'ファイルを書き出す(outputPath・inputPath と同じ場所、どちらも無ければ OS の一時ディレクトリ下の firstch-tools-mcp/)。' +
319
+ '同名のファイルがあれば上書きせずエラーにする(上書きは overwrite: true)。書き出したファイルは消さない。',
244
320
  inputSchema: {
245
321
  markdown: z.string().optional().describe('Marp Markdown 本文(inputPath と排他・どちらか必須)'),
246
322
  inputPath: z.string().optional().describe('Markdownファイルの絶対パス(markdown 未指定時に読み込む)'),
@@ -257,9 +333,13 @@ server.registerTool(
257
333
  .optional()
258
334
  .describe('出力ファイルのベースパス(拡張子は自動。省略時は inputPath 準拠、無ければ一時ディレクトリ)'),
259
335
  title: z.string().optional().describe('HTML の <title>(既定 "Marp slides")'),
336
+ allowRemote: z
337
+ .boolean()
338
+ .optional()
339
+ .describe('Markdown が参照する外部の画像・CSS を読み込むか(既定 false=外部へ通信しない)'),
260
340
  },
261
341
  },
262
- async ({ markdown, inputPath, theme, formats, outputPath, title }) => {
342
+ async ({ markdown, inputPath, theme, formats, outputPath, title, overwrite, allowRemote }) => {
263
343
  await logUsage('marp_render');
264
344
  let md = markdown;
265
345
  let outBase = outputPath;
@@ -272,11 +352,11 @@ server.registerTool(
272
352
  if (!docTitle) docTitle = basename(inputPath, extname(inputPath));
273
353
  }
274
354
  if (md === undefined || md === '') throw new Error('markdown か inputPath のどちらかが必要です');
275
- return asText(await renderMarp(md, { theme, formats, outputPath: outBase, title: docTitle }));
355
+ return asText(await renderMarp(md, { theme, formats, outputPath: outBase, title: docTitle, overwrite, allowRemote }));
276
356
  },
277
357
  );
278
358
 
279
- server.registerTool(
359
+ registerTool(
280
360
  'testdata_generate',
281
361
  {
282
362
  title: 'テストデータ生成(ダミーCSV/JSON/Excel・境界値テキスト)',
@@ -310,7 +390,7 @@ server.registerTool(
310
390
  await logUsage('testdata_generate');
311
391
  const { _bytes, ...result } = generateTestData(opts);
312
392
  if (opts.outputPath && result.mode === 'records') {
313
- await writeFile(opts.outputPath, _bytes);
393
+ await writeOutput(opts.outputPath, _bytes, { overwrite: opts.overwrite });
314
394
  result.output = opts.outputPath;
315
395
  // ファイルに書けたなら base64 は重複した重い情報でしかない
316
396
  delete result.base64;
@@ -319,7 +399,7 @@ server.registerTool(
319
399
  },
320
400
  );
321
401
 
322
- server.registerTool(
402
+ registerTool(
323
403
  'diff_check',
324
404
  {
325
405
  title: 'テキスト・コード差分チェック',
@@ -374,7 +454,7 @@ server.registerTool(
374
454
  },
375
455
  );
376
456
 
377
- server.registerTool(
457
+ registerTool(
378
458
  'cron_explain',
379
459
  {
380
460
  title: 'Cron式の解説+次回発火日時',
@@ -401,7 +481,7 @@ server.registerTool(
401
481
  },
402
482
  );
403
483
 
404
- server.registerTool(
484
+ registerTool(
405
485
  'base64_encode',
406
486
  {
407
487
  title: 'Base64 / Data URI エンコード・デコード',
@@ -435,7 +515,7 @@ server.registerTool(
435
515
  },
436
516
  );
437
517
 
438
- server.registerTool(
518
+ registerTool(
439
519
  'url_params',
440
520
  {
441
521
  title: 'URLパラメータの分解・編集・再構築',
@@ -462,7 +542,7 @@ server.registerTool(
462
542
  .enum(['component', 'uri', 'form'])
463
543
  .optional()
464
544
  .describe('encode/decode の方式(既定 component=encodeURIComponent / uri=encodeURI / form=スペースを +)'),
465
- set: z.record(z.string()).optional().describe('parse: 追加・上書きするパラメータ(値が空文字なら削除)'),
545
+ set: z.record(z.string(), z.string()).optional().describe('parse: 追加・上書きするパラメータ(値が空文字なら削除)'),
466
546
  remove: z.array(z.string()).optional().describe('parse: 削除するパラメータ名(大文字小文字を無視)'),
467
547
  utm: z
468
548
  .record(z.string())
@@ -480,7 +560,7 @@ server.registerTool(
480
560
  },
481
561
  );
482
562
 
483
- server.registerTool(
563
+ registerTool(
484
564
  'html_escape',
485
565
  {
486
566
  title: 'HTML特殊文字のエスケープ・エンティティのデコード',
@@ -525,7 +605,7 @@ const JSON_YAML_SHARED =
525
605
  '設定ファイルの構文チェックにも使える。' +
526
606
  '読み替えで意味が変わる箇所は notes で知らせる(キーの重複=後が勝つ・2の53乗を超える整数の桁落ちなど)。';
527
607
 
528
- server.registerTool(
608
+ registerTool(
529
609
  'json_to_yaml',
530
610
  {
531
611
  title: 'JSON → YAML 変換・整形',
@@ -563,7 +643,7 @@ server.registerTool(
563
643
  },
564
644
  );
565
645
 
566
- server.registerTool(
646
+ registerTool(
567
647
  'yaml_to_json',
568
648
  {
569
649
  title: 'YAML → JSON 変換・構文チェック',
@@ -599,7 +679,7 @@ server.registerTool(
599
679
  },
600
680
  );
601
681
 
602
- server.registerTool(
682
+ registerTool(
603
683
  'px_rem_convert',
604
684
  {
605
685
  title: 'px ⇄ rem / em 単位換算・CSSの一括変換',
@@ -662,7 +742,7 @@ server.registerTool(
662
742
  },
663
743
  );
664
744
 
665
- server.registerTool(
745
+ registerTool(
666
746
  'color_convert',
667
747
  {
668
748
  title: 'カラーコード変換・アルファ透過計算',
@@ -706,7 +786,7 @@ server.registerTool(
706
786
  },
707
787
  );
708
788
 
709
- server.registerTool(
789
+ registerTool(
710
790
  'hash_generate',
711
791
  {
712
792
  title: 'MD5 / SHA-1 / SHA-256 / SHA-384 / SHA-512 ハッシュ生成・照合',
@@ -749,7 +829,7 @@ server.registerTool(
749
829
  },
750
830
  );
751
831
 
752
- server.registerTool(
832
+ registerTool(
753
833
  'jwt_decode',
754
834
  {
755
835
  title: 'JWTのデコード・有効期限チェック・署名の検証',
@@ -786,7 +866,7 @@ server.registerTool(
786
866
  },
787
867
  );
788
868
 
789
- server.registerTool(
869
+ registerTool(
790
870
  'user_agent_parse',
791
871
  {
792
872
  title: 'User-Agent文字列の解析とデバイス判定',
@@ -824,7 +904,7 @@ server.registerTool(
824
904
  },
825
905
  );
826
906
 
827
- server.registerTool(
907
+ registerTool(
828
908
  'uuid_generate',
829
909
  {
830
910
  title: 'UUID v4 / ULID の一括生成',
@@ -863,7 +943,7 @@ server.registerTool(
863
943
  },
864
944
  );
865
945
 
866
- server.registerTool(
946
+ registerTool(
867
947
  'aspect_ratio_calc',
868
948
  {
869
949
  title: 'アスペクト比の計算・レスポンシブサイズ算出',
@@ -924,7 +1004,7 @@ server.registerTool(
924
1004
  },
925
1005
  );
926
1006
 
927
- server.registerTool(
1007
+ registerTool(
928
1008
  'markdown_table',
929
1009
  {
930
1010
  title: 'TSV/CSV → Markdownテーブル整形・相互変換',
@@ -982,7 +1062,7 @@ server.registerTool(
982
1062
  },
983
1063
  );
984
1064
 
985
- server.registerTool(
1065
+ registerTool(
986
1066
  'sql_format',
987
1067
  {
988
1068
  title: 'SQLクエリの整形(予約語の大文字化・句ごとの改行・字下げ)',
@@ -1034,7 +1114,7 @@ server.registerTool(
1034
1114
  },
1035
1115
  );
1036
1116
 
1037
- server.registerTool(
1117
+ registerTool(
1038
1118
  'qr_generate',
1039
1119
  {
1040
1120
  title: 'QRコードの生成(SVG / PNG / 文字の図)',
@@ -1076,7 +1156,7 @@ server.registerTool(
1076
1156
  },
1077
1157
  );
1078
1158
 
1079
- server.registerTool(
1159
+ registerTool(
1080
1160
  'unixtime_convert',
1081
1161
  {
1082
1162
  title: 'UNIXタイムスタンプ⇄日時の相互変換',
@@ -1121,7 +1201,7 @@ server.registerTool(
1121
1201
  },
1122
1202
  );
1123
1203
 
1124
- server.registerTool(
1204
+ registerTool(
1125
1205
  'robotstxt_generate',
1126
1206
  {
1127
1207
  title: 'robots.txt の生成(AIクローラー対応)',
@@ -1168,7 +1248,7 @@ server.registerTool(
1168
1248
  .object({
1169
1249
  preset: z.enum(['allow', 'block', 'training', 'none', 'custom']).optional()
1170
1250
  .describe("AIクローラーのプリセット(既定 'training'=学習目的だけ拒否)"),
1171
- overrides: z.record(z.enum(['allow', 'block', 'omit'])).optional()
1251
+ overrides: z.record(z.string(), z.enum(['allow', 'block', 'omit'])).optional()
1172
1252
  .describe("1件ずつの指定(例: {\"GPTBot\": \"block\", \"PerplexityBot\": \"allow\"})"),
1173
1253
  inherit: z.boolean().optional()
1174
1254
  .describe('共通の禁止パスを許可したAIクローラーのグループへ書き写すか(既定 true)'),
@@ -1203,7 +1283,7 @@ server.registerTool(
1203
1283
  },
1204
1284
  );
1205
1285
 
1206
- server.registerTool(
1286
+ registerTool(
1207
1287
  'case_convert',
1208
1288
  {
1209
1289
  title: '文字列のケース変換(camelCase / snake_case / kebab-case)',
@@ -1248,7 +1328,7 @@ server.registerTool(
1248
1328
  },
1249
1329
  );
1250
1330
 
1251
- server.registerTool(
1331
+ registerTool(
1252
1332
  'csv_convert',
1253
1333
  {
1254
1334
  title: 'CSV/TSV ⇄ JSON の相互変換',
@@ -1297,7 +1377,7 @@ server.registerTool(
1297
1377
  },
1298
1378
  );
1299
1379
 
1300
- server.registerTool(
1380
+ registerTool(
1301
1381
  'zenkaku_convert',
1302
1382
  {
1303
1383
  title: '全角⇄半角の変換とテキストの掃除',
@@ -1349,7 +1429,7 @@ server.registerTool(
1349
1429
  },
1350
1430
  );
1351
1431
 
1352
- server.registerTool(
1432
+ registerTool(
1353
1433
  'cidr_calc',
1354
1434
  {
1355
1435
  title: 'IPアドレス・CIDRの計算',
@@ -1386,7 +1466,7 @@ server.registerTool(
1386
1466
  },
1387
1467
  );
1388
1468
 
1389
- server.registerTool(
1469
+ registerTool(
1390
1470
  'date_calc',
1391
1471
  {
1392
1472
  title: '日数・営業日の計算',
@@ -1432,7 +1512,7 @@ server.registerTool(
1432
1512
  },
1433
1513
  );
1434
1514
 
1435
- server.registerTool(
1515
+ registerTool(
1436
1516
  'html_to_markdown',
1437
1517
  {
1438
1518
  title: 'HTML → Markdown 変換',
@@ -1481,7 +1561,7 @@ server.registerTool(
1481
1561
  },
1482
1562
  );
1483
1563
 
1484
- server.registerTool(
1564
+ registerTool(
1485
1565
  'wareki_convert',
1486
1566
  {
1487
1567
  title: '和暦 ⇄ 西暦変換・満年齢',
@@ -1517,7 +1597,7 @@ server.registerTool(
1517
1597
  },
1518
1598
  );
1519
1599
 
1520
- server.registerTool(
1600
+ registerTool(
1521
1601
  'slug_generate',
1522
1602
  {
1523
1603
  title: 'URLスラッグ生成(日本語タイトル→ローマ字)',
@@ -1553,4 +1633,297 @@ server.registerTool(
1553
1633
  },
1554
1634
  );
1555
1635
 
1556
- await server.connect(new StdioServerTransport());
1636
+ registerTool(
1637
+ 'htpasswd_generate',
1638
+ {
1639
+ title: 'htpasswd 生成・照合(Basic認証)',
1640
+ description:
1641
+ 'Basic認証用の htpasswd の行を作る(tools.first-ch.com/htpasswd/ と同一ロジック)。' +
1642
+ 'ステージングサイト・納品前の確認環境に Basic 認証を掛けるときに使う。' +
1643
+ 'ハッシュは bcrypt($2y$・Apache の htpasswd -B と同じ・既定コスト5)か apr1-md5($apr1$・Apache 2.2 など bcrypt を読めない環境向け)。' +
1644
+ '1人なら user と password、まとめて作るなら users(文字列 "user:pass" か {user, password})か bulk(1行1人の「ユーザー名:パスワード」・# で始まる行と空行は飛ばす)を渡す(200人まで)。' +
1645
+ '**パスワードが空のユーザーは16文字のパスワードを自動生成し、generated で返す**(紛らわしい字 0 O o 1 l I を除いた CSPRNG)。利用者が渡したパスワードは結果に繰り返さない。' +
1646
+ '「:」を含む・空・255バイト超のユーザー名は飛ばし、重複・12文字未満・ユーザー名と同じ・前後の空白・全角文字・bcrypt の72バイト超(以降は無視される)を notes で指摘する。' +
1647
+ 'server(apache / nginx)を渡すと .htaccess か nginx の設定スニペットも返す(file・realm・認証なしで通す ips〔IPv4 / IPv6 / CIDR〕を反映。空白を含むパスは引用し、読めないIPは外して指摘)。' +
1648
+ 'mode="verify" か hash を渡すと、既存の htpasswd の1行(またはハッシュ)と password を照合する($2y$/$2b$/$2a$・$apr1$・$1$・{SHA}。コスト15以上の bcrypt は照合しない)。' +
1649
+ 'outputPath を渡すと htpasswd の中身をファイルへ書き出す(本文は返さない)。パスワードはどこにも記録しない。完全ローカル処理・ネットワーク送信なし。',
1650
+ inputSchema: {
1651
+ mode: z.enum(['generate', 'verify']).optional().describe('処理の種類(省略時は hash があれば verify、無ければ generate)'),
1652
+ user: z.string().optional().describe('1人ぶんのユーザー名(users・bulk と排他)'),
1653
+ password: z.string().optional().describe('user のパスワード(空なら自動生成)。mode=verify では照合するパスワード'),
1654
+ users: z
1655
+ .array(z.union([z.string(), z.object({ user: z.string(), password: z.string().optional() })]))
1656
+ .optional()
1657
+ .describe('まとめて作る(200人まで)。"user:pass" の文字列か {user, password}。パスワード省略で自動生成'),
1658
+ bulk: z.string().optional().describe('1行1人の「ユーザー名:パスワード」(パスワードに : を含んでよい・空なら自動生成)'),
1659
+ algo: z.enum(['bcrypt', 'apr1']).optional().describe("ハッシュ方式(既定 'bcrypt')"),
1660
+ cost: z.number().int().optional().describe('bcrypt のコスト(4〜14・既定 5=htpasswd -B の既定。11以上は全リクエストが遅くなる)'),
1661
+ server: z.enum(['apache', 'nginx']).optional().describe('渡すと .htaccess / nginx の設定スニペットも返す(user 等を省けばスニペットだけ)'),
1662
+ file: z.string().optional().describe('htpasswd を置くサーバー上の絶対パス(既定 apache=/home/example/.htpasswd・nginx=/etc/nginx/.htpasswd)'),
1663
+ realm: z.string().optional().describe('認証領域名 AuthName(既定 Restricted Area)'),
1664
+ ips: z.union([z.string(), z.array(z.string())]).optional().describe('認証なしで通すIP・CIDR(空白・カンマ区切りの文字列か配列)'),
1665
+ hash: z.string().optional().describe('mode=verify で照合する htpasswd の1行(またはハッシュだけ)'),
1666
+ outputPath: z.string().optional().describe('htpasswd の中身を書き出す絶対パス(指定すると htpasswd は返さない)'),
1667
+ lang: z.enum(['ja', 'en']).optional().describe("指摘事項の言語(既定 'ja')"),
1668
+ },
1669
+ },
1670
+ async (opts) => {
1671
+ await logUsage('htpasswd_generate');
1672
+ return asText(await htpasswdGenerateTool(opts));
1673
+ },
1674
+ );
1675
+
1676
+ registerTool(
1677
+ 'openapi_doc_generate',
1678
+ {
1679
+ title: 'OpenAPI → 日本語ドキュメント&TypeScript型定義',
1680
+ description:
1681
+ 'OpenAPI 3.x / Swagger 2.0 の仕様書(YAML か JSON)から、日本語(lang="en" で英語)の Markdown APIリファレンスと ' +
1682
+ 'TypeScript の型定義を作る(tools.first-ch.com/openapi-doc-gen/ と同一ロジック)。' +
1683
+ '受け取った仕様書を顧客・チーム向けの読める資料にする、フロントエンドの型を手書きせずに起こす、といった用途に使う。' +
1684
+ 'Markdown はベースURL・エンドポイント一覧・タグごとのパラメータ/リクエスト/レスポンスの表・スキーマ一覧を含み、' +
1685
+ '例が書かれていないレスポンスにはスキーマから例を作る(examples=false で切る)。' +
1686
+ 'TypeScript は components.schemas(Swagger は definitions)を interface / type にし、' +
1687
+ 'operations=true(既定)ならエンドポイントごとの Params / RequestBody / Response の型も出す。' +
1688
+ '$ref・allOf / oneOf / anyOf・enum・nullable・additionalProperties に対応し、TypeScript の予約語や重複する名前は付け替えて notes で知らせる。' +
1689
+ '**別ファイル・URLを指す $ref は読みに行かない**(その部分は unknown にして OA_EXTERNAL_REF で指摘)。1ファイルにまとめた仕様書を渡すこと。' +
1690
+ 'YAML/JSON の解析は自前(json_to_yaml と同じパーサ。ただし「- 」で始まる折り返し行も description の続きとして読む)。' +
1691
+ '構文の誤りは ok:false と error(code・行・桁・前後の行の抜粋)で返す。' +
1692
+ 'spec か path のどちらか一方を渡す(20MBまで)。outputDir を渡すと <タイトル>.md と <タイトル>.ts を書き出す(本文は返さない)。' +
1693
+ '完全ローカル処理・ネットワーク送信なし。',
1694
+ inputSchema: {
1695
+ spec: z.string().optional().describe('仕様書の本文(YAML か JSON。path と排他)'),
1696
+ path: z.string().optional().describe('仕様書ファイルの絶対パス(UTF-8 として読む。spec と排他)'),
1697
+ lang: z.enum(['ja', 'en']).optional().describe("ドキュメント・指摘・エラーの言語(既定 'ja')"),
1698
+ examples: z.boolean().optional().describe('例が書かれていないレスポンスにスキーマから例を作る(既定 true)'),
1699
+ operations: z.boolean().optional().describe('エンドポイントごとの引数・リクエスト・レスポンスの型も出す(既定 true)'),
1700
+ output: z.enum(['both', 'markdown', 'typescript']).optional().describe("返す(書き出す)もの(既定 'both')"),
1701
+ outputDir: z.string().optional().describe('書き出し先ディレクトリの絶対パス(指定すると markdown / typescript は返さない)'),
1702
+ },
1703
+ },
1704
+ async (opts) => {
1705
+ await logUsage('openapi_doc_generate');
1706
+ return asText(await openApiDocGenerateTool(opts));
1707
+ },
1708
+ );
1709
+
1710
+ registerTool(
1711
+ 'faq_jsonld_generate',
1712
+ {
1713
+ title: 'FAQ構造化データ(JSON-LD)&Markdown生成',
1714
+ description:
1715
+ '質問と回答のペアから、schema.org の FAQPage 形式の JSON-LD・同じ内容の Markdown・貼り付け用の HTML(details / summary)を同時に作る' +
1716
+ '(tools.first-ch.com/faq-jsonld/ と同一ロジック)。' +
1717
+ '**jsonld_generate(type=faqpage)との違い**: あちらは質問と回答を文字列のまま入れるだけ。こちらは回答を' +
1718
+ '「空行で段落・改行は <br>・[文字](URL) と裸の https://… はリンク・行頭の - ・ と 1. は箇条書き」として読み、' +
1719
+ 'JSON-LD の acceptedAnswer.text を HTML(1行だけなら <p> で包まない)か answer_format="text" のプレーンテキストで書き、' +
1720
+ 'Markdown(見出し+本文・記号はエスケープ)と details/summary の HTML も返す。' +
1721
+ 'bulk に「Q: / Q1. / Q. / 質問:」「A: / 回答:/ 答え:」で始まる行や「## 見出し」で書いた文章をまとめて渡すと、質問と回答に分けて items の後ろへ足す。' +
1722
+ 'リンクは http(s)・mailto・tel・/・# だけをリンクにし、javascript: などは文字のまま残して UNSAFE_LINK で指摘する。' +
1723
+ '相対URL(RELATIVE_LINK)・同じ質問の重複(DUPLICATE・全角半角と空白を無視)・片方だけ空の行(SKIPPED・出力しない)も warnings で返す。' +
1724
+ '<script> の中で途切れないよう </script と <!-- と U+2028/2029 をエスケープする。日本語は \\u エスケープしない。' +
1725
+ '質問は200件・質問500字・回答5000字まで。完全ローカル処理・ネットワーク送信なし。',
1726
+ inputSchema: {
1727
+ items: z
1728
+ .array(z.object({ q: z.string().describe('質問(改行は空白に畳む)'), a: z.string().describe('回答(空行で段落・- / 1. で箇条書き・[文字](URL) でリンク)') }))
1729
+ .optional()
1730
+ .describe('質問と回答の配列(bulk と併用可・合計200件まで)'),
1731
+ bulk: z.string().optional().describe('「Q: …」「A: …」や「## 質問」形式でまとめて書いた文章。解析して items の後ろへ足す'),
1732
+ title: z.string().optional().describe('FAQ 全体の見出し(Markdown・HTML の先頭に入る。JSON-LD には入らない)'),
1733
+ level: z.union([z.literal(2), z.literal(3)]).optional().describe('質問の見出しの段(既定 3 = ###。title は1段上)'),
1734
+ answer_format: z.enum(['html', 'text']).optional().describe("JSON-LD の回答の書き方(既定 'html'。'text' はリンクを「文字(URL)」、箇条書きを記号付きの行にする)"),
1735
+ wrap_script: z.boolean().optional().describe('JSON-LD を <script type="application/ld+json"> で包む(既定 true)'),
1736
+ exclusive: z.boolean().optional().describe('details に name="faq" を付け、1つ開くとほかが閉じるようにする(既定 false)'),
1737
+ lang: z.enum(['ja', 'en']).optional().describe("warnings の言語と、answer_format=text のときの書き方(既定 'ja')"),
1738
+ },
1739
+ },
1740
+ async (opts) => {
1741
+ await logUsage('faq_jsonld_generate');
1742
+ return asText(await faqJsonldTool(opts));
1743
+ },
1744
+ );
1745
+
1746
+ registerTool(
1747
+ 'lines_process',
1748
+ {
1749
+ title: 'テキスト行操作(重複削除・並べ替え・行番号)',
1750
+ description:
1751
+ '1行1項目のテキストを整える(tools.first-ch.com/lines/ と同一ロジック)。' +
1752
+ 'キーワード・URL・メールアドレス・商品名の一覧の重複削除や並べ替え、箇条書き化といった定型処理に使う。' +
1753
+ '**適用順は固定**: trim(前後の半角/全角空白・タブ・NBSPを削る) → removeBlank(空行と空白だけの行を削る) → ' +
1754
+ 'dedupe(dedupeMode: first=最初の1行を残す / unique=重複した行は1行も残さない / dupes=重複した行だけを1行ずつ。ignoreCase で大文字小文字を区別しない) → ' +
1755
+ 'sort(asc / desc / reverse / shuffle。asc・desc は numeric〔既定 true〕で item2 < item10・-3 < 1.25 < 10 と数を数として比べ、数値の行を文字の行より前に置く。照合は日本語の Intl.Collator) → ' +
1756
+ 'prefix / suffix → number(start・sep: dot / paren / colon / bracket / tab / space・pad でゼロ埋め。接頭辞の外側に付く)。' +
1757
+ 'preset(uniqsort=トリム+空行除去+重複削除+昇順 / clean / numbered / mdlist="- " の箇条書き / shuffle)は Web版のボタンと同じ設定から始め、個別の引数で上書きできる。' +
1758
+ 'shuffle は seed(0〜4294967295)を渡すと同じ並びを再現でき、渡さなければ暗号学的乱数で偏りなく混ぜる。' +
1759
+ '改行コードは入力の最初のものに揃え、末尾の改行も保つ。どの行が何回出たか(duplicates)と、前後の空白・大文字小文字・全角半角だけが違う「重複しかけ」の組を notes で返す。' +
1760
+ 'text か path のどちらか一方を渡す。outputPath を渡すとそのパスへ書き出す(本文は返さない)。完全ローカル処理・ネットワーク送信なし。',
1761
+ inputSchema: {
1762
+ text: z.string().optional().describe('対象のテキスト(1行1項目。path と排他)'),
1763
+ path: z.string().optional().describe('対象ファイルの絶対パス(UTF-8として読む。text と排他)'),
1764
+ outputPath: z.string().optional().describe('結果を書き出す絶対パス(指定すると本文は返さない)'),
1765
+ preset: z.enum(['uniqsort', 'clean', 'numbered', 'mdlist', 'shuffle']).optional().describe('Web版のプリセットと同じ設定から始める(個別の引数で上書き)'),
1766
+ trim: z.boolean().optional().describe('各行の前後の空白を削る(既定 false)'),
1767
+ removeBlank: z.boolean().optional().describe('空行(空白だけの行を含む)を削る(既定 false)'),
1768
+ dedupe: z.boolean().optional().describe('重複行を削る(既定 false。dedupeMode を渡すと true)'),
1769
+ dedupeMode: z.enum(['first', 'unique', 'dupes']).optional().describe("重複の扱い(既定 'first')"),
1770
+ ignoreCase: z.boolean().optional().describe('重複の判定で大文字・小文字を区別しない(既定 false)'),
1771
+ sort: z.enum(['none', 'asc', 'desc', 'reverse', 'shuffle']).optional().describe("並べ替え(既定 'none')"),
1772
+ numeric: z.boolean().optional().describe('asc/desc で数値を数として比べる(既定 true)'),
1773
+ seed: z.number().int().optional().describe('shuffle のシード(0〜4294967295。同じシードなら同じ並び)'),
1774
+ prefix: z.string().optional().describe('各行の先頭に付ける文字列'),
1775
+ suffix: z.string().optional().describe('各行の末尾に付ける文字列'),
1776
+ number: z.boolean().optional().describe('行番号を付ける(既定 false)'),
1777
+ start: z.number().int().optional().describe('最初の番号(既定 1)'),
1778
+ sep: z.enum(['dot', 'paren', 'colon', 'bracket', 'tab', 'space']).optional().describe("番号の後ろ(既定 'dot'='1. '。paren='1) '・colon='1: '・bracket='(1) ')"),
1779
+ pad: z.boolean().optional().describe('番号の桁をゼロで揃える(既定 false)'),
1780
+ lang: z.enum(['ja', 'en']).optional().describe("指摘事項の言語(既定 'ja')"),
1781
+ },
1782
+ },
1783
+ async (opts) => {
1784
+ await logUsage('lines_process');
1785
+ return asText(await linesProcessTool(opts));
1786
+ },
1787
+ );
1788
+
1789
+ const DPI_NUM = z.union([z.number(), z.string()]);
1790
+
1791
+ registerTool(
1792
+ 'dpi_calc',
1793
+ {
1794
+ title: '印刷サイズ・DPI計算(必要ピクセル数・実効dpi・早見表)',
1795
+ description:
1796
+ '印刷物の仕上がりサイズ(mm)と解像度(dpi)から入稿に必要なピクセル数を求め、逆に手持ちの画像のピクセル数から印刷できる大きさと実効dpiを求める' +
1797
+ '(tools.first-ch.com/dpi/ と同一ロジック)。チラシ・名刺・ポスターの入稿データ作成、支給画像が印刷に足りるかの判定に使う。' +
1798
+ '`mode="size"`(既定)は paper(A0〜A6・B1〜B6〔JIS〕・MEISHI〔名刺91×55〕・HAGAKI・PHOTO_L・LETTER など28種。既定 A4)か widthMm/heightMm(自由なサイズ)と ' +
1799
+ 'dpi(既定350=日本の商業印刷の標準)・bleedMm(塗り足し・片側。既定3)から、仕上がりと塗り足し込みのピクセル数(**端数は切り上げ**)・インチ・画素数・' +
1800
+ '非圧縮のデータ量(RGB/CMYK)・入稿メモ(memo)と指摘(dpiの過不足・塗り足しなし・安全な範囲3mm・PSDの30,000px上限超え・CMYK入稿)を返す。' +
1801
+ '名刺・往復はがき・封筒・チケットは既定で横向き(orientation で変更可)。' +
1802
+ '`mode="reverse"`(width/height を渡すと既定)は画像のピクセル数から、その dpi での印刷サイズ・350dpiでの上限・paper(既定 A4)に使ったときの実効dpi' +
1803
+ '(**用紙の縦横は有利な向きを選ぶ**)と判定(350以上=十分・300以上=実用・200以上=用途しだい・未満=不足)・350dpiに必要なピクセル数・主要12用紙での実効dpi一覧を返す。' +
1804
+ '`mode="table"` は主要12用紙(papers で指定可)の早見表を text / md(Markdownの表)/ csv で返す。' +
1805
+ '`mode="units"`(value を渡すと既定)は mm・cm・inch・px・pt(1/72インチ)・Q(級=0.25mm)を相互換算する(px は dpi で換算)。' +
1806
+ '`mode="papers"` は用紙の一覧。数値は "210mm"・"4,000" のような文字列でも受ける。完全ローカル処理・ネットワーク送信なし。',
1807
+ inputSchema: {
1808
+ mode: z.enum(['size', 'reverse', 'table', 'units', 'papers']).optional().describe('処理の種類(省略時は width/height があれば reverse、value があれば units、それ以外は size)'),
1809
+ paper: z.string().optional().describe("用紙のキー(A4 / B5 / MEISHI / HAGAKI / PHOTO_L / LETTER など。mode=papers で一覧。既定 'A4'。自由なサイズは widthMm/heightMm)"),
1810
+ orientation: z.enum(['portrait', 'landscape']).optional().describe('用紙の向き(mode=size。省略時は用紙の既定=名刺・封筒などは横)'),
1811
+ widthMm: DPI_NUM.optional().describe('仕上がりの幅(mm・自由なサイズ。heightMm と組で。10000まで)'),
1812
+ heightMm: DPI_NUM.optional().describe('仕上がりの高さ(mm)'),
1813
+ dpi: DPI_NUM.optional().describe('解像度(1〜4800・既定 350)'),
1814
+ bleedMm: DPI_NUM.optional().describe('塗り足し(片側・mm。0〜100・既定 3)'),
1815
+ width: DPI_NUM.optional().describe('mode=reverse: 手持ちの画像の幅(px・500000まで)'),
1816
+ height: DPI_NUM.optional().describe('mode=reverse: 手持ちの画像の高さ(px)'),
1817
+ format: z.enum(['text', 'md', 'csv']).optional().describe("mode=table の書き出し形式(既定 'text')"),
1818
+ papers: z.array(z.string()).optional().describe('mode=table に載せる用紙のキー(省略時は主要12用紙)'),
1819
+ value: DPI_NUM.optional().describe('mode=units で換算する値'),
1820
+ from: z.enum(['mm', 'cm', 'inch', 'px', 'pt', 'q']).optional().describe("mode=units の value の単位(既定 'mm')"),
1821
+ lang: z.enum(['ja', 'en']).optional().describe("用紙名・指摘・入稿メモの言語(既定 'ja')"),
1822
+ },
1823
+ },
1824
+ async (opts) => {
1825
+ await logUsage('dpi_calc');
1826
+ return asText(await dpiCalcTool(opts));
1827
+ },
1828
+ );
1829
+
1830
+ registerTool(
1831
+ 'serp_check',
1832
+ {
1833
+ title: 'SERPメタタグ文字数・ピクセル幅チェック',
1834
+ description:
1835
+ 'title / meta description / URL が Google 検索結果でどこまで表示されるかを、文字数ではなく**表示幅(ピクセル)**で判定する' +
1836
+ '(tools.first-ch.com/serp/ の判定部分と同一ロジック。プレビューの描画は除く)。' +
1837
+ '基準はパソコン=結果の幅600px・タイトル20pxで1行・説明文14pxで2行、スマートフォン=380px・タイトル2行・説明文3行(device="both" で両方)。' +
1838
+ '和文は文字単位・欧文は単語単位で折り返し、行頭禁則(、。」など)はぶら下げ・行末禁則(「(など)は次の行へ送る。' +
1839
+ '行数を超えたら最終行を「…」が入る幅まで削り、表示される行(lines)・切り詰められる部分(cut)・幅(width_px / limit_px)・文字数(書記素単位)・状態(ok / cut / short〔上限の半分未満〕/ empty)を返す。' +
1840
+ '指摘(checks)はタイトル・説明文の未入力(fail)、切り詰め・短すぎ・サイト名の区切り(| | - : など)が無い、URL が https でない・パスが4階層以上・%エンコードを含む(warn)。' +
1841
+ 'パンくず表示(host › path)と貼り付け用の <title> / <meta name="description"> / <link rel="canonical"> も返す。' +
1842
+ '**ピクセル幅は近似**: Web版はブラウザの canvas で実測するが、ここでは Arial の字幅表と和文=1em で測る(カーニングなし)。' +
1843
+ 'ブラウザより数px広く出ることがあり、切り詰めの判定は早め(安全側)に寄る。境目の1〜2文字は目安として扱う。' +
1844
+ 'items で500件までまとめて判定できる。URL を取りに行かない。完全ローカル処理・ネットワーク送信なし。',
1845
+ inputSchema: {
1846
+ title: z.string().optional().describe('<title> の文字列(空白は1つに畳む)'),
1847
+ description: z.string().optional().describe('meta description の文字列'),
1848
+ url: z.string().optional().describe('ページの URL(パンくず表示と https・階層の判定に使う。スキーム省略時は https:// とみなす)'),
1849
+ items: z
1850
+ .array(z.object({ title: z.string().optional(), description: z.string().optional(), url: z.string().optional() }))
1851
+ .optional()
1852
+ .describe('まとめて判定する(500件まで。title/description/url と排他)'),
1853
+ device: z.enum(['desktop', 'mobile', 'both']).optional().describe("基準(既定 'desktop'。'both' はパソコンとスマートフォンの両方)"),
1854
+ lang: z.enum(['ja', 'en']).optional().describe("指摘事項の言語(既定 'ja')"),
1855
+ },
1856
+ },
1857
+ async (opts) => {
1858
+ await logUsage('serp_check');
1859
+ return asText(await serpCheckTool(opts));
1860
+ },
1861
+ );
1862
+
1863
+ registerTool(
1864
+ 'css_layout_generate',
1865
+ {
1866
+ title: 'Flexbox / CSS Grid のCSS生成',
1867
+ description:
1868
+ 'Flexbox / CSS Grid のコンテナと子要素の指定から、コピーして使える CSS と HTML を組み立てる(tools.first-ch.com/css-layout/ と同一ロジック)。' +
1869
+ 'レイアウトの実装・コーディング指示の下書き・プロパティの効き方の確認に使う。**既定値と同じ宣言は書かない**(flex-wrap: nowrap・justify-content: flex-start など)、' +
1870
+ '同じトラックが続けば repeat() に畳む、行と列の gap が同じなら1つにまとめる。' +
1871
+ '`mode="flex"`(既定)は display / direction / wrap / justifyContent / alignItems / alignContent / gap と、items(子要素ごとの grow・shrink・basis・alignSelf・order)。' +
1872
+ '`mode="grid"`(columns / rows / areas / autoFit を渡すと既定)は columns・rows(トラックの配列。例: ["240px", "minmax(0, 1fr)"])・autoFit(repeat(auto-fit, minmax(autoFitMin, 1fr)))・' +
1873
+ 'flow・justifyItems・alignItems・justifyContent・alignContent と、items(columnSpan・rowSpan)。' +
1874
+ '**areas(grid-template-areas)は自前で検証する**: 行ごとのマス数が揃っているか・名前が長方形か(L字や分断だと CSS は値全体を捨てる)・名前に使えない字・列トラック数との食い違い。' +
1875
+ '行は改行か " / " で区切る("header header / side main")。正しければ名前ごとの grid-area の規則と HTML を出す。' +
1876
+ 'notes は効かない組み合わせ(flex-grow があると justify-content が効かない・nowrap で align-content は無意味・1fr トラックで justify-content に余りが無い)と' +
1877
+ '落とし穴(min-width: auto であふれる・1fr の最小値は auto・reverse や dense で読む順がずれる・flexbox の gap は Safari 14.1 以降)。hints は選んだ値の一言解説。' +
1878
+ 'preset で定番(center-row / header / card-row / sidebar / holy-grail / auto-fit / mosaic / stack-bottom)から始められ、mode="presets" で全プリセットの CSS を返す。' +
1879
+ '値の範囲は Web 版のフォームと同じ(gap 0〜80px・子要素 flex 8個 / grid 12個まで・grow/shrink 0〜5・order -2〜2・span 1〜6)。' +
1880
+ 'プレビューの描画と折り返し行数の実測はブラウザ専用のため返さない。完全ローカル処理・ネットワーク送信なし。',
1881
+ inputSchema: {
1882
+ mode: z.enum(['flex', 'grid', 'presets']).optional().describe('作るレイアウト(省略時は preset の種類、columns/rows/areas/autoFit があれば grid、それ以外は flex)'),
1883
+ preset: z
1884
+ .enum(['center-row', 'header', 'card-row', 'sidebar', 'holy-grail', 'auto-fit', 'mosaic', 'stack-bottom'])
1885
+ .optional()
1886
+ .describe('定番の組み合わせから始める(ほかの指定はその上に重ねる)'),
1887
+ display: z.enum(['flex', 'inline-flex']).optional().describe("flex: display(既定 'flex')"),
1888
+ direction: z.enum(['row', 'row-reverse', 'column', 'column-reverse']).optional().describe("flex: flex-direction(既定 'row')"),
1889
+ wrap: z.enum(['nowrap', 'wrap', 'wrap-reverse']).optional().describe("flex: flex-wrap(既定 'wrap')"),
1890
+ justifyContent: z.string().optional().describe("justify-content(flex 既定 'flex-start' / grid 既定 'start')"),
1891
+ alignItems: z.string().optional().describe("align-items(既定 'stretch'。flex は flex-start/flex-end/center/baseline、grid は start/end/center も)"),
1892
+ alignContent: z.string().optional().describe("align-content(flex 既定 'stretch' / grid 既定 'start')"),
1893
+ columns: z.array(z.string()).optional().describe('grid: grid-template-columns のトラック(1〜12本・既定 ["1fr","1fr","1fr"])'),
1894
+ rows: z.array(z.string()).optional().describe('grid: grid-template-rows のトラック(既定 ["auto"]=書かない)'),
1895
+ autoFit: z.boolean().optional().describe('grid: 列を repeat(auto-fit, minmax(autoFitMin, 1fr)) にする(既定 false)'),
1896
+ autoFitMin: z.number().int().optional().describe('grid: auto-fit の最小幅 px(80〜400・既定 200)'),
1897
+ flow: z.enum(['row', 'column', 'row dense', 'column dense']).optional().describe("grid: grid-auto-flow(既定 'row')"),
1898
+ justifyItems: z.enum(['stretch', 'start', 'end', 'center']).optional().describe("grid: justify-items(既定 'stretch')"),
1899
+ areas: z.string().optional().describe('grid: grid-template-areas(行を改行か " / " で区切る。"." は空きマス)'),
1900
+ gap: z.number().int().optional().describe('行と列の gap px(0〜80・既定 12)'),
1901
+ rowGap: z.number().int().optional().describe('行方向の gap px(gap より優先)'),
1902
+ colGap: z.number().int().optional().describe('列方向の gap px(gap より優先)'),
1903
+ count: z.number().int().optional().describe('子要素の数(flex 1〜8・既定 4 / grid 1〜12・既定 6。areas が正しければ名前の数になる)'),
1904
+ items: z
1905
+ .array(
1906
+ z
1907
+ .object({
1908
+ grow: z.number().int().optional().describe('flex-grow(0〜5)'),
1909
+ shrink: z.number().int().optional().describe('flex-shrink(0〜5)'),
1910
+ basis: z.string().optional().describe('flex-basis(auto / 0 / 50% / 240px / min-content など)'),
1911
+ alignSelf: z.enum(['auto', 'stretch', 'flex-start', 'flex-end', 'center', 'baseline']).optional().describe('align-self'),
1912
+ order: z.number().int().optional().describe('order(-2〜2)'),
1913
+ columnSpan: z.number().int().optional().describe('grid: grid-column: span N(1〜6)'),
1914
+ rowSpan: z.number().int().optional().describe('grid: grid-row: span N(1〜6)'),
1915
+ })
1916
+ .nullable(),
1917
+ )
1918
+ .optional()
1919
+ .describe('子要素ごとの指定(先頭から順に。null は既定のまま)'),
1920
+ lang: z.enum(['ja', 'en']).optional().describe("notes・hints の言語(既定 'ja')"),
1921
+ },
1922
+ },
1923
+ async (opts) => {
1924
+ await logUsage('css_layout_generate');
1925
+ return asText(await cssLayoutGenerateTool(opts));
1926
+ },
1927
+ );
1928
+
1929
+ serveStdio(buildServer);