Vote on Post or Comment
voteCast an upvote, downvote, or remove your vote on any Reddit post or comment. Specify the full URL and direction.
Instructions
Upvote, downvote, or remove your vote on a single Reddit post or comment. One vote per call.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | Full Reddit URL of the post or comment | |
| direction | Yes | Vote direction: up, down, or unvote to remove |
Implementation Reference
- src/tools/vote.ts:15-73 (handler)The register function that registers the 'vote' tool with server.registerTool, containing the full handler logic: extracts thing ID from URL, maps direction to dir parameter, and calls Reddit API /api/vote. Returns success/error response.
export function register(server: McpServer, client: RedditClient): void { server.registerTool( "vote", { title: "Vote on Post or Comment", description: "Upvote, downvote, or remove your vote on a single Reddit post or comment. One vote per call.", inputSchema: z.object({ url: z.string().describe("Full Reddit URL of the post or comment"), direction: z .enum(["up", "down", "unvote"]) .describe("Vote direction: up, down, or unvote to remove"), }), }, async ({ url, direction }) => { 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 dir = direction === "up" ? "1" : direction === "down" ? "-1" : "0"; await client.post("/api/vote", { id: thingId, dir }); return { content: [ { type: "text" as const, text: JSON.stringify( { success: true, id: thingId, direction }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text" as const, text: `Error voting: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } } ); } - src/tools/vote.ts:22-27 (schema)Input schema for the vote tool: url (string) and direction (enum: up, down, unvote).
inputSchema: z.object({ url: z.string().describe("Full Reddit URL of the post or comment"), direction: z .enum(["up", "down", "unvote"]) .describe("Vote direction: up, down, or unvote to remove"), }), - src/index.ts:10-30 (registration)Import of the vote tool registration function in the main entry point.
import { register as registerVoteTools } from "./tools/vote.js"; import { register as registerSaveTools } from "./tools/save.js"; import { register as registerInboxTools } from "./tools/inbox.js"; import { register as registerSubscriptionTools } from "./tools/subscriptions.js"; import { DEFAULT_SESSION_PATH } from "./constants.js"; const server = new McpServer({ name: "reddirect", version: "1.0.0", }); const sessionPath = process.env.REDDIT_MCP_SESSION_PATH || DEFAULT_SESSION_PATH; const client = new RedditClient(sessionPath); registerAuthTools(server, client); registerBrowseTools(server, client); registerSearchTools(server, client); registerPostTools(server, client); registerVoteTools(server, client); - src/index.ts:30-30 (registration)Registration call for the vote tool in the main server setup.
registerVoteTools(server, client); - src/tools/vote.ts:5-13 (helper)ExtractThingId helper: parses a Reddit URL to extract the full thing ID (t1_ for comments, t3_ for posts).
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; }