Skip to main content
Glama

get_user_posts

Retrieve a Reddit user's post history with sorting options to analyze their content contributions and activity patterns on the platform.

Instructions

Obtenir l'historique des posts d'un utilisateur

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoNombre de posts à récupérer
sortNoMéthode de tri (new, top, hot)new
usernameYesLe nom d'utilisateur Reddit

Implementation Reference

  • Main handler function for the 'get_user_posts' tool. Extracts parameters, fetches posts using Reddit client, formats them into a markdown response, and handles errors.
    export async function getUserPosts(params: { username: string; sort?: string; limit?: number }) { const { username, sort = "new", limit = 25 } = params; const client = getRedditClient(); if (!client) { throw new McpError( ErrorCode.InternalError, "Reddit client not initialized" ); } try { console.log(`[Tool] Getting posts for u/${username}`); const posts = await client.getUserPosts(username, sort, limit); if (posts.length === 0) { return { content: [ { type: "text", text: `# Posts de u/${username}\n\nAucun post trouvé pour cet utilisateur.`, }, ], }; } const postsText = posts.map((post, index) => { const postedDate = new Date(post.createdUtc * 1000).toLocaleString('fr-FR'); const scoreText = post.score >= 0 ? `+${post.score}` : `${post.score}`; return ` ### ${index + 1}. ${post.title} - **Subreddit**: r/${post.subreddit} - **Score**: ${scoreText} (${Math.round(post.upvoteRatio * 100)}% positifs) - **Commentaires**: ${post.numComments} - **Type**: ${post.isSelf ? 'Post texte' : 'Lien'} - **Posté**: ${postedDate} ${post.linkFlairText ? `- **Flair**: ${post.linkFlairText}` : ''} - **Lien**: https://reddit.com${post.permalink} ${post.selftext && post.selftext.length > 0 ? `\n**Contenu**: ${post.selftext.substring(0, 200)}${post.selftext.length > 200 ? '...' : ''}` : ''} `; }).join('\n'); return { content: [ { type: "text", text: `# Posts récents de u/${username} **Tri**: ${sort} **Nombre de posts**: ${posts.length} ${postsText}`, }, ], }; } catch (error) { console.error(`[Error] Error getting user posts: ${error}`); throw new McpError( ErrorCode.InternalError, `Failed to fetch user posts: ${error}` ); } }
  • Input schema definition for the get_user_posts tool, including parameters, types, descriptions, defaults, and required fields.
    name: "get_user_posts", description: "Obtenir l'historique des posts d'un utilisateur", inputSchema: { type: "object", properties: { username: { type: "string", description: "Le nom d'utilisateur Reddit", }, sort: { type: "string", description: "Méthode de tri (new, top, hot)", enum: ["new", "top", "hot"], default: "new", }, limit: { type: "integer", description: "Nombre de posts à récupérer", default: 25, }, }, required: ["username"], },
  • src/index.ts:503-506 (registration)
    Registration in the MCP server request handler: switch case that dispatches CallToolRequest to the getUserPosts tool function.
    case "get_user_posts": return await tools.getUserPosts( toolParams as { username: string; sort?: string; limit?: number } );
  • Helper method in RedditClient class that makes the actual API call to fetch user's submitted posts from Reddit.
    async getUserPosts(username: string, sort: string = "new", limit: number = 25): Promise<RedditPost[]> { await this.authenticate(); try { const response = await this.api.get(`/user/${username}/submitted.json`, { params: { sort, limit, }, }); return response.data.data.children.map((child: any) => { const post = child.data; return { id: post.id, title: post.title, author: post.author, subreddit: post.subreddit, selftext: post.selftext, url: post.url, score: post.score, upvoteRatio: post.upvote_ratio, numComments: post.num_comments, createdUtc: post.created_utc, over18: post.over_18, spoiler: post.spoiler, edited: !!post.edited, isSelf: post.is_self, linkFlairText: post.link_flair_text, permalink: post.permalink, }; }); } catch (error) { console.error(`[Error] Failed to get user posts for ${username}:`, error); throw new Error(`Failed to get user posts for ${username}`); }

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/samy-clivolt/reddit-mcp-server'

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