update_content_type
Modify an existing content type by updating its title, schema, field rules, and options. Use this MCP server tool to adjust content structure, visibility conditions, and URL patterns efficiently.
Instructions
Updates an existing content type identified by its UID. Allows modification of title, schema, options, and field rules.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| field_rules | No | Field visibility rules for showing/hiding fields based on conditions | |
| options | No | Content type options like webpage/content block settings and URL patterns | |
| schema | No | Array of schema fields defining the content structure. Each field object should include properties like: - display_name: Field display name - uid: Unique identifier for the field - data_type: Type of data (text, number, boolean, file, etc.) - field_metadata: Additional metadata for the field - multiple: Whether field accepts multiple values - mandatory: Whether field is required - unique: Whether field values must be unique | |
| title | No | New content type title | |
| uid | Yes | Content type UID to update |
Implementation Reference
- src/index.ts:454-542 (handler)The handler function for the 'update_content_type' tool. It fetches the existing content type details, merges the provided updates (title, schema, options, field_rules) with the current data, constructs the payload, performs a PUT request to the Contentstack API endpoint `/content_types/{uid}`, and returns success or detailed error message.async ({ uid, title, schema, options, field_rules }) => { try { // First fetch existing content type const fetchResponse = await axios.get<ContentTypeResponse>(`${API_BASE_URL}/content_types/${uid}`, { headers: getHeaders(), }) const existingContentType = fetchResponse.data.content_type // Prepare update payload const payload: ContentTypePayload = { content_type: { ...existingContentType, title: title || existingContentType.title, schema: schema ? (schema as ContentTypeSchema[]) : existingContentType.schema, }, } // Update options if provided if (options) { payload.content_type.options = { ...existingContentType.options, ...options, } } // Update field_rules if provided if (field_rules) { payload.content_type.field_rules = field_rules as ContentTypeFieldRule[] } // Update content type const response = await axios.put<ContentTypeResponse>(`${API_BASE_URL}/content_types/${uid}`, payload, { headers: getHeaders(), }) return { content: [ { type: 'text', text: `Content type "${uid}" updated successfully.`, }, ], } } catch (error) { const errorMessage = handleError(error as ApiError) return { content: [ { type: 'text', text: `Error updating content type: ${errorMessage}\n\nPlease ensure your schema adheres to the Contentstack schema specification. Schema should be an array of field objects. Example field objects: // Single line text field example { "display_name": "Field Name", "uid": "field_uid", "data_type": "text", "field_metadata": { "description": "Field description" }, "multiple": false, "mandatory": false, "unique": false } // Select field example { "display_name": "Category", "uid": "category", "data_type": "text", "display_type": "dropdown", "enum": { "advanced": false, "choices": [ {"value": "Technology"}, {"value": "Finance"}, {"value": "Health"} ] }, "multiple": true, "mandatory": false, "unique": false }`, }, ], isError: true, } } },
- src/index.ts:412-453 (schema)Input schema using Zod for validating parameters of the update_content_type tool: uid (required string), title (optional string), schema (optional array of field objects), options (optional object with content type settings), field_rules (optional array of conditional rules).{ uid: z.string().describe('Content type UID to update'), title: z.string().optional().describe('New content type title'), schema: z .array(z.object({}).passthrough()) .optional() .describe( 'Array of schema fields defining the content structure. Each field object should include properties like:\n- display_name: Field display name\n- uid: Unique identifier for the field\n- data_type: Type of data (text, number, boolean, file, etc.)\n- field_metadata: Additional metadata for the field\n- multiple: Whether field accepts multiple values\n- mandatory: Whether field is required\n- unique: Whether field values must be unique', ), options: z .object({ is_page: z.boolean().optional().describe('Set to true for webpage content types, false for content blocks'), singleton: z.boolean().optional().describe('Set to true for single content types, false for multiple'), title: z.string().optional().describe('Field to use as the title'), sub_title: z.array(z.string()).optional().describe('Fields to use as subtitles'), url_pattern: z.string().optional().describe('Default URL pattern for entries'), url_prefix: z.string().optional().describe('Path prefix for entries'), }) .optional() .describe('Content type options like webpage/content block settings and URL patterns'), field_rules: z .array( z.object({ conditions: z.array( z.object({ operand_field: z.string().describe('Field on which to apply condition'), operator: z.string().describe('Operator for condition (e.g., equals, contains)'), value: z.any().describe('Expected value for the condition'), }), ), actions: z.array( z.object({ action: z.string().describe('Action to perform (show/hide)'), target_field: z.string().describe('Field to show/hide based on condition'), }), ), match_type: z.string().describe('Whether all or any conditions should be met'), }), ) .optional() .describe('Field visibility rules for showing/hiding fields based on conditions'), },
- src/index.ts:409-543 (registration)Registration of the 'update_content_type' tool on the MCP server using server.tool(), specifying the tool name, description, input schema, and handler function.server.tool( 'update_content_type', 'Updates an existing content type identified by its UID. Allows modification of title, schema, options, and field rules.', { uid: z.string().describe('Content type UID to update'), title: z.string().optional().describe('New content type title'), schema: z .array(z.object({}).passthrough()) .optional() .describe( 'Array of schema fields defining the content structure. Each field object should include properties like:\n- display_name: Field display name\n- uid: Unique identifier for the field\n- data_type: Type of data (text, number, boolean, file, etc.)\n- field_metadata: Additional metadata for the field\n- multiple: Whether field accepts multiple values\n- mandatory: Whether field is required\n- unique: Whether field values must be unique', ), options: z .object({ is_page: z.boolean().optional().describe('Set to true for webpage content types, false for content blocks'), singleton: z.boolean().optional().describe('Set to true for single content types, false for multiple'), title: z.string().optional().describe('Field to use as the title'), sub_title: z.array(z.string()).optional().describe('Fields to use as subtitles'), url_pattern: z.string().optional().describe('Default URL pattern for entries'), url_prefix: z.string().optional().describe('Path prefix for entries'), }) .optional() .describe('Content type options like webpage/content block settings and URL patterns'), field_rules: z .array( z.object({ conditions: z.array( z.object({ operand_field: z.string().describe('Field on which to apply condition'), operator: z.string().describe('Operator for condition (e.g., equals, contains)'), value: z.any().describe('Expected value for the condition'), }), ), actions: z.array( z.object({ action: z.string().describe('Action to perform (show/hide)'), target_field: z.string().describe('Field to show/hide based on condition'), }), ), match_type: z.string().describe('Whether all or any conditions should be met'), }), ) .optional() .describe('Field visibility rules for showing/hiding fields based on conditions'), }, async ({ uid, title, schema, options, field_rules }) => { try { // First fetch existing content type const fetchResponse = await axios.get<ContentTypeResponse>(`${API_BASE_URL}/content_types/${uid}`, { headers: getHeaders(), }) const existingContentType = fetchResponse.data.content_type // Prepare update payload const payload: ContentTypePayload = { content_type: { ...existingContentType, title: title || existingContentType.title, schema: schema ? (schema as ContentTypeSchema[]) : existingContentType.schema, }, } // Update options if provided if (options) { payload.content_type.options = { ...existingContentType.options, ...options, } } // Update field_rules if provided if (field_rules) { payload.content_type.field_rules = field_rules as ContentTypeFieldRule[] } // Update content type const response = await axios.put<ContentTypeResponse>(`${API_BASE_URL}/content_types/${uid}`, payload, { headers: getHeaders(), }) return { content: [ { type: 'text', text: `Content type "${uid}" updated successfully.`, }, ], } } catch (error) { const errorMessage = handleError(error as ApiError) return { content: [ { type: 'text', text: `Error updating content type: ${errorMessage}\n\nPlease ensure your schema adheres to the Contentstack schema specification. Schema should be an array of field objects. Example field objects: // Single line text field example { "display_name": "Field Name", "uid": "field_uid", "data_type": "text", "field_metadata": { "description": "Field description" }, "multiple": false, "mandatory": false, "unique": false } // Select field example { "display_name": "Category", "uid": "category", "data_type": "text", "display_type": "dropdown", "enum": { "advanced": false, "choices": [ {"value": "Technology"}, {"value": "Finance"}, {"value": "Health"} ] }, "multiple": true, "mandatory": false, "unique": false }`, }, ], isError: true, } } }, )