Skip to main content
Glama
jeebus87

reddirect

by jeebus87

Reply to Post or Comment

reply

Reply to any Reddit post or comment by providing its URL and your response text.

Instructions

Reply to a Reddit post or comment. Provide a full URL.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesFull Reddit URL of the post or comment to reply to
bodyYesReply text content

Implementation Reference

  • The 'register' function in src/tools/post.ts registers the 'reply' tool alongside create_post, edit_content, and delete_content on the MCP server. This is where the tool name 'reply' is bound.
    export function register(server: McpServer, client: RedditClient): void {
      server.registerTool(
        "create_post",
        {
          title: "Create Reddit Post",
          description:
            "Create a new text or link post in a subreddit. Returns the permalink of the created post.",
          inputSchema: z.object({
            subreddit: z.string().describe("Subreddit name without r/ prefix"),
            title: z.string().describe("Post title"),
            type: z
              .enum(["text", "link"])
              .default("text")
              .describe("Post type: text (self post) or link"),
            body: z
              .string()
              .optional()
              .describe("Post body text (for text posts) or URL (for link posts)"),
            flair_text: z
              .string()
              .optional()
              .describe("Flair text to apply to the post"),
          }),
        },
        async ({ subreddit, title, type, body, flair_text }) => {
          try {
            const params: Record<string, string> = {
              sr: subreddit,
              title,
              kind: type === "link" ? "link" : "self",
            };
            if (body) {
              params[type === "link" ? "url" : "text"] = body;
            }
            if (flair_text) {
              params.flair_text = flair_text;
            }
    
            const data = await client.post("/api/submit", params);
            const result = data?.json?.data;
            const errors = data?.json?.errors;
    
            if (errors && errors.length > 0) {
              return {
                content: [
                  {
                    type: "text" as const,
                    text: JSON.stringify({
                      success: false,
                      error: errors.map((e: string[]) => e.join(": ")).join("; "),
                    }, null, 2),
                  },
                ],
                isError: true,
              };
            }
    
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify(
                    {
                      success: true,
                      permalink: result?.url || null,
                      id: result?.name || result?.id || null,
                    },
                    null,
                    2
                  ),
                },
              ],
            };
          } catch (error) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: `Error creating post: ${error instanceof Error ? error.message : String(error)}`,
                },
              ],
              isError: true,
            };
          }
        }
      );
    
      server.registerTool(
        "reply",
        {
          title: "Reply to Post or Comment",
          description:
            "Reply to a Reddit post or comment. Provide a full URL.",
          inputSchema: z.object({
            url: z
              .string()
              .describe("Full Reddit URL of the post or comment to reply to"),
            body: z.string().describe("Reply text content"),
          }),
        },
        async ({ url, body }) => {
          try {
            const thingId = extractThingId(url);
            if (!thingId) {
              return {
                content: [
                  {
                    type: "text" as const,
                    text: "Could not extract post/comment ID from URL.",
                  },
                ],
                isError: true,
              };
            }
    
            const data = await client.post("/api/comment", {
              thing_id: thingId,
              text: body,
            });
    
            const errors = data?.json?.errors;
            if (errors && errors.length > 0) {
              return {
                content: [
                  {
                    type: "text" as const,
                    text: JSON.stringify({
                      success: false,
                      error: errors.map((e: string[]) => e.join(": ")).join("; "),
                    }, null, 2),
                  },
                ],
                isError: true,
              };
            }
    
            const commentData = data?.json?.data?.things?.[0]?.data;
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify(
                    {
                      success: true,
                      id: commentData?.name || null,
                      replied_to: thingId,
                    },
                    null,
                    2
                  ),
                },
              ],
            };
          } catch (error) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: `Error replying: ${error instanceof Error ? error.message : String(error)}`,
                },
              ],
              isError: true,
            };
          }
        }
      );
    
      server.registerTool(
        "edit_content",
        {
          title: "Edit Post or Comment",
          description:
            "Edit your own Reddit post or comment. Provide the URL of the content to edit.",
          inputSchema: z.object({
            url: z
              .string()
              .describe("Full Reddit URL of your post or comment to edit"),
            new_body: z.string().describe("New text content"),
          }),
        },
        async ({ url, new_body }) => {
          try {
            const thingId = extractThingId(url);
            if (!thingId) {
              return {
                content: [
                  {
                    type: "text" as const,
                    text: "Could not extract post/comment ID from URL.",
                  },
                ],
                isError: true,
              };
            }
    
            const data = await client.post("/api/editusertext", {
              thing_id: thingId,
              text: new_body,
            });
    
            const errors = data?.json?.errors;
            if (errors && errors.length > 0) {
              return {
                content: [
                  {
                    type: "text" as const,
                    text: JSON.stringify({
                      success: false,
                      error: errors.map((e: string[]) => e.join(": ")).join("; "),
                    }, null, 2),
                  },
                ],
                isError: true,
              };
            }
    
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify(
                    { success: true, id: thingId, edited: true },
                    null,
                    2
                  ),
                },
              ],
            };
          } catch (error) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: `Error editing: ${error instanceof Error ? error.message : String(error)}`,
                },
              ],
              isError: true,
            };
          }
        }
      );
    
      server.registerTool(
        "delete_content",
        {
          title: "Delete Post or Comment",
          description: "Delete your own Reddit post or comment.",
          inputSchema: z.object({
            url: z
              .string()
              .describe("Full Reddit URL of your post or comment to delete"),
          }),
        },
        async ({ url }) => {
          try {
            const thingId = extractThingId(url);
            if (!thingId) {
              return {
                content: [
                  {
                    type: "text" as const,
                    text: "Could not extract post/comment ID from URL.",
                  },
                ],
                isError: true,
              };
            }
    
            await client.post("/api/del", { id: thingId });
    
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify(
                    { success: true, id: thingId, deleted: true },
                    null,
                    2
                  ),
                },
              ],
            };
          } catch (error) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: `Error deleting: ${error instanceof Error ? error.message : String(error)}`,
                },
              ],
              isError: true,
            };
          }
        }
      );
    }
  • The handler function for the 'reply' tool. It takes 'url' and 'body' parameters, extracts the Reddit thing ID (t3_ for post, t1_ for comment) from the URL using extractThingId, posts to /api/comment with the thing_id and text, then returns success/failure JSON.
    server.registerTool(
      "reply",
      {
        title: "Reply to Post or Comment",
        description:
          "Reply to a Reddit post or comment. Provide a full URL.",
        inputSchema: z.object({
          url: z
            .string()
            .describe("Full Reddit URL of the post or comment to reply to"),
          body: z.string().describe("Reply text content"),
        }),
      },
      async ({ url, body }) => {
        try {
          const thingId = extractThingId(url);
          if (!thingId) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: "Could not extract post/comment ID from URL.",
                },
              ],
              isError: true,
            };
          }
    
          const data = await client.post("/api/comment", {
            thing_id: thingId,
            text: body,
          });
    
          const errors = data?.json?.errors;
          if (errors && errors.length > 0) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify({
                    success: false,
                    error: errors.map((e: string[]) => e.join(": ")).join("; "),
                  }, null, 2),
                },
              ],
              isError: true,
            };
          }
    
          const commentData = data?.json?.data?.things?.[0]?.data;
          return {
            content: [
              {
                type: "text" as const,
                text: JSON.stringify(
                  {
                    success: true,
                    id: commentData?.name || null,
                    replied_to: thingId,
                  },
                  null,
                  2
                ),
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text" as const,
                text: `Error replying: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
            isError: true,
          };
        }
      }
    );
  • Input schema for the 'reply' tool: requires a 'url' (string) and 'body' (string) using Zod validation.
    inputSchema: z.object({
      url: z
        .string()
        .describe("Full Reddit URL of the post or comment to reply to"),
      body: z.string().describe("Reply text content"),
    }),
  • Helper function extractThingId parses a Reddit URL to extract the thing ID. For post URLs (e.g., /r/sub/comments/abc123/...) it returns t3_<id>. For comment URLs (e.g., /r/sub/comments/postid/title/commentid/) it returns t1_<id>. Returns null if unparseable.
    function extractThingId(url: string): string | null {
      // Extract thing ID from URL like /r/sub/comments/abc123/title/
      const match = url.match(/\/comments\/([a-z0-9]+)/i);
      if (match) return `t3_${match[1]}`;
      // Or from a comment URL /r/sub/comments/postid/title/commentid/
      const commentMatch = url.match(
        /\/comments\/[a-z0-9]+\/[^/]*\/([a-z0-9]+)/i
      );
      if (commentMatch) return `t1_${commentMatch[1]}`;
      return null;
    }
  • The RedditClient.post() method handles all write API calls including the reply tool's /api/comment endpoint. It ensures auth, sets Content-Type, appends api_type=json, and returns the JSON response.
    async post(
      endpoint: string,
      body: Record<string, string>
    ): Promise<any> {
      await this.ensureToken();
      if (!this.session?.username) {
        throw new Error(
          "Write operations require authentication. Run the 'authorize' tool first to connect your Reddit account (one-time browser authorization)."
        );
      }
      const url = endpoint.startsWith("http")
        ? endpoint
        : `${OAUTH_BASE}${endpoint}`;
      const res = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          Authorization: `Bearer ${this.session!.accessToken}`,
          "User-Agent": this.userAgent,
        },
        body: new URLSearchParams({
          ...body,
          api_type: "json",
        }),
      });
      return res.json();
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description lacks behavioral details beyond the basic action. It does not disclose that replying creates a new comment (a write operation), that the URL must be a valid Reddit URL, or any side effects, authentication needs, or rate limits. Since no annotations are provided, the description carries the full burden but fails to provide sufficient transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is very short (one sentence plus an instruction), making it concise but lacking in substance. It front-loads the purpose and a key requirement, but every sentence is necessary. The brevity comes at the cost of missing important context.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity and the lack of annotations, the description is incomplete. It does not mention that the URL must point to an existing post or comment, that the user must be authorized, or how the reply will appear. The sibling tools list includes related actions, but the description does not help the agent decide when to reply vs. create or edit.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema already has 100% coverage with clear descriptions for both parameters. The description adds only 'Provide a full URL,' which emphasizes the URL requirement but does not add new semantic meaning beyond the schema. Baseline of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool replies to a Reddit post or comment and instructs to provide a full URL. It is specific about the action and resource, but does not explicitly differentiate from sibling tools like 'create_post' or 'edit_content', though the verb 'reply' implies a response to existing content.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description gives no guidance on when to use this tool versus alternatives, no context about prerequisites (e.g., the user must be logged in), and no mention of when not to use it. The only instruction is to provide a full URL, which is more of a parameter hint than usage guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/jeebus87/reddirect'

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