microcms_create_content_draft
Create and publish new content in microCMS by providing structured data for specific content types, ensuring proper field formatting for images, rich text, dates, and custom fields.
Instructions
Create new content in microCMS and publish it immediately.
Important
Ensure that the "content" you submit strictly adheres to the following specifications. In particular, take extra care when handling custom fields and iframe fields, as mistakes are common in their structure. Read the instructions thoroughly and construct the data precisely as described. In particular, for extended fields (iframe fields), you need to take care to call microcms_get_list tool beforehand, and set its structure to the "data" field (Detail is described below).
Field type specifications
Image fields require URL string uploaded to microCMS media library (e.g., "https://images.microcms-assets.io/assets/xxx/yyy/sample.png").
Multiple image fields use array format.
Rich editor fields expect HTML strings.
Date fields use ISO 8601 format.
Select fields use arrays.
Content reference fields use contentId strings or arrays for multiple references, and you can get contentIds from microcms_get_list tool.
Custom field exepect below struct:
iframe field (Extension field) expects the following structure for CREATE/UPDATE:
IMPORTANT: When retrieving content via API, only the "data" object content is returned (without the wrapper).
IMPORTANT: When creating/updating content, you MUST provide the full structure including id, title, description, imageUrl, updatedAt, and data.
To understand the "data" structure, ALWAYS use microcms_get_list to retrieve existing content first and examine the field structure.
"id", "title", "description", "imageUrl" are metadata displayed in the admin screen and are not included in the API GET response.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| endpoint | Yes | Content type name (e.g., "blogs", "news") | |
| content | Yes | Content data to create (JSON object). Create new content in microCMS and publish it immediately. ## Important Ensure that the "content" you submit strictly adheres to the following specifications. In particular, take extra care when handling custom fields and iframe fields, as mistakes are common in their structure. Read the instructions thoroughly and construct the data precisely as described. In particular, for extended fields (iframe fields), you need to take care to call microcms_get_list tool beforehand, and set its structure to the "data" field (Detail is described below). ## Field type specifications * Image fields require URL string uploaded to microCMS media library (e.g., "https://images.microcms-assets.io/assets/xxx/yyy/sample.png"). * Multiple image fields use array format. * Rich editor fields expect HTML strings. * Date fields use ISO 8601 format. * Select fields use arrays. * Content reference fields use contentId strings or arrays for multiple references, and you can get contentIds from microcms_get_list tool. * Custom field exepect below struct: ```json <field Id in apiFields> { "fieldId": "<target custom field id in customFields>" "key1": "<value1>", "key2": "<value2>", } ``` * iframe field (Extension field) expects the following structure for CREATE/UPDATE: ```json { "id": "some-id", "title": "some-title", "description": "some-description", "imageUrl": "https://images.microcms-assets.io/assets/xxxx/yyyy/{fileName}.png", "updatedAt": "2024-01-01T00:00:00Z", "data": { "key1": "value1", "key2": "value2" } } ``` * **IMPORTANT**: When retrieving content via API, only the "data" object content is returned (without the wrapper). * **IMPORTANT**: When creating/updating content, you MUST provide the full structure including id, title, description, imageUrl, updatedAt, and data. * To understand the "data" structure, ALWAYS use microcms_get_list to retrieve existing content first and examine the field structure. * "id", "title", "description", "imageUrl" are metadata displayed in the admin screen and are not included in the API GET response. | |
| contentId | No | Specific content ID to assign |
Implementation Reference
- src/tools/create-content-draft.ts:29-43 (handler)The handler function that implements the core logic of the tool: destructures input parameters, validates required 'content', configures draft creation options, and invokes the shared 'create' function from the client module.export async function handleCreateContentDraft(params: ToolParameters) { const { endpoint, content, ...options } = params; if (!content) { throw new Error('content is required'); } const createOptions: MicroCMSCreateOptions = { isDraft: true, // Always save as draft }; if (options.contentId) createOptions.contentId = options.contentId; return await create(endpoint, content, createOptions); }
- The tool definition including name, description, and input schema for validation of parameters: endpoint (required), content (required object), and optional contentId.export const createContentDraftTool: Tool = { name: 'microcms_create_content_draft', description: FIELD_FORMATS_DESCRIPTION, inputSchema: { type: 'object', properties: { endpoint: { type: 'string', description: 'Content type name (e.g., "blogs", "news")', }, content: { type: 'object', description: `Content data to create (JSON object). ` + FIELD_FORMATS_DESCRIPTION, }, contentId: { type: 'string', description: 'Specific content ID to assign', }, }, required: ['endpoint', 'content'], }, };
- src/server.ts:97-98 (registration)Switch case in the CallToolRequest handler that routes calls to this tool name to the specific handleCreateContentDraft function.case 'microcms_create_content_draft': result = await handleCreateContentDraft(params);
- src/server.ts:55-55 (registration)Inclusion of the createContentDraftTool in the list of tools returned by ListToolsRequest.createContentDraftTool,
- src/server.ts:13-13 (registration)Import of the tool definition and handler function from the implementation file.import { createContentDraftTool, handleCreateContentDraft } from './tools/create-content-draft.js';