delete_metafield
Delete a single metafield permanently by specifying owner ID, namespace, and key. Use list_metafields to verify before deletion.
Instructions
Permanently delete a single metafield by (ownerId, namespace, key). Irreversible — the value is gone after this call. Use list_metafields first to confirm the namespace and key, since typos result in a no-op rather than an error. Other metafields on the same resource are unaffected. To delete every metafield on a resource, you'd need a list+loop pattern; this tool only deletes one at a time.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ownerId | Yes | GID of the owning resource. | |
| namespace | Yes | Metafield namespace. | |
| key | Yes | Metafield key. |
Implementation Reference
- src/tools/metafields.ts:213-242 (registration)Registration of the 'delete_metafield' tool on the MCP server, wiring it to the deleteMetafieldSchema and the async handler that calls the Shopify GraphQL mutation.
server.tool( "delete_metafield", "Permanently delete a single metafield by (ownerId, namespace, key). Irreversible — the value is gone after this call. Use list_metafields first to confirm the namespace and key, since typos result in a no-op rather than an error. Other metafields on the same resource are unaffected. To delete every metafield on a resource, you'd need a list+loop pattern; this tool only deletes one at a time.", deleteMetafieldSchema, async (args) => { const data = await client.graphql<{ metafieldDelete: { deletedId: string | null; userErrors: ShopifyUserError[]; }; }>(METAFIELD_DELETE_MUTATION, { input: { ownerId: args.ownerId, namespace: args.namespace, key: args.key, }, }); throwIfUserErrors(data.metafieldDelete.userErrors, "metafieldDelete"); return { content: [ { type: "text" as const, text: data.metafieldDelete.deletedId ? `Deleted metafield ${data.metafieldDelete.deletedId}.` : "No metafield matched; nothing deleted.", }, ], }; }, ); - src/tools/metafields.ts:217-241 (handler)Async handler function that executes the delete_metafield tool logic: calls the Shopify GraphQL metafieldDelete mutation using ownerId, namespace, and key, then returns the result.
async (args) => { const data = await client.graphql<{ metafieldDelete: { deletedId: string | null; userErrors: ShopifyUserError[]; }; }>(METAFIELD_DELETE_MUTATION, { input: { ownerId: args.ownerId, namespace: args.namespace, key: args.key, }, }); throwIfUserErrors(data.metafieldDelete.userErrors, "metafieldDelete"); return { content: [ { type: "text" as const, text: data.metafieldDelete.deletedId ? `Deleted metafield ${data.metafieldDelete.deletedId}.` : "No metafield matched; nothing deleted.", }, ], }; }, - src/tools/metafields.ts:107-111 (schema)Zod schema defining the input parameters for delete_metafield: ownerId (string), namespace (string), key (string).
const deleteMetafieldSchema = { ownerId: z.string().describe("GID of the owning resource."), namespace: z.string().describe("Metafield namespace."), key: z.string().describe("Metafield key."), }; - src/tools/metafields.ts:37-44 (helper)The METAFIELD_DELETE_MUTATION GraphQL string used by the delete_metafield handler to delete a metafield via Shopify's Admin API.
const METAFIELD_DELETE_MUTATION = /* GraphQL */ ` mutation MetafieldDelete($input: MetafieldIdentifierInput!) { metafieldDelete(input: $input) { deletedId userErrors { field message } } } `; - src/server.ts:61-69 (registration)Top-level registration call that wires registerMetafieldTools (which registers delete_metafield) into the MCP server.
registerMetafieldTools(s, shopify); registerDraftOrderTools(s, shopify); registerCollectionTools(s, shopify); registerVariantTools(s, shopify); registerFulfillmentTools(s, shopify); registerWebhookTools(s, shopify); registerMetaobjectTools(s, shopify); registerAnalyticsTools(s, shopify); registerBridgeTools(s, shopify, comfyui, config.comfyUIDefaultCkpt);