reply_to_post
Post a reply to an existing Reddit post by providing the post ID and your response content to engage in discussions.
Instructions
Post a reply to an existing Reddit post
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | The content of the reply | |
| post_id | Yes | The ID of the post to reply to | |
| subreddit | No | The subreddit name if known (for validation) |
Implementation Reference
- src/tools/post-tools.ts:212-257 (handler)The MCP tool handler function that processes 'reply_to_post' parameters, calls RedditClient.replyToPost, formats the success response, and handles errors.export async function replyToPost(params: { post_id: string; content: string; subreddit?: string; }) { const { post_id, content, subreddit } = params; const client = getRedditClient(); if (!client) { throw new McpError( ErrorCode.InternalError, "Reddit client not initialized" ); } try { console.log(`[Tool] Replying to post ${post_id}`); const comment = await client.replyToPost(post_id, content); const formattedComment = formatCommentInfo(comment); return { content: [ { type: "text", text: ` # Reply Posted Successfully ## Comment Details - Author: u/${formattedComment.author} - Subreddit: r/${formattedComment.context.subreddit} - Thread: ${formattedComment.context.thread} - Link: ${formattedComment.link} Your reply has been successfully posted. `, }, ], }; } catch (error) { console.error(`[Error] Error replying to post: ${error}`); throw new McpError( ErrorCode.InternalError, `Failed to reply to post: ${error}` ); } }
- src/index.ts:209-229 (schema)Input schema and metadata definition for the 'reply_to_post' tool, registered in the MCP server's tool list.name: "reply_to_post", description: "Post a reply to an existing Reddit post", inputSchema: { type: "object", properties: { post_id: { type: "string", description: "The ID of the post to reply to", }, content: { type: "string", description: "The content of the reply", }, subreddit: { type: "string", description: "The subreddit name if known (for validation)", }, }, required: ["post_id", "content"], }, },
- src/index.ts:464-471 (registration)Dispatch logic in the CallToolRequestSchema handler that routes 'reply_to_post' calls to the tools.replyToPost function.case "reply_to_post": return await tools.replyToPost( toolParams as { post_id: string; content: string; subreddit?: string; } );
- src/client/reddit-client.ts:364-407 (helper)Low-level RedditClient method that handles authentication, post existence check, and API call to create the reply comment via Reddit's /api/comment endpoint.async replyToPost(postId: string, content: string): Promise<RedditComment> { await this.authenticate(); if (!this.username || !this.password) { throw new Error("User authentication required for posting replies"); } try { if (!(await this.checkPostExists(postId))) { throw new Error( `Post with ID ${postId} does not exist or is not accessible` ); } const params = new URLSearchParams(); params.append("thing_id", `t3_${postId}`); params.append("text", content); const response = await this.api.post("/api/comment", params, { headers: { "Content-Type": "application/x-www-form-urlencoded", }, }); // Extract comment data from response const commentData = response.data; return { id: commentData.id, author: this.username, body: content, score: 1, controversiality: 0, subreddit: commentData.subreddit, submissionTitle: commentData.link_title, createdUtc: Date.now() / 1000, edited: false, isSubmitter: false, permalink: commentData.permalink, }; } catch (error) { console.error(`[Error] Failed to reply to post ${postId}:`, error); throw new Error(`Failed to reply to post ${postId}`); } }