Unsave Post or Comment
unsave_itemRemove a saved Reddit post or comment from your collection by providing its full Reddit URL.
Instructions
Remove a Reddit post or comment from your saved items list.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | Full Reddit URL of the post or comment to unsave |
Implementation Reference
- src/tools/save.ts:64-90 (handler)The handler function for the unsave_item tool. Extracts a thing ID from a Reddit URL, then calls the Reddit API /api/unsave endpoint to unsave the item. Returns success/failure response.
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/unsave", { id: thingId }); return { content: [ { type: "text" as const, text: JSON.stringify({ success: true, id: thingId, unsaved: true }, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text" as const, text: `Error unsaving: ${error instanceof Error ? error.message : String(error)}` }, ], isError: true, }; } } - src/tools/save.ts:57-62 (schema)Input validation schema for unsave_item. Accepts a single 'url' string parameter (the full Reddit URL of the post or comment to unsave).
{ title: "Unsave Post or Comment", description: "Remove a Reddit post or comment from your saved items list.", inputSchema: z.object({ url: z.string().describe("Full Reddit URL of the post or comment to unsave"), }), - src/tools/save.ts:55-91 (registration)Registration of the unsave_item tool via server.registerTool(). This is how the tool is registered with the MCP server under the name 'unsave_item'.
server.registerTool( "unsave_item", { title: "Unsave Post or Comment", description: "Remove a Reddit post or comment from your saved items list.", inputSchema: z.object({ url: z.string().describe("Full Reddit URL of the post or comment to unsave"), }), }, 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/unsave", { id: thingId }); return { content: [ { type: "text" as const, text: JSON.stringify({ success: true, id: thingId, unsaved: true }, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text" as const, text: `Error unsaving: ${error instanceof Error ? error.message : String(error)}` }, ], isError: true, }; } } ); - src/tools/save.ts:6-14 (helper)Helper function extractThingId() that parses a Reddit URL to extract the thing ID (t1_ for comments, t3_ for posts), used by the unsave_item handler.
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; } - src/index.ts:31-33 (registration)Registration call in the main entry point, where registerSaveTools (from src/tools/save.ts) is called to register all save-related tools including unsave_item.
registerSaveTools(server, client); registerInboxTools(server, client); registerSubscriptionTools(server, client);