Delete Post or Comment
delete_contentDelete your Reddit post or comment by submitting its full URL.
Instructions
Delete your own Reddit post or comment.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | Full Reddit URL of your post or comment to delete |
Implementation Reference
- src/tools/post.ts:259-261 (registration)Registration of the 'delete_content' tool with the MCP server. Registers the tool name, title, description, and input schema for deleting a Reddit post or comment.
server.registerTool( "delete_content", { - src/tools/post.ts:264-268 (schema)Input schema for 'delete_content': requires a 'url' string parameter (full Reddit URL of the post or comment to delete).
inputSchema: z.object({ url: z .string() .describe("Full Reddit URL of your post or comment to delete"), }), - src/tools/post.ts:270-311 (handler)Handler function that executes the delete logic. Extracts the thing ID from the URL using extractThingId, then calls client.post('/api/del', { id: thingId }) to delete the post or comment. Returns success/failure response.
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, }; } } ); - src/tools/post.ts:5-15 (helper)Helper function extractThingId that parses a Reddit URL to extract the post/comment ID (t3_ for posts, t1_ for comments).
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; } - src/reddit/client.ts:159-185 (helper)RedditClient.post method used by the delete handler to make the POST request to /api/del endpoint.
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(); }