get-blogs
Retrieve blog posts from a Shopify store using search filters and pagination controls to manage content access.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| searchTitle | No | ||
| limit | No |
Implementation Reference
- src/tools/getBlogs.ts:20-103 (handler)Core implementation of the 'get-blogs' tool, defining the tool object with name, schema, initialize, and execute handler that performs GraphQL query to fetch blogs from Shopify.const getBlogs = { name: "get-blogs", description: "Get all blogs or search by title", schema: GetBlogsInputSchema, initialize(client: GraphQLClient) { shopifyClient = client; }, execute: async (input: GetBlogsInput) => { try { const { searchTitle, limit } = input; const query = gql` query GetBlogs($first: Int!, $query: String) { blogs(first: $first, query: $query) { nodes { id handle title updatedAt commentPolicy feed { path location } createdAt templateSuffix tags } pageInfo { hasNextPage hasPreviousPage startCursor endCursor } } } `; const variables = { first: limit, query: searchTitle ? `title:*${searchTitle}*` : undefined }; const data = await shopifyClient.request(query, variables) as { blogs: { nodes: Array<{ id: string; handle: string; title: string; updatedAt: string; commentPolicy: string; feed: { path: string; location: string; } | null; createdAt: string; templateSuffix: string | null; tags: string[]; }>; pageInfo: { hasNextPage: boolean; hasPreviousPage: boolean; startCursor: string; endCursor: string; }; }; }; return { blogs: data.blogs.nodes, pageInfo: data.blogs.pageInfo }; } catch (error) { console.error("Error fetching blogs:", error); throw new Error( `Failed to fetch blogs: ${ error instanceof Error ? error.message : String(error) }` ); } } };
- src/tools/getBlogs.ts:6-9 (schema)Zod input schema for validating parameters of the 'get-blogs' tool: searchTitle (optional string) and limit (number, default 10).const GetBlogsInputSchema = z.object({ searchTitle: z.string().optional().describe("Optional search term to filter blogs by title"), limit: z.number().default(10).describe("Maximum number of blogs to return (default: 10)") });
- src/index.ts:194-206 (registration)Registers the 'get-blogs' tool with the MCP server using server.tool(), providing inline schema and handler that delegates to getBlogs.execute().server.tool( "get-blogs", { searchTitle: z.string().optional(), limit: z.number().default(10) }, async (args) => { const result = await getBlogs.execute(args); return { content: [{ type: "text", text: JSON.stringify(result) }] }; } );
- src/index.ts:18-18 (registration)Import statement for the getBlogs tool module.import { getBlogs } from "./tools/getBlogs.js";
- src/index.ts:76-76 (helper)Initializes the getBlogs tool with the Shopify GraphQL client.getBlogs.initialize(shopifyClient);