update-blog
Modify blog settings in Shopify stores by updating the title, URL handle, template suffix, or comment policy for existing blogs.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| blogId | Yes | The GID of the blog to update (e.g., "gid://shopify/Blog/1234567890") | |
| title | No | ||
| handle | No | ||
| templateSuffix | No | ||
| commentPolicy | No |
Implementation Reference
- src/tools/updateBlog.ts:23-95 (handler)The main tool object defining the 'update-blog' tool, including its execute handler which performs a GraphQL mutation to update blog details using Shopify Admin API.const updateBlog = { name: "update-blog", description: "Updates a blog's details including title, handle, template suffix, and comment policy", schema: UpdateBlogInputSchema, initialize(client: GraphQLClient) { shopifyClient = client; }, execute: async (input: UpdateBlogInput) => { try { const { blogId, ...updateData } = input; const mutation = gql` mutation UpdateBlog($id: ID!, $blog: BlogUpdateInput!) { blogUpdate(id: $id, blog: $blog) { blog { id title handle templateSuffix commentPolicy } userErrors { field message } } } `; const variables = { id: blogId, blog: updateData }; const data = await shopifyClient.request(mutation, variables) as { blogUpdate: { blog: { id: string; title: string; handle: string; templateSuffix: string | null; commentPolicy: string; }; userErrors: Array<{ field: string; message: string; }>; }; }; if (data.blogUpdate.userErrors.length > 0) { throw new Error( `Failed to update blog: ${data.blogUpdate.userErrors .map((error) => error.message) .join(", ")}` ); } return { blog: data.blogUpdate.blog }; } catch (error) { console.error("Error updating blog:", error); throw new Error( `Failed to update blog: ${ error instanceof Error ? error.message : String(error) }` ); } } };
- src/tools/updateBlog.ts:5-12 (schema)Zod schema defining the input parameters for the update-blog tool.// Input schema for updateBlog const UpdateBlogInputSchema = z.object({ blogId: z.string().min(1).describe("The GID of the blog to update (e.g., \"gid://shopify/Blog/1234567890\")"), title: z.string().optional().describe("The new title for the blog"), handle: z.string().optional().describe("The URL-friendly handle for the blog"), templateSuffix: z.string().optional().describe("The template suffix for the blog"), commentPolicy: z.enum(["MODERATED", "CLOSED"]).optional().describe("The comment policy for the blog") });
- src/index.ts:208-224 (registration)Registration of the 'update-blog' tool with the MCP server, including inline schema and delegation to the imported tool's execute method.// Add the updateBlog tool server.tool( "update-blog", { blogId: z.string().min(1).describe("The GID of the blog to update (e.g., \"gid://shopify/Blog/1234567890\")"), title: z.string().optional(), handle: z.string().optional(), templateSuffix: z.string().optional(), commentPolicy: z.enum(["MODERATED", "CLOSED"]).optional() }, async (args) => { const result = await updateBlog.execute(args); return { content: [{ type: "text", text: JSON.stringify(result) }] }; } );