Skip to content

Commit 9aed3b2

Browse files
committed
add bulk_create tools
1 parent 57633c9 commit 9aed3b2

File tree

5 files changed

+194
-3
lines changed

5 files changed

+194
-3
lines changed

manifest.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": "0.2",
33
"name": "microcms-mcp-server",
44
"display_name": "microCMS MCP Server",
5-
"version": "0.7.0",
5+
"version": "0.8.0",
66
"description": "microCMSのMCP Serverです。LLMから直接コンテンツの取得や入稿ができます。",
77
"icon": "assets/icon.png",
88
"author": {
@@ -48,6 +48,14 @@
4848
"name": "microcms_create_content_draft",
4949
"description": "Create new draft content in microCMS"
5050
},
51+
{
52+
"name": "microcms_create_contents_bulk_published",
53+
"description": "Create multiple contents at once and publish them immediately in microCMS"
54+
},
55+
{
56+
"name": "microcms_create_contents_bulk_draft",
57+
"description": "Create multiple contents at once as drafts in microCMS"
58+
},
5159
{
5260
"name": "microcms_update_content_published",
5361
"description": "Update published content (full replacement) in microCMS"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "microcms-mcp-server",
3-
"version": "0.6.0",
3+
"version": "0.8.0",
44
"description": "microCMS MCP Bundle - microCMSのコンテンツAPIやマネジメントAPIを利用し、LLMからコンテンツ管理ができるMCP Bundle",
55
"main": "dist/index.js",
66
"type": "module",

src/server.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ import { deleteMediaTool, handleDeleteMedia } from './tools/delete-media.js';
2323
import { getApiInfoTool, handleGetApiInfo } from './tools/get-api-info.js';
2424
import { getApiListTool, handleGetApiList } from './tools/get-apis-list.js';
2525
import { getMemberTool, handleGetMember } from './tools/get-member.js';
26-
import type { ToolParameters, MediaToolParameters } from './types.js';
26+
import {
27+
createContentsBulkPublishedTool,
28+
createContentsBulkDraftTool,
29+
handleCreateContentsBulkPublished,
30+
handleCreateContentsBulkDraft,
31+
} from './tools/create-contents-bulk.js';
32+
import type { ToolParameters, MediaToolParameters, BulkToolParameters } from './types.js';
2733

2834
const server = new Server(
2935
{
@@ -47,6 +53,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
4753
getContentMetaTool,
4854
createContentPublishedTool,
4955
createContentDraftTool,
56+
createContentsBulkPublishedTool,
57+
createContentsBulkDraftTool,
5058
updateContentPublishedTool,
5159
updateContentDraftTool,
5260
patchContentTool,
@@ -89,6 +97,12 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
8997
case 'microcms_create_content_draft':
9098
result = await handleCreateContentDraft(params);
9199
break;
100+
case 'microcms_create_contents_bulk_published':
101+
result = await handleCreateContentsBulkPublished(params as unknown as BulkToolParameters);
102+
break;
103+
case 'microcms_create_contents_bulk_draft':
104+
result = await handleCreateContentsBulkDraft(params as unknown as BulkToolParameters);
105+
break;
92106
case 'microcms_update_content_published':
93107
result = await handleUpdateContentPublished(params);
94108
break;

src/tools/create-contents-bulk.ts

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import { Tool } from '@modelcontextprotocol/sdk/types.js';
2+
import { create } from '../client.js';
3+
import type { BulkToolParameters, BulkCreateResult } from '../types.js';
4+
import { FIELD_FORMATS_DESCRIPTION } from '../constants.js';
5+
6+
const BULK_DESCRIPTION = `
7+
Create multiple contents in microCMS at once.
8+
This tool processes contents sequentially and continues even if some fail.
9+
Results include success/failure status for each content.
10+
11+
${FIELD_FORMATS_DESCRIPTION}
12+
`;
13+
14+
export const createContentsBulkPublishedTool: Tool = {
15+
name: 'microcms_create_contents_bulk_published',
16+
description: BULK_DESCRIPTION,
17+
inputSchema: {
18+
type: 'object',
19+
properties: {
20+
endpoint: {
21+
type: 'string',
22+
description: 'Content type name (e.g., "blogs", "news")',
23+
},
24+
contents: {
25+
type: 'array',
26+
description: 'Array of contents to create',
27+
items: {
28+
type: 'object',
29+
properties: {
30+
content: {
31+
type: 'object',
32+
description: 'Content data to create (JSON object)',
33+
},
34+
contentId: {
35+
type: 'string',
36+
description: 'Specific content ID to assign (optional)',
37+
},
38+
},
39+
required: ['content'],
40+
},
41+
},
42+
},
43+
required: ['endpoint', 'contents'],
44+
},
45+
};
46+
47+
export const createContentsBulkDraftTool: Tool = {
48+
name: 'microcms_create_contents_bulk_draft',
49+
description: BULK_DESCRIPTION,
50+
inputSchema: {
51+
type: 'object',
52+
properties: {
53+
endpoint: {
54+
type: 'string',
55+
description: 'Content type name (e.g., "blogs", "news")',
56+
},
57+
contents: {
58+
type: 'array',
59+
description: 'Array of contents to create as draft',
60+
items: {
61+
type: 'object',
62+
properties: {
63+
content: {
64+
type: 'object',
65+
description: 'Content data to create (JSON object)',
66+
},
67+
contentId: {
68+
type: 'string',
69+
description: 'Specific content ID to assign (optional)',
70+
},
71+
},
72+
required: ['content'],
73+
},
74+
},
75+
},
76+
required: ['endpoint', 'contents'],
77+
},
78+
};
79+
80+
async function handleBulkCreate(
81+
params: BulkToolParameters,
82+
isDraft: boolean
83+
): Promise<BulkCreateResult> {
84+
const { endpoint, contents } = params;
85+
86+
if (!contents || !Array.isArray(contents) || contents.length === 0) {
87+
throw new Error('contents array is required and must not be empty');
88+
}
89+
90+
const results: BulkCreateResult['results'] = [];
91+
let successCount = 0;
92+
let failureCount = 0;
93+
94+
for (let i = 0; i < contents.length; i++) {
95+
const item = contents[i];
96+
97+
try {
98+
const createOptions: { isDraft: boolean; contentId?: string } = {
99+
isDraft,
100+
};
101+
102+
if (item.contentId) {
103+
createOptions.contentId = item.contentId;
104+
}
105+
106+
const result = await create(endpoint, item.content, createOptions);
107+
108+
results.push({
109+
index: i,
110+
success: true,
111+
id: result.id,
112+
});
113+
successCount++;
114+
} catch (error) {
115+
const errorMessage = error instanceof Error ? error.message : String(error);
116+
results.push({
117+
index: i,
118+
success: false,
119+
error: errorMessage,
120+
});
121+
failureCount++;
122+
}
123+
}
124+
125+
return {
126+
totalCount: contents.length,
127+
successCount,
128+
failureCount,
129+
results,
130+
};
131+
}
132+
133+
export async function handleCreateContentsBulkPublished(
134+
params: BulkToolParameters
135+
): Promise<BulkCreateResult> {
136+
return handleBulkCreate(params, false);
137+
}
138+
139+
export async function handleCreateContentsBulkDraft(
140+
params: BulkToolParameters
141+
): Promise<BulkCreateResult> {
142+
return handleBulkCreate(params, true);
143+
}
144+

src/types.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,29 @@ export interface MediaToolParameters {
9393
mimeType?: string;
9494
externalUrl?: string;
9595
url?: string;
96+
}
97+
98+
// Bulk create types
99+
export interface BulkCreateItem {
100+
content: Record<string, any>;
101+
contentId?: string;
102+
}
103+
104+
export interface BulkCreateResultItem {
105+
index: number;
106+
success: boolean;
107+
id?: string;
108+
error?: string;
109+
}
110+
111+
export interface BulkCreateResult {
112+
totalCount: number;
113+
successCount: number;
114+
failureCount: number;
115+
results: BulkCreateResultItem[];
116+
}
117+
118+
export interface BulkToolParameters {
119+
endpoint: string;
120+
contents: BulkCreateItem[];
96121
}

0 commit comments

Comments
 (0)