Skip to main content
Glama

get-articles

Retrieve blog articles from a Shopify store by specifying a blog ID, with options to search by title and limit results.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
blogIdYesThe GID of the blog to get articles from (e.g., "gid://shopify/Blog/1234567890")
searchTitleNo
limitNo

Implementation Reference

  • Full implementation of the get-articles tool, including name, description, schema reference, initialize method, and the main execute handler that performs the GraphQL query to fetch articles.
    const getArticles = {
      name: "get-articles",
      description: "Get all articles from a blog or search by title",
      schema: GetArticlesInputSchema,
    
      initialize(client: GraphQLClient) {
        shopifyClient = client;
      },
    
      execute: async (input: GetArticlesInput) => {
        try {
          const { blogId, searchTitle, limit } = input;
    
          const query = gql`
            query GetArticles($blogId: ID!, $first: Int!) {
              blog(id: $blogId) {
                id
                title
                articles(first: $first) {
                  edges {
                    node {
                      id
                      title
                      handle
                      author {
                        name
                      }
                      publishedAt
                      tags
                      image {
                        id
                        url
                        altText
                      }
                      comments(first: 0) {
                        pageInfo {
                          hasNextPage
                          hasPreviousPage
                        }
                      }
                    }
                  }
                  pageInfo {
                    hasNextPage
                    hasPreviousPage
                    startCursor
                    endCursor
                  }
                }
              }
            }
          `;
    
          const variables = {
            blogId,
            first: limit
          };
    
          const data = await shopifyClient.request(query, variables) as {
            blog: {
              id: string;
              title: string;
              articles: {
                edges: Array<{
                  node: {
                    id: string;
                    title: string;
                    handle: string;
                    author: {
                      name: string;
                    } | null;
                    publishedAt: string;
                    tags: string[];
                    image: {
                      id: string;
                      url: string;
                      altText: string | null;
                    } | null;
                    comments: {
                      pageInfo: {
                        hasNextPage: boolean;
                        hasPreviousPage: boolean;
                      };
                    };
                  };
                }>;
                pageInfo: {
                  hasNextPage: boolean;
                  hasPreviousPage: boolean;
                  startCursor: string;
                  endCursor: string;
                };
              };
            };
          };
    
          return { 
            blogId: data.blog.id,
            blogTitle: data.blog.title,
            articles: data.blog.articles.edges.map(edge => ({
              id: edge.node.id,
              title: edge.node.title,
              handle: edge.node.handle,
              author: edge.node.author,
              publishedAt: edge.node.publishedAt,
              tags: edge.node.tags,
              image: edge.node.image,
              hasComments: edge.node.comments.pageInfo.hasNextPage || edge.node.comments.pageInfo.hasPreviousPage
            })),
            pageInfo: data.blog.articles.pageInfo
          };
        } catch (error) {
          console.error("Error fetching articles:", error);
          throw new Error(
            `Failed to fetch articles: ${
              error instanceof Error ? error.message : String(error)
            }`
          );
        }
      }
    };
  • Zod input schema definition for validating parameters to the get-articles tool.
    const GetArticlesInputSchema = z.object({
      blogId: z.string().min(1).describe("The GID of the blog to get articles from (e.g., \"gid://shopify/Blog/1234567890\")"),
      searchTitle: z.string().optional().describe("Optional search term to filter articles by title"),
      limit: z.number().default(10).describe("Maximum number of articles to return (default: 10)")
    });
  • src/index.ts:227-240 (registration)
    Registration of the get-articles tool in the MCP server, including inline schema and wrapper that calls the tool's execute method.
    server.tool(
      "get-articles",
      {
        blogId: z.string().min(1).describe("The GID of the blog to get articles from (e.g., \"gid://shopify/Blog/1234567890\")"),
        searchTitle: z.string().optional(),
        limit: z.number().default(10)
      },
      async (args) => {
        const result = await getArticles.execute(args);
        return {
          content: [{ type: "text", text: JSON.stringify(result) }]
        };
      }
    );
  • src/index.ts:78-78 (registration)
    Initialization call for the getArticles tool with the Shopify GraphQL client.
    getArticles.initialize(shopifyClient);
  • src/index.ts:20-20 (registration)
    Import of the getArticles tool implementation.
    import { getArticles } from "./tools/getArticles.js";

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/luckyfarnon/Shopify-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server