Skip to main content
Glama
discourse

Discourse MCP

Official
by discourse

List User's Chat Channels

discourse_list_user_chat_channels

Retrieve all chat channels for the authenticated user, including public channels and direct messages, with unread status tracking.

Instructions

List all chat channels for the currently authenticated user, including both public channels they're a member of and direct message channels. Includes unread tracking information.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler function that retrieves the authenticated user's chat channels (public and DM) from Discourse API, formats them into a markdown list with details like unread counts, mentions, last message, and URLs.
      async (_args, _extra: any) => {
        try {
          const { base, client } = ctx.siteState.ensureSelectedSite();
    
          const url = `/chat/api/me/channels`;
          const data = (await client.get(url)) as any;
    
          const publicChannels: any[] = data?.public_channels || [];
          const dmChannels: any[] = data?.direct_message_channels || [];
          const tracking = data?.tracking || {};
    
          const lines: string[] = [];
          lines.push("# My Chat Channels");
          lines.push("");
    
          // Public channels
          if (publicChannels.length > 0) {
            lines.push(`## Public Channels (${publicChannels.length})`);
            lines.push("");
            for (const channel of publicChannels) {
              const title = channel.title || `Channel ${channel.id}`;
              const slug = channel.slug || String(channel.id);
              const unreadCount = tracking?.channel_tracking?.[channel.id]?.unread_count || 0;
              const mentionCount = tracking?.channel_tracking?.[channel.id]?.mention_count || 0;
    
              lines.push(`### ${title}`);
              lines.push(`- **ID**: ${channel.id}`);
              lines.push(`- **Slug**: ${slug}`);
              lines.push(`- **Status**: ${channel.status || "open"}`);
              if (unreadCount > 0) {
                lines.push(`- **Unread**: ${unreadCount} messages`);
              }
              if (mentionCount > 0) {
                lines.push(`- **Mentions**: ${mentionCount}`);
              }
              if (channel.last_message) {
                const lastMsg = channel.last_message;
                lines.push(`- **Last Message**: by @${lastMsg.user?.username || "unknown"} at ${lastMsg.created_at || "unknown time"}`);
              }
              lines.push(`- **URL**: ${base}/chat/c/${slug}/${channel.id}`);
              lines.push("");
            }
          } else {
            lines.push("## Public Channels");
            lines.push("No public channels.");
            lines.push("");
          }
    
          // Direct message channels
          if (dmChannels.length > 0) {
            lines.push(`## Direct Messages (${dmChannels.length})`);
            lines.push("");
            for (const channel of dmChannels) {
              const title = channel.title || `DM ${channel.id}`;
              const unreadCount = tracking?.channel_tracking?.[channel.id]?.unread_count || 0;
              const mentionCount = tracking?.channel_tracking?.[channel.id]?.mention_count || 0;
    
              lines.push(`### ${title}`);
              lines.push(`- **ID**: ${channel.id}`);
              if (unreadCount > 0) {
                lines.push(`- **Unread**: ${unreadCount} messages`);
              }
              if (mentionCount > 0) {
                lines.push(`- **Mentions**: ${mentionCount}`);
              }
              if (channel.last_message) {
                const lastMsg = channel.last_message;
                lines.push(`- **Last Message**: by @${lastMsg.user?.username || "unknown"} at ${lastMsg.created_at || "unknown time"}`);
              }
              lines.push(`- **URL**: ${base}/chat/c/-/${channel.id}`);
              lines.push("");
            }
          } else {
            lines.push("## Direct Messages");
            lines.push("No direct message channels.");
            lines.push("");
          }
    
          return { content: [{ type: "text", text: lines.join("\n") }] };
        } catch (e: any) {
          return {
            content: [{ type: "text", text: `Failed to list user chat channels: ${e?.message || String(e)}` }],
            isError: true
          };
        }
      }
    );
  • Zod input schema for the tool: no input parameters required.
    const schema = z.object({}).strict();
  • Module that exports the registration function for the tool, including tool name, title, description, schema, and inline handler.
    export const registerListUserChatChannels: RegisterFn = (server, ctx) => {
      const schema = z.object({}).strict();
    
      server.registerTool(
        "discourse_list_user_chat_channels",
        {
          title: "List User's Chat Channels",
          description: "List all chat channels for the currently authenticated user, including both public channels they're a member of and direct message channels. Includes unread tracking information.",
          inputSchema: schema.shape,
        },
        async (_args, _extra: any) => {
          try {
            const { base, client } = ctx.siteState.ensureSelectedSite();
    
            const url = `/chat/api/me/channels`;
            const data = (await client.get(url)) as any;
    
            const publicChannels: any[] = data?.public_channels || [];
            const dmChannels: any[] = data?.direct_message_channels || [];
            const tracking = data?.tracking || {};
    
            const lines: string[] = [];
            lines.push("# My Chat Channels");
            lines.push("");
    
            // Public channels
            if (publicChannels.length > 0) {
              lines.push(`## Public Channels (${publicChannels.length})`);
              lines.push("");
              for (const channel of publicChannels) {
                const title = channel.title || `Channel ${channel.id}`;
                const slug = channel.slug || String(channel.id);
                const unreadCount = tracking?.channel_tracking?.[channel.id]?.unread_count || 0;
                const mentionCount = tracking?.channel_tracking?.[channel.id]?.mention_count || 0;
    
                lines.push(`### ${title}`);
                lines.push(`- **ID**: ${channel.id}`);
                lines.push(`- **Slug**: ${slug}`);
                lines.push(`- **Status**: ${channel.status || "open"}`);
                if (unreadCount > 0) {
                  lines.push(`- **Unread**: ${unreadCount} messages`);
                }
                if (mentionCount > 0) {
                  lines.push(`- **Mentions**: ${mentionCount}`);
                }
                if (channel.last_message) {
                  const lastMsg = channel.last_message;
                  lines.push(`- **Last Message**: by @${lastMsg.user?.username || "unknown"} at ${lastMsg.created_at || "unknown time"}`);
                }
                lines.push(`- **URL**: ${base}/chat/c/${slug}/${channel.id}`);
                lines.push("");
              }
            } else {
              lines.push("## Public Channels");
              lines.push("No public channels.");
              lines.push("");
            }
    
            // Direct message channels
            if (dmChannels.length > 0) {
              lines.push(`## Direct Messages (${dmChannels.length})`);
              lines.push("");
              for (const channel of dmChannels) {
                const title = channel.title || `DM ${channel.id}`;
                const unreadCount = tracking?.channel_tracking?.[channel.id]?.unread_count || 0;
                const mentionCount = tracking?.channel_tracking?.[channel.id]?.mention_count || 0;
    
                lines.push(`### ${title}`);
                lines.push(`- **ID**: ${channel.id}`);
                if (unreadCount > 0) {
                  lines.push(`- **Unread**: ${unreadCount} messages`);
                }
                if (mentionCount > 0) {
                  lines.push(`- **Mentions**: ${mentionCount}`);
                }
                if (channel.last_message) {
                  const lastMsg = channel.last_message;
                  lines.push(`- **Last Message**: by @${lastMsg.user?.username || "unknown"} at ${lastMsg.created_at || "unknown time"}`);
                }
                lines.push(`- **URL**: ${base}/chat/c/-/${channel.id}`);
                lines.push("");
              }
            } else {
              lines.push("## Direct Messages");
              lines.push("No direct message channels.");
              lines.push("");
            }
    
            return { content: [{ type: "text", text: lines.join("\n") }] };
          } catch (e: any) {
            return {
              content: [{ type: "text", text: `Failed to list user chat channels: ${e?.message || String(e)}` }],
              isError: true
            };
          }
        }
      );
    };
  • Top-level registration call that invokes the tool's registration function during MCP server setup.
    registerListUserChatChannels(server, ctx, { allowWrites: false });
Behavior3/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 mentions authentication requirement and unread tracking information, which are useful behavioral traits. However, it doesn't cover other important aspects like pagination, rate limits, error conditions, or response format, leaving gaps for a tool that likely returns a list of channels.

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, well-structured sentence that efficiently conveys the tool's purpose, scope, and key feature (unread tracking). Every element earns its place with no redundant information, making it appropriately front-loaded and concise.

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

Completeness3/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 (listing user-specific channels with tracking), no annotations, and no output schema, the description is somewhat complete but has gaps. It covers authentication context and what's included, but doesn't describe the response structure, potential limitations, or how unread tracking is presented, which would help the agent use it effectively.

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 tool has 0 parameters with 100% schema description coverage, so the baseline is 4. The description appropriately doesn't discuss parameters since none exist, and it adds value by explaining what the tool returns (channels with unread tracking) beyond what the empty schema provides.

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: listing all chat channels for the authenticated user, specifying both public channels they're a member of and direct message channels. It distinguishes from siblings like 'discourse_list_chat_channels' by focusing on user-specific channels rather than all channels, though it doesn't explicitly name this distinction.

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 context by mentioning 'currently authenticated user' and including unread tracking, suggesting it's for personal chat management. However, it lacks explicit guidance on when to use this tool versus alternatives like 'discourse_list_chat_channels' or 'discourse_get_chat_messages', leaving the agent to infer based on scope.

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