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
| Name | Required | Description | Default |
|---|---|---|---|
| post_id | Yes | The post ID to get comments for | |
| limit | No | Max comments to return (default 20) |
Implementation Reference
- src/server.ts:149-162 (handler)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) }], }; }, ); - src/api/client.ts:171-180 (helper)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); } - src/api/types.ts:81-91 (schema)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; }