delete_metafield
Delete a single metafield by owner ID, namespace, and key. Use list_metafields to verify identifiers beforehand to avoid irreversible removal.
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:217-242 (handler)Handler function for the delete_metafield tool. Calls Shopify's metafieldDelete mutation with 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)Input schema for delete_metafield tool defining three required string parameters: ownerId, namespace, and key.
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:213-242 (registration)Registration of the delete_metafield tool on the MCP server via registerMetafieldTools (called from src/server.ts:61).
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:37-44 (helper)GraphQL mutation string used by the delete_metafield handler to call Shopify's metafieldDelete.
const METAFIELD_DELETE_MUTATION = /* GraphQL */ ` mutation MetafieldDelete($input: MetafieldIdentifierInput!) { metafieldDelete(input: $input) { deletedId userErrors { field message } } } `;