Skip to main content
Glama

get_post_comments

Retrieve comments from Substack posts to analyze reader engagement and feedback. Returns commenter details, text, dates, and reactions.

Instructions

Get comments on a published post. Returns commenter name, comment body, date, and reaction counts.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
post_idYesThe post ID to get comments for
limitNoMax comments to return (default 20)

Implementation Reference

  • The handler function for get_post_comments tool. Calls the API client to fetch comments, then maps the response to extract id, name, body, date, reactions, and replies count, returning the result as formatted JSON.
    async ({ post_id, limit }) => {
      const comments = await client.getPostComments(post_id, limit);
      const summary = comments.map((c) => ({
        id: c.id,
        name: c.name,
        body: c.body,
        date: c.date,
        reactions: c.reactions,
        replies: c.children_count,
      }));
      return {
        content: [{ type: "text", text: JSON.stringify(summary, null, 2) }],
      };
    },
  • src/server.ts:142-163 (registration)
    Registration of the get_post_comments tool with MCP server. Defines the tool name, description, input schema (post_id as number, limit as optional number with default 20), and the handler function.
    server.tool(
      "get_post_comments",
      "Get comments on a published post. Returns commenter name, comment body, date, and reaction counts.",
      {
        post_id: z.number().describe("The post ID to get comments for"),
        limit: z.number().optional().default(20).describe("Max comments to return (default 20)"),
      },
      async ({ post_id, limit }) => {
        const comments = await client.getPostComments(post_id, limit);
        const summary = comments.map((c) => ({
          id: c.id,
          name: c.name,
          body: c.body,
          date: c.date,
          reactions: c.reactions,
          replies: c.children_count,
        }));
        return {
          content: [{ type: "text", text: JSON.stringify(summary, null, 2) }],
        };
      },
    );
  • API client method getPostComments that fetches comments from the Substack API endpoint /api/v1/post/{postId}/comments. Returns an array of SubstackComment objects, sliced to the specified limit.
    async getPostComments(
      postId: number,
      limit = 20,
    ): Promise<SubstackComment[]> {
      const data = await this.request<{ comments: SubstackComment[] }>(
        `${this.publicationUrl}/api/v1/post/${postId}/comments`,
      );
      const comments = data.comments || [];
      return comments.slice(0, limit);
    }
  • TypeScript interface SubstackComment defining the structure of comment objects returned by the API. Includes id, body, name, date, user_id, optional reactions map, and children_count for replies.
    export interface SubstackComment {
      id: number;
      body: string;
      body_json?: unknown;
      name: string;
      date: string;
      user_id: number;
      author_is_admin?: boolean;
      reactions?: Record<string, number>;
      children_count?: number;
    }

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/conorbronsdon/substack-mcp'

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