@kagayoi/hatena-blog-mcp 0.0.2

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.
@@ -0,0 +1,477 @@
1
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { z } from "zod";
3
+ import type { AtomPubClient } from "../../atompub/client.js";
4
+ import type { ContentType, Entry, EntryWritePayload } from "../../atompub/types.js";
5
+ import {
6
+ MAX_CATEGORY_CHARS,
7
+ MAX_CATEGORY_COUNT,
8
+ MAX_CONTENT_CHARS,
9
+ MAX_IDENTIFIER_CHARS,
10
+ MAX_TITLE_CHARS,
11
+ } from "../../utils/limits.js";
12
+ import { makeClient, type ToolContext } from "../context.js";
13
+ import { ok, type ToolTextResult, toolError } from "../response.js";
14
+
15
+ // ---------------------------------------------------------------------------
16
+ // Entry view shape (how we present entries back to the MCP client)
17
+ // ---------------------------------------------------------------------------
18
+
19
+ /**
20
+ * Strip internals (atomId, empty strings, optional html) before shipping an
21
+ * entry to the MCP client. Keeps the wire shape stable even if the XML layer
22
+ * grows new fields.
23
+ */
24
+ export function entryView(entry: Entry, includeHtml: boolean): Record<string, unknown> {
25
+ const view: Record<string, unknown> = {
26
+ id: entry.id,
27
+ title: entry.title,
28
+ author: entry.authorName,
29
+ content: entry.content,
30
+ content_type: entry.contentType,
31
+ categories: entry.categories,
32
+ draft: entry.control.draft,
33
+ preview: entry.control.preview,
34
+ scheduled: entry.control.scheduled,
35
+ updated: entry.updated,
36
+ };
37
+ if (entry.published !== undefined) view.published = entry.published;
38
+ if (entry.edited !== undefined) view.edited = entry.edited;
39
+ if (entry.url !== undefined) view.url = entry.url;
40
+ if (entry.customUrl !== undefined) view.custom_url = entry.customUrl;
41
+ if (includeHtml && entry.formattedContent !== undefined) {
42
+ view.formatted_content = entry.formattedContent;
43
+ }
44
+ return view;
45
+ }
46
+
47
+ // ---------------------------------------------------------------------------
48
+ // mergeEntry — the heart of update_entry's partial-update semantics
49
+ // ---------------------------------------------------------------------------
50
+
51
+ export interface EntryPatch {
52
+ title?: string;
53
+ content?: string;
54
+ eyecatchImageUrl?: string;
55
+ categories?: string[];
56
+ draft?: boolean;
57
+ preview?: boolean;
58
+ customUrl?: string;
59
+ touchUpdated?: boolean;
60
+ }
61
+
62
+ const AUTO_EYECATCH_START = "<!-- hatena-blog-mcp:auto-eyecatch:start -->";
63
+ const AUTO_EYECATCH_END = "<!-- hatena-blog-mcp:auto-eyecatch:end -->";
64
+ const AUTO_EYECATCH_BLOCK_PATTERN =
65
+ /^<!-- hatena-blog-mcp:auto-eyecatch:start -->\r?\n[\s\S]*?\r?\n<!-- hatena-blog-mcp:auto-eyecatch:end -->(?:\r?\n){0,2}/;
66
+
67
+ function parseEyecatchImageUrl(value: string): URL {
68
+ let parsed: URL;
69
+ try {
70
+ parsed = new URL(value);
71
+ } catch {
72
+ throw new Error(
73
+ "eyecatch_image_url には認証情報を含まない http または https の画像URLを指定してください。",
74
+ );
75
+ }
76
+ if (
77
+ (parsed.protocol !== "http:" && parsed.protocol !== "https:") ||
78
+ parsed.username !== "" ||
79
+ parsed.password !== ""
80
+ ) {
81
+ throw new Error(
82
+ "eyecatch_image_url には認証情報を含まない http または https の画像URLを指定してください。",
83
+ );
84
+ }
85
+ return parsed;
86
+ }
87
+
88
+ function isSupportedEyecatchImageUrl(value: string): boolean {
89
+ try {
90
+ parseEyecatchImageUrl(value);
91
+ return true;
92
+ } catch {
93
+ return false;
94
+ }
95
+ }
96
+
97
+ function escapeHtmlAttribute(value: string): string {
98
+ return value
99
+ .replaceAll("&", "&amp;")
100
+ .replaceAll('"', "&quot;")
101
+ .replaceAll("<", "&lt;")
102
+ .replaceAll(">", "&gt;");
103
+ }
104
+
105
+ /**
106
+ * Add a visible lead image so Hatena can use its documented first-image
107
+ * fallback for the entry's eyecatch. This does not set Hatena's private
108
+ * eyecatch metadata. A marker pair lets a later call replace our prior block
109
+ * instead of accumulating duplicate lead images.
110
+ */
111
+ export function applyAutoEyecatch(content: string, imageUrl: string): string {
112
+ const normalizedUrl = parseEyecatchImageUrl(imageUrl).href;
113
+ const contentWithoutPriorBlock = content.replace(AUTO_EYECATCH_BLOCK_PATTERN, "");
114
+ const block = `${AUTO_EYECATCH_START}\n<p><img src="${escapeHtmlAttribute(normalizedUrl)}" alt=""></p>\n${AUTO_EYECATCH_END}`;
115
+ const result =
116
+ contentWithoutPriorBlock.length === 0 ? block : `${block}\n\n${contentWithoutPriorBlock}`;
117
+ if (result.length > MAX_CONTENT_CHARS) {
118
+ throw new Error(
119
+ `自動アイキャッチ画像を追加すると本文が最大 ${MAX_CONTENT_CHARS} 文字を超えます。本文を短くしてください。`,
120
+ );
121
+ }
122
+ return result;
123
+ }
124
+
125
+ /**
126
+ * Merge a user-supplied patch onto the existing entry, producing a payload
127
+ * safe to PUT. Unspecified fields fall back to existing values — except for
128
+ * `updated` (omitted unless `touchUpdated` is true) and `customUrl` (only
129
+ * sent if the patch explicitly provides one, since omitting it preserves
130
+ * the existing slug).
131
+ *
132
+ * **content_type MUST be taken from the existing entry** — Hatena will coerce
133
+ * the body's syntax mode to match whatever we send, so changing it silently
134
+ * flips Markdown into plain text (or vice versa).
135
+ */
136
+ export function mergeEntry(existing: Entry, patch: EntryPatch): EntryWritePayload {
137
+ const content = patch.content ?? existing.content;
138
+ const payload: EntryWritePayload = {
139
+ title: patch.title ?? existing.title,
140
+ content:
141
+ patch.eyecatchImageUrl === undefined
142
+ ? content
143
+ : applyAutoEyecatch(content, patch.eyecatchImageUrl),
144
+ categories: patch.categories ?? existing.categories,
145
+ control: {
146
+ draft: patch.draft ?? existing.control.draft,
147
+ preview: patch.preview ?? existing.control.preview,
148
+ scheduled: existing.control.scheduled,
149
+ },
150
+ };
151
+ if (existing.contentType !== undefined) payload.contentType = existing.contentType;
152
+ if (existing.authorName) payload.authorName = existing.authorName;
153
+ if (patch.customUrl !== undefined) {
154
+ payload.customUrl = patch.customUrl;
155
+ }
156
+ if (patch.touchUpdated === true) {
157
+ payload.updated = new Date().toISOString();
158
+ }
159
+ return payload;
160
+ }
161
+
162
+ // ---------------------------------------------------------------------------
163
+ // Zod shapes (shared shape fragments keep tool definitions DRY)
164
+ // ---------------------------------------------------------------------------
165
+
166
+ const identifier = z.string().min(1).max(MAX_IDENTIFIER_CHARS);
167
+ const blogId = identifier.describe("Blog ID, e.g. example.hatenablog.com");
168
+ const hatenaIdOverride = z
169
+ .string()
170
+ .min(1)
171
+ .max(MAX_IDENTIFIER_CHARS)
172
+ .optional()
173
+ .describe("Override the Hatena ID derived from the Authorization header");
174
+ const contentTypeSchema = z
175
+ .enum(["text/x-markdown", "text/x-hatena-syntax", "text/html"])
176
+ .describe("Body syntax. Omit on create to use the blog's default.");
177
+ const eyecatchImageUrlSchema = z
178
+ .string()
179
+ .url()
180
+ .max(MAX_IDENTIFIER_CHARS)
181
+ .refine(isSupportedEyecatchImageUrl, {
182
+ message: "認証情報を含まない http または https の画像URLを指定してください。",
183
+ })
184
+ .describe(
185
+ "本文先頭に画像を挿入し、はてなの自動アイキャッチ候補にします。公式アイキャッチ項目を直接設定する機能ではありません。",
186
+ );
187
+
188
+ // ---------------------------------------------------------------------------
189
+ // Handlers (exported for direct unit testing without the MCP framework)
190
+ // ---------------------------------------------------------------------------
191
+
192
+ interface ListEntriesArgs {
193
+ blog_id: string;
194
+ hatena_id?: string | undefined;
195
+ page?: string | undefined;
196
+ include_html?: boolean | undefined;
197
+ }
198
+
199
+ export async function listEntriesHandler(
200
+ args: ListEntriesArgs,
201
+ ctx: ToolContext,
202
+ ): Promise<ToolTextResult> {
203
+ try {
204
+ const client = makeClient(ctx, args.blog_id, args.hatena_id);
205
+ const listOpts: { page?: string } = {};
206
+ if (args.page !== undefined) listOpts.page = args.page;
207
+ const feed = await client.listEntries(listOpts);
208
+ return ok({
209
+ entries: feed.entries.map((e) => entryView(e, args.include_html ?? false)),
210
+ next_page: feed.nextPage,
211
+ });
212
+ } catch (err) {
213
+ return toolError(err, { operation: "list_entries", requestId: ctx.requestId });
214
+ }
215
+ }
216
+
217
+ interface GetEntryArgs {
218
+ blog_id: string;
219
+ entry_id: string;
220
+ hatena_id?: string | undefined;
221
+ include_html?: boolean | undefined;
222
+ }
223
+
224
+ export async function getEntryHandler(
225
+ args: GetEntryArgs,
226
+ ctx: ToolContext,
227
+ ): Promise<ToolTextResult> {
228
+ try {
229
+ const client = makeClient(ctx, args.blog_id, args.hatena_id);
230
+ const entry = await client.getEntry(args.entry_id);
231
+ return ok(entryView(entry, args.include_html ?? false));
232
+ } catch (err) {
233
+ return toolError(err, { operation: "get_entry", requestId: ctx.requestId });
234
+ }
235
+ }
236
+
237
+ interface CreateEntryArgs {
238
+ blog_id: string;
239
+ hatena_id?: string | undefined;
240
+ title: string;
241
+ content: string;
242
+ content_type?: ContentType | undefined;
243
+ eyecatch_image_url?: string | undefined;
244
+ categories?: string[] | undefined;
245
+ draft?: boolean | undefined;
246
+ preview?: boolean | undefined;
247
+ scheduled?: boolean | undefined;
248
+ updated?: string | undefined;
249
+ custom_url?: string | undefined;
250
+ }
251
+
252
+ export async function createEntryHandler(
253
+ args: CreateEntryArgs,
254
+ ctx: ToolContext,
255
+ ): Promise<ToolTextResult> {
256
+ try {
257
+ if (args.scheduled === true && (args.updated === undefined || args.draft !== true)) {
258
+ return toolError(
259
+ new Error(
260
+ "scheduled=true の場合は draft=true と updated (ISO8601 の公開日時) を指定してください。",
261
+ ),
262
+ { operation: "create_entry", requestId: ctx.requestId },
263
+ );
264
+ }
265
+ const client = makeClient(ctx, args.blog_id, args.hatena_id);
266
+ const payload: EntryWritePayload = {
267
+ title: args.title,
268
+ content:
269
+ args.eyecatch_image_url === undefined
270
+ ? args.content
271
+ : applyAutoEyecatch(args.content, args.eyecatch_image_url),
272
+ control: {
273
+ draft: args.draft ?? false,
274
+ preview: args.preview ?? false,
275
+ scheduled: args.scheduled ?? false,
276
+ },
277
+ };
278
+ if (args.content_type !== undefined) payload.contentType = args.content_type;
279
+ if (args.categories !== undefined) payload.categories = args.categories;
280
+ if (args.updated !== undefined) payload.updated = args.updated;
281
+ if (args.custom_url !== undefined) payload.customUrl = args.custom_url;
282
+ const entry = await client.createEntry(payload);
283
+ return ok(entryView(entry, false));
284
+ } catch (err) {
285
+ return toolError(err, { operation: "create_entry", requestId: ctx.requestId });
286
+ }
287
+ }
288
+
289
+ interface UpdateEntryArgs {
290
+ blog_id: string;
291
+ hatena_id?: string | undefined;
292
+ entry_id: string;
293
+ title?: string | undefined;
294
+ content?: string | undefined;
295
+ eyecatch_image_url?: string | undefined;
296
+ categories?: string[] | undefined;
297
+ draft?: boolean | undefined;
298
+ preview?: boolean | undefined;
299
+ custom_url?: string | undefined;
300
+ touch_updated?: boolean | undefined;
301
+ expected_edited?: string | undefined;
302
+ }
303
+
304
+ export async function updateEntryHandler(
305
+ args: UpdateEntryArgs,
306
+ ctx: ToolContext,
307
+ ): Promise<ToolTextResult> {
308
+ try {
309
+ const client = makeClient(ctx, args.blog_id, args.hatena_id);
310
+ const existing = await client.getEntry(args.entry_id);
311
+ if (args.expected_edited !== undefined && existing.edited !== args.expected_edited) {
312
+ return toolError(
313
+ new Error("更新競合を検出しました。get_entry で最新状態を取得してから再試行してください。"),
314
+ { operation: "update_entry", requestId: ctx.requestId },
315
+ );
316
+ }
317
+ const patch: EntryPatch = {};
318
+ if (args.title !== undefined) patch.title = args.title;
319
+ if (args.content !== undefined) patch.content = args.content;
320
+ if (args.eyecatch_image_url !== undefined) {
321
+ patch.eyecatchImageUrl = args.eyecatch_image_url;
322
+ }
323
+ if (args.categories !== undefined) patch.categories = args.categories;
324
+ if (args.draft !== undefined) patch.draft = args.draft;
325
+ if (args.preview !== undefined) patch.preview = args.preview;
326
+ if (args.custom_url !== undefined) patch.customUrl = args.custom_url;
327
+ if (args.touch_updated !== undefined) patch.touchUpdated = args.touch_updated;
328
+ const payload = mergeEntry(existing, patch);
329
+ const updated = await client.updateEntry(args.entry_id, payload);
330
+ return ok(entryView(updated, false));
331
+ } catch (err) {
332
+ return toolError(err, { operation: "update_entry", requestId: ctx.requestId });
333
+ }
334
+ }
335
+
336
+ interface DeleteEntryArgs {
337
+ blog_id: string;
338
+ hatena_id?: string | undefined;
339
+ entry_id: string;
340
+ }
341
+
342
+ export async function deleteEntryHandler(
343
+ args: DeleteEntryArgs,
344
+ ctx: ToolContext,
345
+ ): Promise<ToolTextResult> {
346
+ try {
347
+ const client = makeClient(ctx, args.blog_id, args.hatena_id);
348
+ await client.deleteEntry(args.entry_id);
349
+ return ok({ ok: true });
350
+ } catch (err) {
351
+ return toolError(err, { operation: "delete_entry", requestId: ctx.requestId });
352
+ }
353
+ }
354
+
355
+ // ---------------------------------------------------------------------------
356
+ // Registration
357
+ // ---------------------------------------------------------------------------
358
+
359
+ export function registerEntryTools(server: McpServer, ctx: ToolContext): void {
360
+ server.registerTool(
361
+ "list_entries",
362
+ {
363
+ description:
364
+ "ブログエントリの一覧を取得します。1ページ7件。続きは返り値の next_page を page に渡して再取得してください。",
365
+ inputSchema: {
366
+ blog_id: blogId,
367
+ hatena_id: hatenaIdOverride,
368
+ page: z
369
+ .string()
370
+ .max(MAX_IDENTIFIER_CHARS)
371
+ .optional()
372
+ .describe("next_page token from a previous response"),
373
+ include_html: z
374
+ .boolean()
375
+ .optional()
376
+ .describe("Include the rendered HTML (hatena:formatted-content) in each entry"),
377
+ },
378
+ annotations: { readOnlyHint: true },
379
+ },
380
+ (args) => listEntriesHandler(args, ctx),
381
+ );
382
+
383
+ server.registerTool(
384
+ "get_entry",
385
+ {
386
+ description: "エントリを1件取得します。",
387
+ inputSchema: {
388
+ blog_id: blogId,
389
+ hatena_id: hatenaIdOverride,
390
+ entry_id: identifier,
391
+ include_html: z.boolean().optional(),
392
+ },
393
+ annotations: { readOnlyHint: true },
394
+ },
395
+ (args) => getEntryHandler(args, ctx),
396
+ );
397
+
398
+ server.registerTool(
399
+ "create_entry",
400
+ {
401
+ description: "新規エントリを投稿します。",
402
+ inputSchema: {
403
+ blog_id: blogId,
404
+ hatena_id: hatenaIdOverride,
405
+ title: z.string().min(1).max(MAX_TITLE_CHARS),
406
+ content: z.string().max(MAX_CONTENT_CHARS),
407
+ content_type: contentTypeSchema.optional(),
408
+ eyecatch_image_url: eyecatchImageUrlSchema.optional(),
409
+ categories: z.array(z.string().max(MAX_CATEGORY_CHARS)).max(MAX_CATEGORY_COUNT).optional(),
410
+ draft: z.boolean().optional(),
411
+ preview: z.boolean().optional(),
412
+ scheduled: z.boolean().optional().describe("true requires draft=true and updated."),
413
+ updated: z
414
+ .string()
415
+ .max(MAX_IDENTIFIER_CHARS)
416
+ .optional()
417
+ .describe("ISO-8601. Required when scheduled=true."),
418
+ custom_url: z.string().max(MAX_IDENTIFIER_CHARS).optional(),
419
+ },
420
+ },
421
+ (args) => createEntryHandler(args, ctx),
422
+ );
423
+
424
+ server.registerTool(
425
+ "update_entry",
426
+ {
427
+ description:
428
+ "エントリを部分更新します。指定したフィールドのみ書き換え、未指定のフィールドは既存値を維持します (投稿日時・URL・本文の記法を含む)。",
429
+ inputSchema: {
430
+ blog_id: blogId,
431
+ hatena_id: hatenaIdOverride,
432
+ entry_id: identifier,
433
+ title: z.string().max(MAX_TITLE_CHARS).optional(),
434
+ content: z.string().max(MAX_CONTENT_CHARS).optional(),
435
+ eyecatch_image_url: eyecatchImageUrlSchema.optional(),
436
+ categories: z
437
+ .array(z.string().max(MAX_CATEGORY_CHARS))
438
+ .max(MAX_CATEGORY_COUNT)
439
+ .optional()
440
+ .describe("空配列 [] を渡すとカテゴリを空にします"),
441
+ draft: z.boolean().optional(),
442
+ preview: z.boolean().optional(),
443
+ custom_url: z.string().max(MAX_IDENTIFIER_CHARS).optional(),
444
+ touch_updated: z
445
+ .boolean()
446
+ .optional()
447
+ .describe(
448
+ "true を指定した場合のみ現在時刻で updated を送信します (デフォルト false = 投稿日時を保持)",
449
+ ),
450
+ expected_edited: z
451
+ .string()
452
+ .max(MAX_IDENTIFIER_CHARS)
453
+ .optional()
454
+ .describe("get_entry が返した edited。現在値と異なる場合は更新せず競合エラーにします"),
455
+ },
456
+ annotations: { destructiveHint: true },
457
+ },
458
+ (args) => updateEntryHandler(args, ctx),
459
+ );
460
+
461
+ server.registerTool(
462
+ "delete_entry",
463
+ {
464
+ description: "エントリを削除します。",
465
+ inputSchema: {
466
+ blog_id: blogId,
467
+ hatena_id: hatenaIdOverride,
468
+ entry_id: identifier,
469
+ },
470
+ annotations: { destructiveHint: true, idempotentHint: true },
471
+ },
472
+ (args) => deleteEntryHandler(args, ctx),
473
+ );
474
+ }
475
+
476
+ // Re-export for convenience when other modules want the same client factory.
477
+ export type { AtomPubClient };
@@ -0,0 +1,123 @@
1
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { z } from "zod";
3
+ import { FotolifeClient } from "../../fotolife/client.js";
4
+ import type { FotolifeContentType, FotolifeImage } from "../../fotolife/types.js";
5
+ import {
6
+ MAX_IDENTIFIER_CHARS,
7
+ MAX_IMAGE_BASE64_CHARS,
8
+ MAX_TITLE_CHARS,
9
+ } from "../../utils/limits.js";
10
+ import type { ToolContext } from "../context.js";
11
+ import { ok, type ToolTextResult, toolError } from "../response.js";
12
+
13
+ const imageContentType = z.enum([
14
+ "image/png",
15
+ "image/jpeg",
16
+ "image/gif",
17
+ "image/webp",
18
+ "image/avif",
19
+ "image/bmp",
20
+ ]);
21
+
22
+ interface UploadImageArgs {
23
+ title: string;
24
+ content_type: FotolifeContentType;
25
+ data_base64: string;
26
+ folder?: string | undefined;
27
+ }
28
+
29
+ interface GetImageArgs {
30
+ image_id: string;
31
+ }
32
+
33
+ function makeFotolifeClient(ctx: ToolContext): FotolifeClient {
34
+ const options: ConstructorParameters<typeof FotolifeClient>[0] = {
35
+ credentials: ctx.credentials,
36
+ };
37
+ if (ctx.fetchImpl) options.fetchImpl = ctx.fetchImpl;
38
+ if (ctx.retry) options.retry = ctx.retry;
39
+ if (ctx.signal) options.signal = ctx.signal;
40
+ if (ctx.requestTimeoutMs !== undefined) options.requestTimeoutMs = ctx.requestTimeoutMs;
41
+ return new FotolifeClient(options);
42
+ }
43
+
44
+ function imageView(image: FotolifeImage): Record<string, unknown> {
45
+ return {
46
+ id: image.id,
47
+ title: image.title,
48
+ syntax: image.syntax,
49
+ blog_syntax: image.blogSyntax,
50
+ image_url: image.imageUrl,
51
+ ...(image.imageUrlSmall !== undefined ? { image_url_small: image.imageUrlSmall } : {}),
52
+ ...(image.pageUrl !== undefined ? { page_url: image.pageUrl } : {}),
53
+ ...(image.editUrl !== undefined ? { edit_url: image.editUrl } : {}),
54
+ ...(image.folder !== undefined ? { folder: image.folder } : {}),
55
+ ...(image.issued !== undefined ? { issued: image.issued } : {}),
56
+ };
57
+ }
58
+
59
+ export async function getImageHandler(
60
+ args: GetImageArgs,
61
+ ctx: ToolContext,
62
+ ): Promise<ToolTextResult> {
63
+ try {
64
+ const image = await makeFotolifeClient(ctx).getImage(args.image_id);
65
+ return ok(imageView(image));
66
+ } catch (err) {
67
+ return toolError(err, { operation: "get_image", requestId: ctx.requestId });
68
+ }
69
+ }
70
+
71
+ export async function uploadImageHandler(
72
+ args: UploadImageArgs,
73
+ ctx: ToolContext,
74
+ ): Promise<ToolTextResult> {
75
+ try {
76
+ const image = await makeFotolifeClient(ctx).uploadImage({
77
+ title: args.title,
78
+ contentType: args.content_type,
79
+ dataBase64: args.data_base64,
80
+ ...(args.folder !== undefined ? { folder: args.folder } : {}),
81
+ });
82
+ return ok(imageView(image));
83
+ } catch (err) {
84
+ return toolError(err, { operation: "upload_image", requestId: ctx.requestId });
85
+ }
86
+ }
87
+
88
+ export function registerImageTools(server: McpServer, ctx: ToolContext): void {
89
+ server.registerTool(
90
+ "get_image",
91
+ {
92
+ description: "はてなフォトライフの画像メタデータを1件取得します。",
93
+ inputSchema: {
94
+ image_id: z
95
+ .string()
96
+ .min(1)
97
+ .max(MAX_IDENTIFIER_CHARS)
98
+ .describe("fotolife画像ID。末尾のp/j/g付き記法も指定できます"),
99
+ },
100
+ annotations: { readOnlyHint: true },
101
+ },
102
+ (args) => getImageHandler(args, ctx),
103
+ );
104
+
105
+ server.registerTool(
106
+ "upload_image",
107
+ {
108
+ description:
109
+ "画像をはてなフォトライフへ投稿し、記事へ貼り付けられるblog_syntaxと画像URLを返します。",
110
+ inputSchema: {
111
+ title: z.string().min(1).max(MAX_TITLE_CHARS),
112
+ content_type: imageContentType,
113
+ data_base64: z
114
+ .string()
115
+ .min(1)
116
+ .max(MAX_IMAGE_BASE64_CHARS)
117
+ .describe("画像ファイル本体のbase64文字列 (最大10 MiB)"),
118
+ folder: z.string().min(1).max(MAX_TITLE_CHARS).optional().describe("省略時は Hatena Blog"),
119
+ },
120
+ },
121
+ (args) => uploadImageHandler(args, ctx),
122
+ );
123
+ }