Skip to main content
Glama
liuyang1520

Reddit MCP Server

by liuyang1520

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
NameRequiredDescriptionDefault
usernameYesReddit username (without u/ prefix)
sortNoSort order for postsnew
limitNoNumber of posts to retrieve (1-100)

Implementation Reference

  • 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)); }
  • 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'], }, },
  • 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), }, ], }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/liuyang1520/reddit-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server