Skip to main content
Glama

create_metaobject

Create a metaobject instance by providing its type and field values. Optionally set a handle or publish status. Returns the GID for linking to products or other entities via metafields.

Instructions

Create a new metaobject (instance) of an existing type. The type must match a registered metaobject definition — call list_metaobject_definitions first if you're unsure. fields is an array of {key, value} pairs; values are always strings (JSON/reference fields take a JSON-encoded string, primitives take literal text). handle is optional; Shopify generates one from the displayName field if present. status only applies to types that have the publishable capability — passing it for non-publishable types is silently ignored. Returns the new metaobject's GID for use in subsequent set_metafield calls (e.g. linking the metaobject to a product via a metaobject_reference metafield).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
typeYesType handle from a registered metaobject definition. The definition must already exist; this tool does not create new types/schemas.
handleNoOptional URL-safe handle. If the type has a 'displayName' field, Shopify generates a handle from it; otherwise pass one here.
fieldsYesField values. Provide at least the required fields from the type's definition. Required fields without values cause a validation error.
statusNoPublish status. Only applies to types that declared the `publishable` capability — passing this for non-publishable types is silently ignored. ACTIVE = visible on storefront, DRAFT = hidden.

Implementation Reference

  • Handler for the create_metaobject tool. Calls the Shopify GraphQL metaobjectCreate mutation with type, fields, optional handle, and optional publishable status.
    server.tool(
    "create_metaobject",
    "Create a new metaobject (instance) of an existing type. The `type` must match a registered metaobject definition — call list_metaobject_definitions first if you're unsure. `fields` is an array of {key, value} pairs; values are always strings (JSON/reference fields take a JSON-encoded string, primitives take literal text). `handle` is optional; Shopify generates one from the displayName field if present. `status` only applies to types that have the `publishable` capability — passing it for non-publishable types is silently ignored. Returns the new metaobject's GID for use in subsequent set_metafield calls (e.g. linking the metaobject to a product via a metaobject_reference metafield).",
    createMetaobjectSchema,
    async (args) => {
      const metaobject: Record<string, unknown> = {
        type: args.type,
        fields: args.fields,
      };
      if (args.handle) metaobject.handle = args.handle;
      if (args.status) {
        metaobject.capabilities = {
          publishable: { status: args.status },
        };
      }
    
      const data = await client.graphql<{
        metaobjectCreate: {
          metaobject: MetaobjectNode | null;
          userErrors: ShopifyUserError[];
        };
      }>(METAOBJECT_CREATE_MUTATION, { metaobject });
      throwIfUserErrors(data.metaobjectCreate.userErrors, "metaobjectCreate");
      const m = data.metaobjectCreate.metaobject;
      if (!m) {
        return {
          content: [
            { type: "text" as const, text: "metaobjectCreate returned no metaobject." },
          ],
        };
      }
      return {
        content: [
          {
            type: "text" as const,
            text: `Created metaobject ${m.displayName ?? m.handle} (${m.type}) — ${m.id}`,
          },
        ],
      };
    },
  • Zod schema defining the input parameters for create_metaobject: type (required), handle (optional), fields (array of {key, value}), and status (ACTIVE/DRAFT, optional).
    const createMetaobjectSchema = {
      type: z
        .string()
        .describe(
          "Type handle from a registered metaobject definition. The definition must already exist; this tool does not create new types/schemas.",
        ),
      handle: z
        .string()
        .optional()
        .describe(
          "Optional URL-safe handle. If the type has a 'displayName' field, Shopify generates a handle from it; otherwise pass one here.",
        ),
      fields: z
        .array(fieldInputSchema)
        .min(1)
        .describe(
          "Field values. Provide at least the required fields from the type's definition. Required fields without values cause a validation error.",
        ),
      status: z
        .enum(["ACTIVE", "DRAFT"])
        .optional()
        .describe(
          "Publish status. Only applies to types that declared the `publishable` capability — passing this for non-publishable types is silently ignored. ACTIVE = visible on storefront, DRAFT = hidden.",
        ),
    };
  • Registration of the create_metaobject tool via server.tool() inside registerMetaobjectTools, which is called from src/server.ts (line 67).
      server.tool(
      "create_metaobject",
      "Create a new metaobject (instance) of an existing type. The `type` must match a registered metaobject definition — call list_metaobject_definitions first if you're unsure. `fields` is an array of {key, value} pairs; values are always strings (JSON/reference fields take a JSON-encoded string, primitives take literal text). `handle` is optional; Shopify generates one from the displayName field if present. `status` only applies to types that have the `publishable` capability — passing it for non-publishable types is silently ignored. Returns the new metaobject's GID for use in subsequent set_metafield calls (e.g. linking the metaobject to a product via a metaobject_reference metafield).",
      createMetaobjectSchema,
      async (args) => {
        const metaobject: Record<string, unknown> = {
          type: args.type,
          fields: args.fields,
        };
        if (args.handle) metaobject.handle = args.handle;
        if (args.status) {
          metaobject.capabilities = {
            publishable: { status: args.status },
          };
        }
    
        const data = await client.graphql<{
          metaobjectCreate: {
            metaobject: MetaobjectNode | null;
            userErrors: ShopifyUserError[];
          };
        }>(METAOBJECT_CREATE_MUTATION, { metaobject });
        throwIfUserErrors(data.metaobjectCreate.userErrors, "metaobjectCreate");
        const m = data.metaobjectCreate.metaobject;
        if (!m) {
          return {
            content: [
              { type: "text" as const, text: "metaobjectCreate returned no metaobject." },
            ],
          };
        }
        return {
          content: [
            {
              type: "text" as const,
              text: `Created metaobject ${m.displayName ?? m.handle} (${m.type}) — ${m.id}`,
            },
          ],
        };
      },
    );
  • Reusable helper schema for a single field input (key + value), used by createMetaobjectSchema's fields array.
    const fieldInputSchema = z.object({
      key: z
        .string()
        .describe(
          "Field key as declared in the metaobject definition (case-sensitive). Get the list of valid keys from list_metaobject_definitions.",
        ),
      value: z
        .string()
        .describe(
          "Field value, always serialized as a string. Primitive types take literal strings ('hello', '42', 'true'). JSON, list, and reference types take JSON-encoded strings (e.g. '\"gid://shopify/Product/123\"' for a product reference, '[1,2,3]' for a list).",
        ),
    });
  • GraphQL mutation string used by the create_metaobject handler to call Shopify's metaobjectCreate.
    const METAOBJECT_CREATE_MUTATION = /* GraphQL */ `
      mutation MetaobjectCreate($metaobject: MetaobjectCreateInput!) {
        metaobjectCreate(metaobject: $metaobject) {
          metaobject {
            id
            type
            handle
            displayName
            fields { key type value }
            capabilities { publishable { status } }
          }
          userErrors { field message code }
        }
      }
    `;
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden. It discloses handle generation behavior, silent ignoring of status for non-publishable types, and return of GID. It mentions validation errors for missing required fields but omits details on other error scenarios or rate limits.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Three sentences, front-loaded with purpose, then key details. Each sentence earns its place with no redundant or vague phrasing.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Covers main aspects: return value (GID) despite no output schema, linking to products via set_metafield. Lacks error handling beyond validation errors, but overall complete given parameter complexity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, baseline 3. Description adds significant value: explains value serialization (primitives vs JSON), handle generation from displayName, and status applicability. This goes well beyond schema descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'Create a new metaobject (instance) of an existing type' with a specific verb ('create') and resource ('metaobject'). It distinguishes from sibling tools like delete_metaobject and update_metaobject.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description advises calling list_metaobject_definitions first if unsure of the type, and explains optionality of handle and applicability of status. However, it does not explicitly state when to use this tool versus alternatives like update_metaobject.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/miller-joe/shopify-mcp'

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