Skip to main content
Glama

List User Posts

discourse_list_user_posts

Retrieve user posts and replies from Discourse forums to analyze contributions or monitor activity. Supports pagination for accessing historical content.

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

  • The async handler function that fetches user posts and replies from Discourse using the user_actions API endpoint, paginates with offset, formats post details including topic title, date, URL, category, and excerpt, and returns formatted text 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 schema for tool input: required 'username' string and optional 'page' non-negative integer for pagination.
    const schema = z.object({
      username: z.string().min(1),
      page: z.number().int().min(0).optional(),
    });
  • The server.registerTool call that defines and registers the 'discourse_list_user_posts' tool with its metadata, input schema, and handler.
    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 during MCP tools initialization in registerAllTools, with read-only permissions.
    registerListUserPosts(server, ctx, { allowWrites: false });
  • Helper function exported as registerListUserPosts that encapsulates the schema, tool registration, and handler for discourse_list_user_posts.
    export const registerListUserPosts: RegisterFn = (server, ctx) => {
      const schema = z.object({
        username: z.string().min(1),
        page: z.number().int().min(0).optional(),
      });
    
      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
            };
          }
        }
      );
    };
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: it's a read operation (implied by 'Get'), returns paginated results (30 posts per page, page parameter usage), orders by recency, and handles offsets. It doesn't cover error cases, rate limits, or authentication needs, but for a 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 (default pagination, ordering, parameter usage). Every sentence adds value: the first states what it does, the second specifies default behavior and pagination logic. No wasted words, and it's appropriately sized for a simple list tool.

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 no annotations, no output schema, and low schema coverage, the description does well by explaining parameters, pagination, and ordering. It doesn't describe the return format (e.g., structure of posts) or error handling, which would be helpful. For a read-only list tool with simple parameters, it's mostly complete but has minor gaps in output details.

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

Parameters5/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 adds crucial semantics: 'username' is required to specify the user, and 'page' controls pagination with explicit offset mapping (page 0 = offset 0, page 1 = offset 30). This clarifies parameter usage beyond the schema's basic types and constraints, fully compensating for the lack of schema descriptions.

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 source ('Discourse instance'), distinguishing it from siblings like discourse_list_categories or discourse_list_tags. However, it doesn't explicitly differentiate from discourse_read_post or discourse_read_topic, which are more specific read operations.

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 and default behavior, but doesn't explicitly state when to use this tool versus alternatives. It doesn't compare to siblings like discourse_search (which might find posts across users) or discourse_get_user (which retrieves user metadata rather than posts). The guidance is functional but lacks contextual decision-making help.

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

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