get_user_posts
Retrieve Reddit posts submitted by a specific user, with options to sort by hot, new, or top and control the number of results returned.
Instructions
Get posts submitted by a user
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes | Reddit username (without u/ prefix) | |
| sort | No | Sort order for posts | new |
| limit | No | Number of posts to retrieve (1-100) |
Implementation Reference
- src/reddit-client.ts:160-163 (handler)Core handler function in RedditClient that fetches user's submitted posts from the Reddit API endpoint `/user/{username}/submitted`, maps the response data to RedditPost objects using mapPost.async getUserPosts(username: string, sort: 'hot' | 'new' | 'top' = 'new', limit: number = 25): Promise<RedditPost[]> { const data = await this.makeRequest(`/user/${username}/submitted?sort=${sort}&limit=${limit}`); return data.data.children.map((child: any) => this.mapPost(child.data)); }
- src/index.ts:61-65 (schema)Zod schema for runtime validation of input arguments to the get_user_posts tool.const GetUserPostsSchema = z.object({ username: z.string().min(1, "Username is required"), sort: z.enum(['hot', 'new', 'top']).default('new'), limit: z.number().min(1).max(100).default(25), });
- src/index.ts:178-204 (registration)Tool registration in the MCP listTools response, defining the tool's name, description, and JSON schema for inputs.{ name: 'get_user_posts', description: 'Get posts submitted by a user', inputSchema: { type: 'object', properties: { username: { type: 'string', description: 'Reddit username (without u/ prefix)', }, sort: { type: 'string', enum: ['hot', 'new', 'top'], description: 'Sort order for posts', default: 'new', }, limit: { type: 'number', description: 'Number of posts to retrieve (1-100)', minimum: 1, maximum: 100, default: 25, }, }, required: ['username'], }, },
- src/index.ts:361-372 (handler)Dispatch handler in MCP callTool request that parses arguments with Zod schema and invokes the RedditClient.getUserPosts method, formats response as MCP content.case 'get_user_posts': { const args = GetUserPostsSchema.parse(request.params.arguments); const posts = await redditClient.getUserPosts(args.username, args.sort, args.limit); return { content: [ { type: 'text', text: JSON.stringify(posts, null, 2), }, ], }; }