microcms_patch_content_status
Change content publication status between published and draft. Transition content to PUBLISH for publishing or DRAFT for draft.
Instructions
Change content publication status in microCMS (Management API). Can change status between PUBLISH (published) and DRAFT (draft). Note: Only transitions between "published" and "draft" are supported.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| serviceId | No | Service ID (required in multi-service mode, optional in single-service mode) | |
| endpoint | Yes | Content type name (e.g., "blogs", "news") | |
| contentId | Yes | Content ID to change status | |
| status | Yes | Target status: "PUBLISH" to publish content, "DRAFT" to set as draft |
Implementation Reference
- src/server.ts:52-55 (registration)Import of handlePatchContentStatus and patchContentStatusTool into the server module.
import { handlePatchContentStatus, patchContentStatusTool, } from './tools/patch-content-status.js'; - src/server.ts:81-81 (registration)Registration of patchContentStatusTool in the tools array for the server.
patchContentStatusTool, - src/server.ts:122-122 (registration)Maps the tool name 'microcms_patch_content_status' to the handler function handlePatchContentStatus.
microcms_patch_content_status: handlePatchContentStatus, - Tool definition with name 'microcms_patch_content_status', description, and inputSchema (serviceId, endpoint, contentId, status with enum 'PUBLISH'/'DRAFT').
export const patchContentStatusTool: Tool = { name: 'microcms_patch_content_status', description: 'Change content publication status in microCMS (Management API). Can change status between PUBLISH (published) and DRAFT (draft). Note: Only transitions between "published" and "draft" are supported.', inputSchema: { type: 'object', properties: { serviceId: { type: 'string', description: 'Service ID (required in multi-service mode, optional in single-service mode)', }, endpoint: { type: 'string', description: 'Content type name (e.g., "blogs", "news")', }, contentId: { type: 'string', description: 'Content ID to change status', }, status: { type: 'string', enum: ['PUBLISH', 'DRAFT'], description: 'Target status: "PUBLISH" to publish content, "DRAFT" to set as draft', }, }, required: ['endpoint', 'contentId', 'status'], }, }; - src/tools/patch-content-status.ts:36-56 (handler)Handler function that validates endpoint/contentId/status and calls patchContentStatus client function.
export async function handlePatchContentStatus( params: ToolParameters & { status: 'PUBLISH' | 'DRAFT' }, serviceId?: string ) { const { endpoint, contentId, status } = params; if (!endpoint) { throw new Error('endpoint is required'); } if (!contentId) { throw new Error('contentId is required'); } if (!status || (status !== 'PUBLISH' && status !== 'DRAFT')) { throw new Error('status must be either "PUBLISH" or "DRAFT"'); } await patchContentStatus(endpoint, contentId, status, serviceId); return { message: `Content ${contentId} status changed to ${status}` }; } - src/client.ts:498-522 (helper)Client helper function that sends a PATCH request to the microCMS Management API to change content publication status.
export async function patchContentStatus( endpoint: string, contentId: string, status: 'PUBLISH' | 'DRAFT', serviceId?: string ): Promise<void> { const clients = getClientsForService(serviceId); const url = `https://${clients.serviceDomain}.microcms-management.io/api/v1/contents/${endpoint}/${contentId}/status`; const response = await fetch(url, { method: 'PATCH', headers: { 'X-MICROCMS-API-KEY': clients.apiKey, 'Content-Type': 'application/json', }, body: JSON.stringify({ status: [status] }), }); if (!response.ok) { const errorText = await response.text(); throw new Error( `Failed to patch content status: ${response.status} ${response.statusText} - ${errorText}` ); } }