Skip to main content
Glama
elmapicms

elmapicms-mcp-server

Official
by elmapicms

Create Field

create_field

Add 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
NameRequiredDescriptionDefault
collection_slugYesThe slug of the collection to add the field to
typeYesField type: text, number, richtext, boolean, date, media, relation, select, longtext, group, etc.
labelYesDisplay label (max 60 chars)
nameYesField identifier in kebab-case (max 60 chars)
descriptionNoField description
placeholderNoPlaceholder text
optionsNoField-specific options (e.g. { repeatable: true } for group fields)
validationsNoValidation rules (e.g. { required: { status: true, message: 'Required' } })
parent_field_idNoInternal ID of a group field to nest this field under

Implementation Reference

  • 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) }],
      };
    });
  • 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"
        ),
    },
  • 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) }],
      };
    });
  • 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);
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/elmapicms/elmapicms-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server