Skip to main content
Glama

get_user_activity

Analyze Reddit user activity to understand posting patterns, engagement metrics, and content preferences. Provides detailed insights into user behavior and contributions across subreddits.

Instructions

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

Input Schema

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

Implementation Reference

  • Core handler function for the 'get_user_activity' tool. Fetches recent posts and comments for a Reddit user, analyzes subreddit activity, calculates engagement statistics (average/max scores, account age), determines top subreddits, and generates a comprehensive markdown report with behavioral insights.
    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}` ); } }
  • src/index.ts:389-407 (registration)
    Tool registration in the MCP server's ListTools response, defining the name, description, and input schema (username required, optional limit).
    { 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"], }, },
  • Input schema definition for the 'get_user_activity' tool, specifying parameters for username (string, required) and limit (integer, optional default 50).
    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)
    Dispatch case in the CallToolRequestHandler switch statement that routes calls to the getUserActivity function from the tools module.
    case "get_user_activity": return await tools.getUserActivity( toolParams as { username: string; limit?: number } );
  • Re-export of the getUserActivity function from user-tools.ts, making it available via the 'tools' import in index.ts.
    export * from "./user-tools"; export * from "./post-tools"; export * from "./subreddit-tools"; export * from "./search-tools";

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