Create Field
create_fieldAdd custom fields to collections in ElmapiCMS to structure content with various data types like text, numbers, dates, media, and relationships.
Instructions
Add a new field to a collection
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection_slug | Yes | The slug of the collection to add the field to | |
| type | Yes | Field type: text, number, richtext, boolean, date, media, relation, select, longtext, group, etc. | |
| label | Yes | Display label (max 60 chars) | |
| name | Yes | Field identifier in kebab-case (max 60 chars) | |
| description | No | Field description | |
| placeholder | No | Placeholder text | |
| options | No | Field-specific options (e.g. { repeatable: true } for group fields) | |
| validations | No | Validation rules (e.g. { required: { status: true, message: 'Required' } }) | |
| parent_field_id | No | Internal ID of a group field to nest this field under |
Implementation Reference
- src/tools/fields.ts:47-55 (handler)The create_field tool handler that executes the tool logic. It extracts collection_slug from parameters, sends a POST request to the ElmapiCMS API endpoint `/collections/${collection_slug}/fields`, and returns the result as formatted JSON.
}, async ({ collection_slug, ...fieldData }) => { const result = await client.post( `/collections/${collection_slug}/fields`, fieldData ); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }); - src/tools/fields.ts:13-46 (schema)Input schema definition for create_field tool using Zod validation. Defines required parameters (collection_slug, type, label, name) and optional parameters (description, placeholder, options, validations, parent_field_id).
inputSchema: { collection_slug: z .string() .describe("The slug of the collection to add the field to"), type: z .string() .describe( "Field type: text, number, richtext, boolean, date, media, relation, select, longtext, group, etc." ), label: z.string().describe("Display label (max 60 chars)"), name: z .string() .describe("Field identifier in kebab-case (max 60 chars)"), description: z.string().optional().describe("Field description"), placeholder: z.string().optional().describe("Placeholder text"), options: z .record(z.string(), z.unknown()) .optional() .describe( "Field-specific options (e.g. { repeatable: true } for group fields)" ), validations: z .record(z.string(), z.unknown()) .optional() .describe( "Validation rules (e.g. { required: { status: true, message: 'Required' } })" ), parent_field_id: z .number() .optional() .describe( "Internal ID of a group field to nest this field under" ), }, - src/tools/fields.ts:10-55 (registration)Tool registration call using server.registerTool. Registers the create_field tool with title 'Create Field', description, input schema, and handler function within the registerFieldTools function.
server.registerTool("create_field", { title: "Create Field", description: "Add a new field to a collection", inputSchema: { collection_slug: z .string() .describe("The slug of the collection to add the field to"), type: z .string() .describe( "Field type: text, number, richtext, boolean, date, media, relation, select, longtext, group, etc." ), label: z.string().describe("Display label (max 60 chars)"), name: z .string() .describe("Field identifier in kebab-case (max 60 chars)"), description: z.string().optional().describe("Field description"), placeholder: z.string().optional().describe("Placeholder text"), options: z .record(z.string(), z.unknown()) .optional() .describe( "Field-specific options (e.g. { repeatable: true } for group fields)" ), validations: z .record(z.string(), z.unknown()) .optional() .describe( "Validation rules (e.g. { required: { status: true, message: 'Required' } })" ), parent_field_id: z .number() .optional() .describe( "Internal ID of a group field to nest this field under" ), }, }, async ({ collection_slug, ...fieldData }) => { const result = await client.post( `/collections/${collection_slug}/fields`, fieldData ); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }); - src/client.ts:114-122 (helper)The post helper method of ElmapiClient class used by the create_field handler. Performs HTTP POST requests with JSON body and handles error responses.
async post(path: string, body?: unknown): Promise<unknown> { const response = await fetch(`${this.baseUrl}${path}`, { method: "POST", headers: this.headers(), body: body ? JSON.stringify(body) : undefined, }); return this.handleResponse(response); }