Skip to main content
Glama
jeebus87

reddirect

by jeebus87

Create Reddit Post

create_post

Post text or link content to any subreddit by specifying title, body, and optional flair. Returns the permalink.

Instructions

Create a new text or link post in a subreddit. Returns the permalink of the created post.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
subredditYesSubreddit name without r/ prefix
titleYesPost title
typeNoPost type: text (self post) or linktext
bodyNoPost body text (for text posts) or URL (for link posts)
flair_textNoFlair text to apply to the post

Implementation Reference

  • The tool 'create_post' is registered via server.registerTool() in the register() function of src/tools/post.ts. This is both the registration point and the handler implementation (the handler is the inline async function passed as the third argument).
    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,
            };
          }
        }
      );
  • Input schema for 'create_post' using Zod: requires subreddit (string), title (string), optional type (enum 'text'|'link' defaulting to 'text'), optional body (string), and optional flair_text (string).
    "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"),
      }),
    },
  • The handler function for 'create_post'. It builds params for the Reddit API (kind='self' or 'link'), calls client.post('/api/submit', params), handles errors from the API response, and returns success with permalink and id or error details.
    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,
        };
      }
    }
  • src/index.ts:29-29 (registration)
    The registration function registerPostTools (imported from ./tools/post.js) is called here with server and client, which in turn registers all post-related tools including 'create_post'.
    registerPostTools(server, client);
  • Helper: RedditClient.post() method used by the 'create_post' handler to call the Reddit API. It ensures authentication, sends POST requests with URL-encoded params and 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();
    }
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It adequately states the creation action and return value (permalink), but omits details such as required authentication, rate limits, or potential side effects. This is minimally acceptable for a creation tool.

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

Conciseness5/5

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

The description is extremely concise at two sentences, front-loading the purpose and including key return information. Every word serves a purpose without redundancy.

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

Completeness4/5

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

For a tool with five parameters and no output schema, the description sufficiently covers the core behavior and return value. It is complete enough for basic usage, though additional detail on optional parameters like flair_text would enhance completeness.

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 has 100% parameter description coverage, so the description adds limited value beyond confirming the post type (text/link) and return value. The description does not provide additional context that the schema lacks, earning a baseline score of 3.

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

Purpose5/5

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

The description clearly states the action (create a new post), specifies the resource (subreddit), and differentiates between text and link posts. The mention of returning a permalink adds further clarity. This distinguishes it from sibling tools like delete_content or edit_content.

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

Usage Guidelines3/5

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

The description implies usage when one wants to create a post, but it does not explicitly state when to use this tool versus alternatives like reply or edit_content. No exclusions or prerequisites are mentioned, which limits guidance for an AI agent.

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