create-article
Create and publish articles to Shopify blogs using HTML content, author details, tags, and publication settings.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| blogId | Yes | The GID of the blog to create the article in (e.g., "gid://shopify/Blog/1234567890") | |
| title | Yes | The title of the article | |
| content | Yes | The content of the article in HTML format | |
| author | Yes | ||
| published | No | Whether to publish the article immediately | |
| tags | No | Tags to categorize the article |
Implementation Reference
- src/tools/createArticle.ts:71-127 (handler)The main handler function that executes the tool by sending a GraphQL mutation to create an article in the specified Shopify blog.execute: async (args: z.infer<typeof schema>) => { if (!createArticle.client) { throw new Error("GraphQL client not initialized"); } const variables = { article: { blogId: args.blogId, title: args.title, body: args.content, author: args.author, isPublished: args.published, tags: args.tags } }; try { const response = await createArticle.client.request<{ articleCreate: { article: { id: string; title: string; handle: string; body: string; summary: string | null; tags: string[]; author: { name: string; }; image: { altText: string | null; originalSrc: string; } | null; }; userErrors: Array<{ field: string; message: string; }>; }; }>(CREATE_ARTICLE_MUTATION, variables); if (response.articleCreate.userErrors.length > 0) { throw new Error( `Failed to create article: ${response.articleCreate.userErrors .map((error) => `${error.field}: ${error.message}`) .join(", ")}` ); } return response.articleCreate.article; } catch (error) { if (error instanceof Error) { throw new Error(`Failed to create article: ${error.message}`); } throw error; } }
- src/tools/createArticle.ts:5-14 (schema)Zod schema defining the input parameters and validation for the create-article tool.export const schema = z.object({ blogId: z.string().min(1).describe("The GID of the blog to create the article in (e.g., \"gid://shopify/Blog/1234567890\")"), title: z.string().min(1).describe("The title of the article"), content: z.string().min(1).describe("The content of the article in HTML format"), author: z.object({ name: z.string().min(1).describe("The name of the article's author") }), published: z.boolean().optional().describe("Whether to publish the article immediately"), tags: z.array(z.string()).optional().describe("Tags to categorize the article") });
- src/index.ts:297-306 (registration)Registers the create-article tool with the MCP server, delegating execution to createArticle.execute.server.tool( "create-article", createArticle.schema.shape, async (args: z.infer<typeof createArticle.schema>) => { const result = await createArticle.execute(args); return { content: [{ type: "text", text: JSON.stringify(result) }] }; } );
- src/tools/createArticle.ts:38-62 (helper)GraphQL mutation used by the handler to create the article in Shopify.const CREATE_ARTICLE_MUTATION = gql` mutation CreateArticle($article: ArticleCreateInput!) { articleCreate(article: $article) { article { id title handle body summary tags author { name } image { altText originalSrc } } userErrors { field message } } } `;