get-article-by-id
Fetch a specific article from a Shopify store using its unique GID identifier to retrieve blog content for display or analysis.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| articleId | Yes | The GID of the article to fetch (e.g., "gid://shopify/Article/1234567890") |
Implementation Reference
- src/tools/getArticleById.ts:22-71 (handler)The execute handler function that queries Shopify GraphQL API for the specific article by its GID and returns its details including title, author, blog, body, published date, and tags.
async execute(input: GetArticleByIdInput) { try { const query = gql` query GetArticleById($id: ID!) { article(id: $id) { id title handle author { name } blog { id title } body publishedAt tags } } `; const data = await shopifyClient.request(query, { id: input.articleId }) as { article: { id: string; title: string; handle: string; author: { name: string; } | null; blog: { id: string; title: string; }; body: string; publishedAt: string; tags: string[]; }; }; return { article: data.article }; } catch (error) { console.error("Error fetching article by ID:", error); throw new Error( `Failed to fetch article: ${error instanceof Error ? error.message : String(error)}` ); } } - src/tools/getArticleById.ts:5-7 (schema)Zod input schema defining the required articleId parameter.
const GetArticleByIdInputSchema = z.object({ articleId: z.string().min(1).describe("The GID of the article to fetch (e.g., \"gid://shopify/Article/1234567890\")") }); - src/index.ts:275-284 (registration)MCP server registration of the 'get-article-by-id' tool, using the schema from the tool module and delegating execution to its execute method.
server.tool( "get-article-by-id", getArticleById.schema.shape, async (args: z.infer<typeof getArticleById.schema>) => { const result = await getArticleById.execute(args); return { content: [{ type: "text", text: JSON.stringify(result) }] }; } );