Skip to main content
Glama

get_user_comments

Retrieve a Reddit user's comment history to analyze their activity and contributions across the platform.

Instructions

Obtenir l'historique des commentaires d'un utilisateur

Input Schema

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

Implementation Reference

  • Main tool handler: fetches user comments from Reddit client, formats them into a structured text response with details like post, score, date, link, and truncated content.
    export async function getUserComments(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 comments for u/${username}`); const comments = await client.getUserComments(username, sort, limit); if (comments.length === 0) { return { content: [ { type: "text", text: `# Commentaires de u/${username}\n\nAucun commentaire trouvé pour cet utilisateur.`, }, ], }; } const commentsText = comments.map((comment, index) => { const postedDate = new Date(comment.createdUtc * 1000).toLocaleString('fr-FR'); const scoreText = comment.score >= 0 ? `+${comment.score}` : `${comment.score}`; const controversialText = comment.controversiality > 0 ? ' (Controversé)' : ''; return ` ### ${index + 1}. Commentaire dans r/${comment.subreddit} - **Post**: ${comment.submissionTitle} - **Score**: ${scoreText}${controversialText} - **Posté**: ${postedDate} - **Lien**: ${comment.permalink} **Contenu**: ${comment.body.substring(0, 300)}${comment.body.length > 300 ? '...' : ''} `; }).join('\n'); return { content: [ { type: "text", text: `# Commentaires récents de u/${username} **Tri**: ${sort} **Nombre de commentaires**: ${comments.length} ${commentsText}`, }, ], }; } catch (error) { console.error(`[Error] Error getting user comments: ${error}`); throw new McpError( ErrorCode.InternalError, `Failed to fetch user comments: ${error}` ); } }
  • Input schema definition for the get_user_comments tool, specifying parameters: username (required), sort (enum: new/top/hot, default new), limit (default 25).
    { name: "get_user_comments", description: "Obtenir l'historique des commentaires 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 commentaires à récupérer", default: 25, }, }, required: ["username"], }, },
  • src/index.ts:508-511 (registration)
    Tool call dispatching: handles CallToolRequest for get_user_comments by invoking tools.getUserComments with typed parameters.
    case "get_user_comments": return await tools.getUserComments( toolParams as { username: string; sort?: string; limit?: number } );
  • RedditClient helper method: authenticates and fetches user's comments via Reddit API endpoint /user/{username}/comments.json, maps response to RedditComment objects.
    async getUserComments(username: string, sort: string = "new", limit: number = 25): Promise<RedditComment[]> { await this.authenticate(); try { const response = await this.api.get(`/user/${username}/comments.json`, { params: { sort, limit, }, }); return response.data.data.children.map((child: any) => { const comment = child.data; return { id: comment.id, author: comment.author, body: comment.body, score: comment.score, controversiality: comment.controversiality, subreddit: comment.subreddit, submissionTitle: comment.link_title || "Unknown Post", createdUtc: comment.created_utc, edited: !!comment.edited, isSubmitter: comment.is_submitter, permalink: `https://reddit.com${comment.permalink}`, }; }); } catch (error) { console.error(`[Error] Failed to get user comments for ${username}:`, error); throw new Error(`Failed to get user comments 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