Skip to main content
Glama

list_metafields

Retrieve metafields attached to a Shopify resource to inspect current custom data, filter by namespace, and audit which apps have written values before setting a metafield.

Instructions

List metafields attached to a single Shopify resource. Returns each metafield's namespace.key, type, current value, and optional description. Pass a namespace to scope the read to one app/integration's metafields (recommended when the resource has many). Empty result is normal for resources without metafields. Use this to inspect existing custom data before calling set_metafield, or to audit which apps have written what to a record.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ownerIdYesGID of the resource to read metafields from.
namespaceNoFilter to a single namespace. Omit to return all.
firstNo

Implementation Reference

  • The handler function for the 'list_metafields' tool. It executes a GraphQL query (GET_METAFIELDS_QUERY) to fetch metafields for a given ownerId, optionally filtered by namespace, and formats the results into a text response. Handles empty results and pagination hints.
    async (args) => {
      const data = await client.graphql<{
        node: {
          metafields?: {
            edges: Array<{ node: Metafield }>;
            pageInfo: { hasNextPage: boolean; endCursor?: string | null };
          };
        } | null;
      }>(GET_METAFIELDS_QUERY, {
        ownerId: args.ownerId,
        first: args.first,
        namespace: args.namespace,
      });
      if (!data.node) {
        return {
          content: [
            { type: "text" as const, text: `Owner not found: ${args.ownerId}` },
          ],
        };
      }
      const edges = data.node.metafields?.edges ?? [];
      if (edges.length === 0) {
        return {
          content: [
            {
              type: "text" as const,
              text: `No metafields on ${args.ownerId}${args.namespace ? ` (namespace=${args.namespace})` : ""}.`,
            },
          ],
        };
      }
      const lines = [
        `Found ${edges.length} metafield(s):`,
        ...edges.map(({ node }) => {
          const desc = node.description ? ` — ${node.description}` : "";
          return `  ${node.namespace}.${node.key} (${node.type}) = ${node.value}${desc}`;
        }),
      ];
      if (data.node.metafields?.pageInfo.hasNextPage) {
        lines.push("(more available; raise `first` to page further)");
      }
      return { content: [{ type: "text" as const, text: lines.join("\n") }] };
    },
  • The input schema for the 'list_metafields' tool. Defines parameters: ownerId (string, required), namespace (string, optional), and first (number, default 50, min 1, max 100).
    const listMetafieldsSchema = {
      ownerId: z.string().describe("GID of the resource to read metafields from."),
      namespace: z
        .string()
        .optional()
        .describe("Filter to a single namespace. Omit to return all."),
      first: z.number().int().min(1).max(100).default(50),
    };
  • Registration of the 'list_metafields' tool on the MCP server via server.tool(), binding the name, description, schema (listMetafieldsSchema), and handler.
    server.tool(
      "list_metafields",
      "List metafields attached to a single Shopify resource. Returns each metafield's namespace.key, type, current value, and optional description. Pass a `namespace` to scope the read to one app/integration's metafields (recommended when the resource has many). Empty result is normal for resources without metafields. Use this to inspect existing custom data before calling set_metafield, or to audit which apps have written what to a record.",
      listMetafieldsSchema,
      async (args) => {
        const data = await client.graphql<{
          node: {
            metafields?: {
              edges: Array<{ node: Metafield }>;
              pageInfo: { hasNextPage: boolean; endCursor?: string | null };
            };
          } | null;
        }>(GET_METAFIELDS_QUERY, {
          ownerId: args.ownerId,
          first: args.first,
          namespace: args.namespace,
        });
        if (!data.node) {
          return {
            content: [
              { type: "text" as const, text: `Owner not found: ${args.ownerId}` },
            ],
          };
        }
        const edges = data.node.metafields?.edges ?? [];
        if (edges.length === 0) {
          return {
            content: [
              {
                type: "text" as const,
                text: `No metafields on ${args.ownerId}${args.namespace ? ` (namespace=${args.namespace})` : ""}.`,
              },
            ],
          };
        }
        const lines = [
          `Found ${edges.length} metafield(s):`,
          ...edges.map(({ node }) => {
            const desc = node.description ? ` — ${node.description}` : "";
            return `  ${node.namespace}.${node.key} (${node.type}) = ${node.value}${desc}`;
          }),
        ];
        if (data.node.metafields?.pageInfo.hasNextPage) {
          lines.push("(more available; raise `first` to page further)");
        }
        return { content: [{ type: "text" as const, text: lines.join("\n") }] };
      },
    );
  • src/server.ts:61-61 (registration)
    Top-level registration call: registerMetafieldTools is invoked with the MCP server and Shopify client in the server setup.
    registerMetafieldTools(s, shopify);
Behavior3/5

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

With no annotations, the description carries the burden of behavioral disclosure. It notes that an empty result is normal, implying no side effects, but does not explicitly state idempotency or read-only nature. It also does not mention auth requirements or rate limits, leaving gaps for a tool with no annotations.

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?

The description is concise (4 sentences), front-loaded with the primary purpose, and each sentence adds distinct value: what it returns, recommended filtering, normalcy of empty result, and use cases. No wasted words.

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

Completeness5/5

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

Given no output schema, the description explains return values comprehensively. It covers edge cases (empty result), provides use cases (inspect before set, audit), and guides parameter usage. For a list tool with 3 parameters, this description is thorough and leaves few questions.

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

Parameters3/5

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

Schema coverage is 67% (2 of 3 params have descriptions). The description adds value for the 'namespace' parameter by explaining its purpose (scoping to one app/integration). It does not add meaning for 'first' beyond schema defaults. With high schema coverage, baseline is 3, and description provides marginal extra context.

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 the tool lists metafields attached to a single Shopify resource, and specifies what is returned (namespace.key, type, value, description). It distinguishes itself from sibling tools like set_metafield and delete_metafield by its read-only listing purpose.

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 provides explicit guidance on when to use this tool: for inspecting custom data before set_metafield or auditing app writes. It also recommends using the namespace parameter to scope the read. However, it does not explicitly state when not to use it or mention alternatives to avoid.

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