Skip to main content
Glama
discourse

Discourse MCP

Official
by discourse

List User Posts

discourse_list_user_posts

Retrieve user posts and replies from Discourse forums to analyze contributions, monitor activity, or gather content. Returns recent posts with pagination support for comprehensive user history.

Instructions

Get a list of user posts and replies from a Discourse instance, with the most recent first. Returns 30 posts per page by default. Use the page parameter to paginate (page 0 = offset 0, page 1 = offset 30, etc.).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
usernameYes
pageNo

Implementation Reference

  • Handler function that fetches user posts and replies from Discourse API using user_actions endpoint with filter=4,5, processes them into formatted markdown blocks with topic links, handles pagination, and returns content or error.
    async ({ username, page }, _extra: any) => {
      try {
        const { base, client } = ctx.siteState.ensureSelectedSite();
        const offset = (page || 0) * 30;
    
        // The filter parameter 4,5 corresponds to posts and replies
        const data = (await client.get(
          `/user_actions.json?offset=${offset}&username=${encodeURIComponent(username)}&filter=4,5`
        )) as any;
    
        const userActions = data?.user_actions || [];
    
        if (userActions.length === 0) {
          return {
            content: [{
              type: "text",
              text: page && page > 0
                ? `No more posts found for @${username} at page ${page}.`
                : `No posts found for @${username}.`
            }]
          };
        }
    
        const posts = userActions.map((action: any) => {
          const excerpt = action.excerpt || "";
          const truncated = action.truncated ? "..." : "";
          const date = action.created_at || "";
          const topicTitle = action.title || "";
          const topicSlug = action.slug || "";
          const topicId = action.topic_id || "";
          const postNumber = action.post_number || "";
          const categoryId = action.category_id || "";
    
          const postUrl = `${base}/t/${topicSlug}/${topicId}/${postNumber}`;
    
          return [
            `**${topicTitle}**`,
            `Posted: ${date}`,
            `Topic: ${postUrl}`,
            categoryId ? `Category ID: ${categoryId}` : undefined,
            excerpt ? `\n${excerpt}${truncated}` : undefined,
          ].filter(Boolean).join("\n");
        });
    
        const totalShown = userActions.length;
        const pageInfo = page && page > 0 ? ` (page ${page})` : "";
        const header = `Showing ${totalShown} posts for @${username}${pageInfo}:\n\n`;
        const footer = totalShown === 30 ? `\n\nTo see more posts, use page ${(page || 0) + 1}.` : "";
    
        return {
          content: [{
            type: "text",
            text: header + posts.join("\n\n---\n\n") + footer
          }]
        };
      } catch (e: any) {
        return {
          content: [{
            type: "text",
            text: `Failed to get posts for ${username}: ${e?.message || String(e)}`
          }],
          isError: true
        };
      }
    }
  • Zod input schema validating username as non-empty string and optional page as non-negative integer.
    const schema = z.object({
      username: z.string().min(1),
      page: z.number().int().min(0).optional(),
    });
  • Direct registration of the tool via server.registerTool, including name, metadata, input schema, and handler function.
    server.registerTool(
      "discourse_list_user_posts",
      {
        title: "List User Posts",
        description: "Get a list of user posts and replies from a Discourse instance, with the most recent first. Returns 30 posts per page by default. Use the page parameter to paginate (page 0 = offset 0, page 1 = offset 30, etc.).",
        inputSchema: schema.shape,
      },
      async ({ username, page }, _extra: any) => {
        try {
          const { base, client } = ctx.siteState.ensureSelectedSite();
          const offset = (page || 0) * 30;
    
          // The filter parameter 4,5 corresponds to posts and replies
          const data = (await client.get(
            `/user_actions.json?offset=${offset}&username=${encodeURIComponent(username)}&filter=4,5`
          )) as any;
    
          const userActions = data?.user_actions || [];
    
          if (userActions.length === 0) {
            return {
              content: [{
                type: "text",
                text: page && page > 0
                  ? `No more posts found for @${username} at page ${page}.`
                  : `No posts found for @${username}.`
              }]
            };
          }
    
          const posts = userActions.map((action: any) => {
            const excerpt = action.excerpt || "";
            const truncated = action.truncated ? "..." : "";
            const date = action.created_at || "";
            const topicTitle = action.title || "";
            const topicSlug = action.slug || "";
            const topicId = action.topic_id || "";
            const postNumber = action.post_number || "";
            const categoryId = action.category_id || "";
    
            const postUrl = `${base}/t/${topicSlug}/${topicId}/${postNumber}`;
    
            return [
              `**${topicTitle}**`,
              `Posted: ${date}`,
              `Topic: ${postUrl}`,
              categoryId ? `Category ID: ${categoryId}` : undefined,
              excerpt ? `\n${excerpt}${truncated}` : undefined,
            ].filter(Boolean).join("\n");
          });
    
          const totalShown = userActions.length;
          const pageInfo = page && page > 0 ? ` (page ${page})` : "";
          const header = `Showing ${totalShown} posts for @${username}${pageInfo}:\n\n`;
          const footer = totalShown === 30 ? `\n\nTo see more posts, use page ${(page || 0) + 1}.` : "";
    
          return {
            content: [{
              type: "text",
              text: header + posts.join("\n\n---\n\n") + footer
            }]
          };
        } catch (e: any) {
          return {
            content: [{
              type: "text",
              text: `Failed to get posts for ${username}: ${e?.message || String(e)}`
            }],
            isError: true
          };
        }
      }
    );
  • Top-level call to registerListUserPosts function within registerAllTools, which triggers the tool registration.
    registerListUserPosts(server, ctx, { allowWrites: false });
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: the ordering ('most recent first'), pagination details (30 posts per page, page parameter usage), and that it returns a list. It doesn't cover aspects like rate limits, authentication needs, or error handling, but for a read-only list tool, this is reasonably transparent.

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 front-loaded with the core purpose, followed by essential behavioral details (ordering, pagination). Every sentence adds value: the first states what the tool does, the second specifies default behavior and pagination mechanics. There's no wasted text, making it highly efficient.

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

Completeness4/5

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

Given the tool's moderate complexity (list operation with pagination), no annotations, and no output schema, the description is fairly complete. It covers purpose, ordering, pagination, and parameter usage. It doesn't describe the return format (e.g., structure of posts) or error cases, but for a list tool, this is a minor gap.

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

Parameters4/5

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

The input schema has 0% description coverage, so the description must compensate. It explains the 'page' parameter's semantics in detail (pagination logic with offsets), which adds significant value beyond the schema's type constraints. It doesn't explicitly describe the 'username' parameter, but its purpose is implied by the tool name and context. This partial coverage is adequate given the low schema 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 clearly states the tool's purpose: 'Get a list of user posts and replies from a Discourse instance, with the most recent first.' It specifies the verb ('Get'), resource ('user posts and replies'), and scope ('from a Discourse instance'). However, it doesn't explicitly differentiate from sibling tools like discourse_get_user or discourse_read_post, which might also retrieve user-related content.

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

Usage Guidelines3/5

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

The description implies usage by mentioning pagination ('Use the page parameter to paginate'), suggesting this tool is for retrieving multiple posts. However, it doesn't provide explicit guidance on when to use this tool versus alternatives like discourse_search or discourse_read_topic, nor does it mention any prerequisites or exclusions.

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/discourse/discourse-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server