create-content-published.ts•1.26 kB
import { Tool } from '@modelcontextprotocol/sdk/types.js';
import { create } from '../client.js';
import type { ToolParameters, MicroCMSCreateOptions } from '../types.js';
import { FIELD_FORMATS_DESCRIPTION } from '../constants.js';
export const createContentPublishedTool: Tool = {
name: 'microcms_create_content_published',
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'],
},
};
export async function handleCreateContentPublished(params: ToolParameters) {
const { endpoint, content, ...options } = params;
if (!content) {
throw new Error('content is required');
}
const createOptions: MicroCMSCreateOptions = {
isDraft: false, // Always publish
};
if (options.contentId) createOptions.contentId = options.contentId;
return await create(endpoint, content, createOptions);
}