get-blog-by-id
Retrieve specific blog details from a Shopify store using its unique GID via the GraphQL API, enabling targeted data access for store management.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| blogId | Yes | The GID of the blog to fetch (e.g., "gid://shopify/Blog/1234567890") |
Implementation Reference
- src/tools/getBlogById.ts:22-83 (handler)The 'execute' function that implements the core logic of fetching a blog by its ID using Shopify's GraphQL API.async execute(input: GetBlogByIdInput) { try { const query = gql` query GetBlogById($id: ID!) { blog(id: $id) { id title handle templateSuffix commentPolicy createdAt updatedAt articles(first: 5) { nodes { id title handle publishedAt author { name } tags } } } } `; const data = await shopifyClient.request(query, { id: input.blogId }) as { blog: { id: string; title: string; handle: string; templateSuffix: string | null; commentPolicy: string; createdAt: string; updatedAt: string; articles: { nodes: Array<{ id: string; title: string; handle: string; publishedAt: string; author: { name: string; } | null; tags: string[]; }>; }; }; }; return { blog: data.blog }; } catch (error) { console.error("Error fetching blog by ID:", error); throw new Error( `Failed to fetch blog: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/tools/getBlogById.ts:5-7 (schema)Zod input schema defining the required 'blogId' parameter.const GetBlogByIdInputSchema = z.object({ blogId: z.string().min(1).describe("The GID of the blog to fetch (e.g., \"gid://shopify/Blog/1234567890\")") });
- src/index.ts:264-273 (registration)MCP server registration of the 'get-blog-by-id' tool, using the schema and execute method from the imported tool module.server.tool( "get-blog-by-id", getBlogById.schema.shape, async (args: z.infer<typeof getBlogById.schema>) => { const result = await getBlogById.execute(args); return { content: [{ type: "text", text: JSON.stringify(result) }] }; } );