Skip to main content
Glama

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

  • The handler function that implements the tool logic: fetches the user's chat channels from `/chat/api/me/channels`, processes public and DM channels with unread tracking, formats into Markdown list with details like ID, slug, status, unread/mention counts, 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 (empty object, no parameters required).
    const schema = z.object({}).strict();
  • Registers the tool using server.registerTool with name, metadata (title, description, inputSchema), and handler function.
      "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
          };
        }
      }
    );
  • Invokes the registration function for this tool within the overall tools registry.
    registerListUserChatChannels(server, ctx, { allowWrites: false });
  • Imports the registration function for the discourse_list_user_chat_channels tool.
    import { registerListUserChatChannels } from "./builtin/list_user_chat_channels.js";
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 describes the resource scope and includes unread tracking, but does not mention authentication requirements, rate limits, pagination, or error handling. It adds some context but lacks comprehensive behavioral traits for a tool with no annotation coverage.

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 purpose, scope, and key features without any wasted words. It is front-loaded with the core action and appropriately sized for the tool's complexity.

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 no annotations and no output schema, the description provides basic purpose and scope but lacks details on authentication, response format, pagination, or error handling. It is adequate for a simple list tool but has clear gaps in behavioral and output context that could hinder effective use by an AI agent.

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 parameters with 100% coverage, so no parameter documentation is needed. The description appropriately does not discuss parameters, focusing instead on the tool's purpose and output characteristics. This meets the baseline for tools with no parameters.

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

Purpose5/5

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

The description clearly states the verb ('List') and resource ('all chat channels for the currently authenticated user'), specifying scope ('both public channels they're a member of and direct message channels') and additional information ('unread tracking information'). It distinguishes from sibling 'discourse_list_chat_channels' by focusing on the user's channels rather than all channels.

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

Usage Guidelines4/5

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

The description implies usage context by specifying 'for the currently authenticated user' and includes unread tracking, but does not explicitly state when to use this tool versus alternatives like 'discourse_list_chat_channels' or 'discourse_get_user'. It provides clear context but lacks explicit exclusions or named alternatives.

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