Skip to main content
Glama

get_user_activity

Analyze a Reddit user's activity to understand their posting patterns, comments, and engagement across subreddits.

Instructions

Obtenir une analyse détaillée de l'activité d'un utilisateur

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoNombre d'éléments d'activité à analyser
usernameYesLe nom d'utilisateur Reddit

Implementation Reference

  • The core handler function that retrieves and analyzes a user's recent posts and comments from Reddit, computes top subreddits activity, average and max scores, account age, and provides behavioral insights in a formatted Markdown report.
    export async function getUserActivity(params: { username: string; limit?: number }) { const { username, limit = 50 } = params; const client = getRedditClient(); if (!client) { throw new McpError( ErrorCode.InternalError, "Reddit client not initialized" ); } try { console.log(`[Tool] Getting activity overview for u/${username}`); const { posts, comments } = await client.getUserOverview(username, "new", limit); const user = await client.getUser(username); // Analyser les subreddits les plus actifs const subredditActivity: { [key: string]: { posts: number; comments: number } } = {}; posts.forEach(post => { if (!subredditActivity[post.subreddit]) { subredditActivity[post.subreddit] = { posts: 0, comments: 0 }; } subredditActivity[post.subreddit].posts++; }); comments.forEach(comment => { if (!subredditActivity[comment.subreddit]) { subredditActivity[comment.subreddit] = { posts: 0, comments: 0 }; } subredditActivity[comment.subreddit].comments++; }); const topSubreddits = Object.entries(subredditActivity) .map(([name, activity]) => ({ name, total: activity.posts + activity.comments, posts: activity.posts, comments: activity.comments })) .sort((a, b) => b.total - a.total) .slice(0, 10); // Statistiques de score const postScores = posts.map(p => p.score); const commentScores = comments.map(c => c.score); const avgPostScore = postScores.length > 0 ? Math.round(postScores.reduce((a, b) => a + b, 0) / postScores.length) : 0; const avgCommentScore = commentScores.length > 0 ? Math.round(commentScores.reduce((a, b) => a + b, 0) / commentScores.length) : 0; const maxPostScore = postScores.length > 0 ? Math.max(...postScores) : 0; const maxCommentScore = commentScores.length > 0 ? Math.max(...commentScores) : 0; const accountAge = Math.floor((Date.now() / 1000 - user.createdUtc) / (24 * 60 * 60)); const topSubredditsText = topSubreddits.map((sr, index) => `${index + 1}. **r/${sr.name}** - ${sr.total} activités (${sr.posts} posts, ${sr.comments} commentaires)` ).join('\n'); return { content: [ { type: "text", text: `# Analyse d'activité détaillée - u/${username} ## 📊 Statistiques générales - **Âge du compte**: ${accountAge} jours - **Karma total**: ${user.totalKarma.toLocaleString()} - **Posts récents analysés**: ${posts.length} - **Commentaires récents analysés**: ${comments.length} ## 📈 Performance - **Score moyen des posts**: ${avgPostScore} - **Score moyen des commentaires**: ${avgCommentScore} - **Meilleur post**: ${maxPostScore} points - **Meilleur commentaire**: ${maxCommentScore} points ## 🎯 Subreddits les plus actifs ${topSubredditsText} ## 📅 Activité récente - **Posts dans les dernières données**: ${posts.length} - **Commentaires dans les dernières données**: ${comments.length} - **Ratio posts/commentaires**: ${posts.length > 0 ? Math.round((comments.length / posts.length) * 100) / 100 : 'N/A'} ## 💡 Analyse comportementale ${posts.length > comments.length ? '- **Profil**: Créateur de contenu - publie plus qu\'il ne commente' : '- **Profil**: Participant actif - commente plus qu\'il ne publie'} ${avgPostScore > avgCommentScore ? '- **Engagement**: Les posts génèrent plus d\'engagement que les commentaires' : '- **Engagement**: Les commentaires sont mieux reçus que les posts'} ${topSubreddits.length > 0 ? `- **Communauté principale**: Très actif dans r/${topSubreddits[0].name}` : '- **Communauté**: Activité dispersée dans plusieurs subreddits'}`, }, ], }; } catch (error) { console.error(`[Error] Error getting user activity: ${error}`); throw new McpError( ErrorCode.InternalError, `Failed to fetch user activity: ${error}` ); } }
  • The tool definition in listTools response, including name, description, and inputSchema specifying 'username' (required string) and 'limit' (optional integer, default 50).
    { name: "get_user_activity", description: "Obtenir une analyse détaillée de l'activité d'un utilisateur", inputSchema: { type: "object", properties: { username: { type: "string", description: "Le nom d'utilisateur Reddit", }, limit: { type: "integer", description: "Nombre d'éléments d'activité à analyser", default: 50, }, }, required: ["username"], }, },
  • src/index.ts:513-516 (registration)
    The switch case in the CallToolRequest handler that routes requests for 'get_user_activity' to the tools.getUserActivity function.
    case "get_user_activity": return await tools.getUserActivity( toolParams as { username: string; limit?: number } );

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