Skip to main content
Glama

get_user_info

Retrieve Reddit user information including profile details and activity data by providing a username.

Instructions

Get information about a Reddit user

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
usernameYesThe username of the Reddit user to get info for

Implementation Reference

  • The core handler function for the 'get_user_info' tool. It fetches user data from Reddit using the client, formats it with formatUserInfo, and returns a formatted MCP response.
    export async function getUserInfo(params: { username: string }) { const { username } = params; const client = getRedditClient(); if (!client) { throw new McpError( ErrorCode.InternalError, "Reddit client not initialized" ); } try { console.log(`[Tool] Getting info for u/${username}`); const user = await client.getUser(username); const formattedUser = formatUserInfo(user); return { content: [ { type: "text", text: ` # User Information: u/${formattedUser.username} ## Profile Overview - Username: u/${formattedUser.username} - Karma: - Comment Karma: ${formattedUser.karma.commentKarma.toLocaleString()} - Post Karma: ${formattedUser.karma.postKarma.toLocaleString()} - Total Karma: ${formattedUser.karma.totalKarma.toLocaleString()} - Account Status: ${formattedUser.accountStatus.join(", ")} - Account Created: ${formattedUser.accountCreated} - Profile URL: ${formattedUser.profileUrl} ## Activity Analysis - ${formattedUser.activityAnalysis.replace(/\n - /g, "\n- ")} ## Recommendations - ${formattedUser.recommendations.replace(/\n - /g, "\n- ")} `, }, ], }; } catch (error) { console.error(`[Error] Error getting user info: ${error}`); throw new McpError( ErrorCode.InternalError, `Failed to fetch user data: ${error}` ); } }
  • Input schema definition for the 'get_user_info' tool, specifying the required 'username' parameter.
    inputSchema: { type: "object", properties: { username: { type: "string", description: "The username of the Reddit user to get info for", }, }, required: ["username"], },
  • src/index.ts:143-156 (registration)
    Registration of the 'get_user_info' tool in the server's listTools response, including name, description, and schema.
    { name: "get_user_info", description: "Get information about a Reddit user", inputSchema: { type: "object", properties: { username: { type: "string", description: "The username of the Reddit user to get info for", }, }, required: ["username"], }, },
  • src/index.ts:443-444 (registration)
    Dispatch logic in the callTool request handler that routes 'get_user_info' calls to the tools.getUserInfo function.
    case "get_user_info": return await tools.getUserInfo(toolParams as { username: string });
  • Helper function formatUserInfo that processes raw Reddit user data into a formatted structure used by the handler, including activity analysis and recommendations.
    export function formatUserInfo(user: RedditUser): FormattedUserInfo { const status: string[] = []; if (user.isMod) status.push("Moderator"); if (user.isGold) status.push("Reddit Gold Member"); if (user.isEmployee) status.push("Reddit Employee"); const accountAgeDays = (Date.now() / 1000 - user.createdUtc) / (24 * 3600); // age in days const karmaRatio = user.commentKarma / (user.linkKarma || 1); return { username: user.name, karma: { commentKarma: user.commentKarma, postKarma: user.linkKarma, totalKarma: user.totalKarma, }, accountStatus: status.length ? status : ["Regular User"], accountCreated: formatTimestamp(user.createdUtc), profileUrl: user.profileUrl, activityAnalysis: analyzeUserActivity( karmaRatio, user.isMod, accountAgeDays ), recommendations: getUserRecommendations( karmaRatio, user.isMod, accountAgeDays ), }; }

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