Create Collection
create_collectionCreate a new content collection with optional field definitions to establish its schema in one request.
Instructions
Create a new collection. Optionally include field definitions to create the collection with its full schema in a single request.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Display name (max 60 chars) | |
| slug | Yes | URL-friendly identifier, kebab-case (max 60 chars) | |
| is_singleton | No | If true, collection can only have one entry | |
| fields | No | Array of field definitions to create with the collection |
Implementation Reference
- src/tools/collections.ts:36-99 (handler)Complete create_collection tool implementation including registration, Zod input schema validation, and async handler function that creates a collection via POST /collections API endpoint. The handler accepts name, slug, optional is_singleton flag, and optional array of field definitions.
server.registerTool("create_collection", { title: "Create Collection", description: "Create a new collection. Optionally include field definitions to create the collection with its full schema in a single request.", inputSchema: { name: z.string().describe("Display name (max 60 chars)"), slug: z .string() .describe("URL-friendly identifier, kebab-case (max 60 chars)"), is_singleton: z .boolean() .optional() .describe("If true, collection can only have one entry"), fields: z .array( z.object({ type: z .string() .describe( "Field type: text, number, richtext, boolean, date, media, relation, select, longtext, group, etc." ), label: z.string().describe("Display label"), name: z.string().describe("Field identifier in kebab-case"), 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' } })" ), children: z .array( z.object({ type: z.string(), label: z.string(), name: z.string(), description: z.string().optional(), placeholder: z.string().optional(), options: z.record(z.string(), z.unknown()).optional(), validations: z.record(z.string(), z.unknown()).optional(), }) ) .optional() .describe("Child fields (only for group type)"), }) ) .optional() .describe("Array of field definitions to create with the collection"), }, }, async ({ name, slug, is_singleton, fields }) => { const body: Record<string, unknown> = { name, slug }; if (is_singleton !== undefined) body.is_singleton = is_singleton; if (fields) body.fields = fields; const result = await client.post("/collections", body); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }); - src/tools/collections.ts:40-89 (schema)Zod input schema for create_collection tool defining the structure: name (required string, max 60 chars), slug (required string, kebab-case, max 60 chars), is_singleton (optional boolean), and fields (optional array with complex nested structure for field definitions including type, label, name, description, placeholder, options, validations, and children for group fields).
inputSchema: { name: z.string().describe("Display name (max 60 chars)"), slug: z .string() .describe("URL-friendly identifier, kebab-case (max 60 chars)"), is_singleton: z .boolean() .optional() .describe("If true, collection can only have one entry"), fields: z .array( z.object({ type: z .string() .describe( "Field type: text, number, richtext, boolean, date, media, relation, select, longtext, group, etc." ), label: z.string().describe("Display label"), name: z.string().describe("Field identifier in kebab-case"), 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' } })" ), children: z .array( z.object({ type: z.string(), label: z.string(), name: z.string(), description: z.string().optional(), placeholder: z.string().optional(), options: z.record(z.string(), z.unknown()).optional(), validations: z.record(z.string(), z.unknown()).optional(), }) ) .optional() .describe("Child fields (only for group type)"), }) ) .optional() .describe("Array of field definitions to create with the collection"), }, - src/tools/collections.ts:90-99 (handler)Async handler function that executes create_collection logic: constructs request body with name and slug, conditionally adds is_singleton and fields if provided, then calls client.post('/collections', body) and returns the JSON result.
}, async ({ name, slug, is_singleton, fields }) => { const body: Record<string, unknown> = { name, slug }; if (is_singleton !== undefined) body.is_singleton = is_singleton; if (fields) body.fields = fields; const result = await client.post("/collections", body); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }); - src/client.ts:114-122 (helper)ElmapiClient.post helper method used by create_collection handler to make HTTP POST requests to the API endpoint. Sets method, headers, and JSON body, then handles the response through handleResponse.
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); } - src/resources.ts:211-213 (helper)Documentation reference in collections guide that explains how to create a collection with fields in a single request using the create_collection tool, which is the recommended approach for efficiency.
You can create a collection and all its fields in a single request using the \`create_collection\` tool with the \`fields\` parameter. This is the recommended approach for efficiency. Group fields can include \`children\` in the same request to create nested fields.