Skip to main content
Glama
jeebus87

reddirect

by jeebus87

Save Post or Comment

save_item

Save any Reddit post or comment to your saved items by providing its full URL.

Instructions

Save a Reddit post or comment to your saved items list.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesFull Reddit URL of the post or comment to save

Implementation Reference

  • The tool 'save_item' is registered via server.registerTool() with name 'save_item', including schema and handler in one call.
    export function register(server: McpServer, client: RedditClient): void {
      server.registerTool(
        "save_item",
        {
          title: "Save Post or Comment",
          description: "Save a Reddit post or comment to your saved items list.",
          inputSchema: z.object({
            url: z.string().describe("Full Reddit URL of the post or comment to save"),
          }),
        },
        async ({ url }) => {
          try {
            const thingId = extractThingId(url);
            if (!thingId) {
              return {
                content: [{ type: "text" as const, text: "Could not extract ID from URL." }],
                isError: true,
              };
            }
            await client.post("/api/save", { id: thingId });
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify({ success: true, id: thingId, saved: true }, null, 2),
                },
              ],
            };
          } catch (error) {
            return {
              content: [
                { type: "text" as const, text: `Error saving: ${error instanceof Error ? error.message : String(error)}` },
              ],
              isError: true,
            };
          }
        }
      );
  • The handler function for 'save_item' that extracts a Reddit thing ID from a URL and calls client.post('/api/save', {id}) to save the item.
    async ({ url }) => {
      try {
        const thingId = extractThingId(url);
        if (!thingId) {
          return {
            content: [{ type: "text" as const, text: "Could not extract ID from URL." }],
            isError: true,
          };
        }
        await client.post("/api/save", { id: thingId });
        return {
          content: [
            {
              type: "text" as const,
              text: JSON.stringify({ success: true, id: thingId, saved: true }, null, 2),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            { type: "text" as const, text: `Error saving: ${error instanceof Error ? error.message : String(error)}` },
          ],
          isError: true,
        };
      }
    }
  • Input schema for 'save_item' defines a single required string parameter 'url' (the full Reddit URL of the post or comment to save).
    inputSchema: z.object({
      url: z.string().describe("Full Reddit URL of the post or comment to save"),
    }),
  • Helper function extractThingId() that parses a Reddit URL to extract the thing ID (t1_ for comments, t3_ for posts) used in the save API call.
    function extractThingId(url: string): string | null {
      const commentMatch = url.match(
        /\/comments\/[a-z0-9]+\/[^/]*\/([a-z0-9]+)/i
      );
      if (commentMatch) return `t1_${commentMatch[1]}`;
      const postMatch = url.match(/\/comments\/([a-z0-9]+)/i);
      if (postMatch) return `t3_${postMatch[1]}`;
      return null;
    }
  • The RedditClient.post() method called by the save_item handler. It sends a POST request to /api/save on the Reddit OAuth API with Bearer token authentication.
    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?

With no annotations, the description should disclose behavioral traits such as authentication requirements, idempotency, or side effects. It only says 'save', leaving critical details unstated.

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

Conciseness4/5

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

The description is a single clear sentence, but it could be more efficient by also including usage notes. Still, it is not verbose.

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 lack of annotations and output schema, the description fails to provide sufficient context for a state-changing operation, such as reversibility or duplicate handling.

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 documents the url parameter fully (100% coverage), so the description adds no extra meaning. Baseline of 3 is appropriate.

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 explicitly states the action ('save') and the resource ('a Reddit post or comment'), clearly differentiating it from siblings like unsave_item and get_saved_items.

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?

No guidance is provided on when to use this tool versus alternatives, nor any prerequisites like authentication. The description simply states the function without context.

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