Skip to main content
Glama

get_user_posts

Retrieve a Reddit user's post history to analyze their contributions, with options to sort by new, top, or hot posts and control the number of results returned.

Instructions

Obtenir l'historique des posts d'un utilisateur

Input Schema

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

Implementation Reference

  • The main handler function for the 'get_user_posts' MCP tool. It fetches the user's posts using the Reddit client, formats them into a structured Markdown response with details like title, subreddit, score, comments, date, and link.
    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}`
        );
      }
    }
  • The input schema and metadata for the 'get_user_posts' tool, defined in the listTools response.
    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)
    The dispatch handler in the CallToolRequestSchema that routes 'get_user_posts' calls to the tools.getUserPosts function.
    case "get_user_posts":
      return await tools.getUserPosts(
        toolParams as { username: string; sort?: string; limit?: number }
      );
  • The RedditClient method that fetches raw user posts from the Reddit API, called by the main handler.
    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}`);
      }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure but offers minimal information. It doesn't mention whether this is a read-only operation (implied by 'get'), rate limits, authentication requirements, pagination behavior, or what happens if the user doesn't exist. For a tool with 3 parameters and no annotation coverage, this is inadequate.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence in French that directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded with the core functionality.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 3 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what the tool returns (post objects? metadata?), error conditions, or behavioral constraints. The agent lacks critical context needed to use this tool effectively beyond basic parameter passing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all parameters (username, sort, limit) with descriptions, enum values, defaults, and requirements. The description adds no parameter-specific information beyond what's in the schema, meeting the baseline for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Obtenir l'historique des posts d'un utilisateur' clearly states the verb ('obtenir' - get) and resource ('historique des posts' - post history) with the target ('d'un utilisateur' - of a user). It distinguishes from siblings like get_user_comments (which gets comments) and get_user_info (which gets profile info), but doesn't explicitly differentiate from get_user_activity which might overlap.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to choose get_user_posts over get_user_activity, get_user_comments, or search_posts, nor does it specify prerequisites or exclusions. The agent must infer usage from the name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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