friday-mcp-v2 2.0.5 → 2.0.6

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.
@@ -31,24 +31,34 @@ async function resolveMode(args) {
31
31
  }
32
32
 
33
33
  try {
34
- const status = await client.getStatus();
34
+ const requestedPostId = args?.postId ? Number(args.postId) : null;
35
+ const status = await client.getStatus(requestedPostId);
36
+
35
37
  if (status.editorConnected && status.postId) {
36
- const argPostId = args?.postId;
37
- if (argPostId && argPostId !== status.postId) {
38
- return { mode: 'headless', postId: argPostId, client };
38
+ if (requestedPostId) {
39
+ if (requestedPostId === Number(status.postId) || status.checkedEditorConnected) {
40
+ return {
41
+ mode: 'error',
42
+ message: `postId ${requestedPostId} はエディタで開かれています。postId を省略してエディタ経由で操作するか、エディタを閉じてから Headless モードを使用してください。`
43
+ };
44
+ }
45
+ return { mode: 'headless', postId: requestedPostId, client };
39
46
  }
40
47
  return { mode: 'editor', postId: status.postId, client };
41
48
  }
42
- const postId = args?.postId;
43
- if (!postId) {
49
+
50
+ if (requestedPostId && status.checkedEditorConnected) {
51
+ return {
52
+ mode: 'error',
53
+ message: `postId ${requestedPostId} はエディタで開かれています。postId を省略してエディタ経由で操作するか、エディタを閉じてから Headless モードを使用してください。`
54
+ };
55
+ }
56
+
57
+ if (!requestedPostId) {
44
58
  return { mode: 'error', message: 'エディタ未接続です。postId を指定して Headless モードを使用してください。' };
45
59
  }
46
- return { mode: 'headless', postId, client };
60
+ return { mode: 'headless', postId: requestedPostId, client };
47
61
  } catch (e) {
48
- const postId = args?.postId;
49
- if (postId) {
50
- return { mode: 'headless', postId, client };
51
- }
52
62
  return { mode: 'error', message: `接続エラー: ${e.message}` };
53
63
  }
54
64
  }
@@ -339,18 +349,16 @@ const tools = [
339
349
  },
340
350
  {
341
351
  name: "insert_block",
342
- description: "Insert a new block at the specified position. If index is omitted, inserts at the end.",
352
+ description: "Insert Gutenberg HTML at the specified position. If index is omitted, appends to end.",
343
353
  inputSchema: {
344
354
  type: "object",
345
355
  properties: {
346
356
  postId: postIdParam,
347
357
  site: siteParam,
348
- blockType: { type: "string", description: "Block type (e.g. core/paragraph, core/heading, core/list)" },
349
- content: { type: "string", description: "Block content (HTML or plain text depending on block type)" },
358
+ rawHTML: { type: "string", description: "Gutenberg markup HTML to insert (e.g. '<!-- wp:paragraph -->\\n<p>text</p>\\n<!-- /wp:paragraph -->')." },
350
359
  index: { type: "number", description: "Insert position (0-based flattened index). If omitted, appends to end." },
351
- blocks: { type: "array", items: { type: "object", properties: { blockType: { type: "string" }, content: { type: "string" } }, required: ["blockType", "content"] }, description: "Multiple blocks to insert. Cannot be used with blockType/content." },
352
- rawHTML: { type: "string", description: "Gutenberg markup HTML to insert directly. Cannot be used with blockType/content or blocks." },
353
360
  },
361
+ required: ["rawHTML"],
354
362
  },
355
363
  },
356
364
  {
@@ -1394,67 +1402,24 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1394
1402
 
1395
1403
  case "insert_block": {
1396
1404
  const { mode, postId, message, client } = await resolveMode(args);
1397
- if (mode === 'error') {
1398
- return errorResponse(name, message, args?.site);
1399
- }
1405
+ if (mode === 'error') return errorResponse(name, message, args?.site);
1400
1406
 
1401
- const { blockType, content, index, blocks, rawHTML } = args;
1402
-
1403
- // 排他バリデーション
1404
- const hasLegacy = blockType !== undefined || content !== undefined;
1405
- const hasBlocks = blocks !== undefined;
1406
- const hasRawHTML = rawHTML !== undefined;
1407
- const modeCount = [hasLegacy, hasBlocks, hasRawHTML].filter(Boolean).length;
1408
- if (modeCount === 0) {
1409
- return { content: [{ type: "text", text: "❌ blockType+content、blocks、rawHTML のいずれかを指定してください。" }], isError: true };
1410
- }
1411
- if (modeCount > 1) {
1412
- return { content: [{ type: "text", text: "❌ blockType+content、blocks、rawHTML は同時に指定できません。" }], isError: true };
1413
- }
1414
-
1415
- // 複数挿入モード (blocks / rawHTML)
1416
- if (hasBlocks || hasRawHTML) {
1417
- if (hasBlocks && (!Array.isArray(blocks) || blocks.length === 0)) {
1418
- return { content: [{ type: "text", text: "❌ blocks は1つ以上の要素を含む配列で指定してください。" }], isError: true };
1419
- }
1420
-
1421
- if (mode === 'headless') {
1422
- const params = { index };
1423
- if (hasBlocks) params.blocks = blocks;
1424
- if (hasRawHTML) params.rawHTML = rawHTML;
1425
- const result = await client.headlessInsert(postId, params);
1426
- const count = result.insertedIndices ? result.insertedIndices.length : result.count || 1;
1427
- return { content: [{ type: "text", text: `✅ ${count}ブロック挿入 at ${index ?? 'end'}` }] };
1428
- }
1429
-
1430
- const cmdParams = { index };
1431
- if (hasBlocks) cmdParams.blocks = blocks;
1432
- if (hasRawHTML) cmdParams.rawHTML = rawHTML;
1433
- const result = await client.sendEditorCommand("insert_block", cmdParams);
1434
- if (!result)
1435
- return timeoutResponse(name, client, args?.site);
1436
- if (!result.success)
1437
- return errorResponse(name, result.error, args?.site);
1438
- const count = result.insertedCount || result.inserted?.length || 1;
1439
- return { content: [{ type: "text", text: `✅ ${count}ブロック挿入 at ${index ?? 'end'}` }] };
1440
- }
1441
-
1442
- // 既存モード(単一 blockType + content)
1443
- if (!blockType || content === undefined) {
1444
- return { content: [{ type: "text", text: "❌ blockType と content は必須です" }], isError: true };
1407
+ const { rawHTML, index } = args;
1408
+ if (!rawHTML) {
1409
+ return { content: [{ type: "text", text: "❌ rawHTML を指定してください。Gutenberg HTML 形式のブロックマークアップが必要です。" }], isError: true };
1445
1410
  }
1446
1411
 
1447
1412
  if (mode === 'headless') {
1448
- const result = await client.headlessInsert(postId, { blockType, content, index });
1449
- return { content: [{ type: "text", text: `✅ ブロック挿入: ${blockType} at ${result.newIndex}` }] };
1413
+ const result = await client.headlessInsert(postId, { rawHTML, index });
1414
+ const count = result.insertedIndices ? result.insertedIndices.length : result.count || 1;
1415
+ return { content: [{ type: "text", text: `✅ ${count}ブロック挿入 at ${index ?? 'end'}` }] };
1450
1416
  }
1451
1417
 
1452
- const result = await client.sendEditorCommand("insert_block", { blockType, content, index });
1453
- if (!result)
1454
- return timeoutResponse(name, client, args?.site);
1455
- if (!result.success)
1456
- return errorResponse(name, result.error, args?.site);
1457
- return { content: [{ type: "text", text: `✅ ブロック挿入: ${result.inserted.type} at ${result.inserted.index}` }] };
1418
+ const result = await client.sendEditorCommand("insert_block", { rawHTML, index });
1419
+ if (!result) return timeoutResponse(name, client, args?.site);
1420
+ if (!result.success) return errorResponse(name, result.error, args?.site);
1421
+ const count = result.insertedCount || result.inserted?.length || 1;
1422
+ return { content: [{ type: "text", text: `✅ ${count}ブロック挿入 at ${index ?? 'end'}` }] };
1458
1423
  }
1459
1424
 
1460
1425
  case "get_block_html": {
@@ -53,8 +53,11 @@ export class FridayWPClient {
53
53
  // Status
54
54
  // ========================================
55
55
 
56
- async getStatus() {
57
- return this.request('/status');
56
+ async getStatus(checkPostId) {
57
+ const endpoint = checkPostId
58
+ ? `/status?checkPostId=${checkPostId}`
59
+ : '/status';
60
+ return this.request(endpoint);
58
61
  }
59
62
 
60
63
  // ========================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "friday-mcp-v2",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "description": "WordPress MCP Server for Claude Code - REST API direct communication",
5
5
  "type": "module",
6
6
  "main": "dist/mcp-server.js",