Get Inbox
get_inboxRetrieve Reddit inbox messages with filters for unread, mentions, and replies. Control the number of results.
Instructions
Get your Reddit inbox messages including unread, mentions, and comment replies.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filter | No | Filter inbox by message type | all |
| limit | No | Number of messages to return |
Implementation Reference
- src/tools/inbox.ts:27-76 (handler)The async handler function that executes the 'get_inbox' tool logic. It maps the filter parameter to a Reddit API endpoint, fetches messages via client.getJson(), transforms them, and returns the result.
async ({ filter, limit }) => { try { const pathMap: Record<string, string> = { all: "/message/inbox", unread: "/message/unread", messages: "/message/messages", comment_replies: "/message/comments", post_replies: "/message/selfreply", mentions: "/message/mentions", }; const data = await client.getJson( `${pathMap[filter]}.json?limit=${limit}` ); const messages = (data?.data?.children || []).map((c: any) => { const d = c.data; return { id: d.name, type: d.was_comment ? "comment" : "message", subject: d.subject, author: d.author, body: d.body, is_unread: d.new, context_permalink: d.context ? `${BASE_URL}${d.context}` : null, createdUtc: d.created_utc, }; }); return { content: [ { type: "text" as const, text: JSON.stringify({ filter, messages }, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text" as const, text: `Error getting inbox: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } } - src/tools/inbox.ts:13-25 (schema)Input schema for the 'get_inbox' tool using Zod, defining 'filter' (enum with defaults to 'all') and 'limit' (number 1-100, default 25) parameters.
inputSchema: z.object({ filter: z .enum(["all", "unread", "messages", "comment_replies", "post_replies", "mentions"]) .default("all") .describe("Filter inbox by message type"), limit: z .number() .int() .min(1) .max(100) .default(25) .describe("Number of messages to return"), }), - src/tools/inbox.ts:6-77 (registration)Registration of the 'get_inbox' tool via server.registerTool() with name 'get_inbox', title, description, input schema, and handler callback.
export function register(server: McpServer, client: RedditClient): void { server.registerTool( "get_inbox", { title: "Get Inbox", description: "Get your Reddit inbox messages including unread, mentions, and comment replies.", inputSchema: z.object({ filter: z .enum(["all", "unread", "messages", "comment_replies", "post_replies", "mentions"]) .default("all") .describe("Filter inbox by message type"), limit: z .number() .int() .min(1) .max(100) .default(25) .describe("Number of messages to return"), }), }, async ({ filter, limit }) => { try { const pathMap: Record<string, string> = { all: "/message/inbox", unread: "/message/unread", messages: "/message/messages", comment_replies: "/message/comments", post_replies: "/message/selfreply", mentions: "/message/mentions", }; const data = await client.getJson( `${pathMap[filter]}.json?limit=${limit}` ); const messages = (data?.data?.children || []).map((c: any) => { const d = c.data; return { id: d.name, type: d.was_comment ? "comment" : "message", subject: d.subject, author: d.author, body: d.body, is_unread: d.new, context_permalink: d.context ? `${BASE_URL}${d.context}` : null, createdUtc: d.created_utc, }; }); return { content: [ { type: "text" as const, text: JSON.stringify({ filter, messages }, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text" as const, text: `Error getting inbox: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } } ); - src/index.ts:32-33 (registration)Registration call in main entry point: registerInboxTools(server, client) which invokes the register function exported from inbox.ts.
registerInboxTools(server, client); registerSubscriptionTools(server, client); - src/reddit/client.ts:147-157 (helper)The getJson helper method on RedditClient used by the inbox handler to fetch data from the Reddit API with automatic token refresh on 401.
async getJson(endpoint: string): Promise<any> { const res = await this.get(endpoint); if (res.status === 401) { // Token expired, retry this.session = null; await this.ensureToken(); const retry = await this.get(endpoint); return retry.json(); } return res.json(); }