Skip to main content
Glama
oregpt

Slack MCP Server

by oregpt

channels_list

Retrieve and organize Slack workspace channels by type (public, private, DMs) with optional popularity sorting and pagination for efficient channel discovery.

Instructions

Lists workspace channels by type (public, private, DMs, group DMs) with optional popularity sorting. Supports pagination.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accessTokenYesSlack OAuth token (xoxp-... or xoxb-...)
channel_typesYesComma-separated channel types: mpim, im, public_channel, private_channel
sortNoSort by member count (popularity)
limitNoNumber of results (max: 999, default: 100)
cursorNoPagination cursor from previous response

Implementation Reference

  • The handler function for the 'channels_list' tool. It validates input using ChannelsListSchema, calls Slack's conversations.list API filtered by channel types, optionally sorts channels by member count (popularity), formats the response, and handles errors.
    /** * Tool: channels_list * Lists workspace channels with optional sorting */ export async function channelsList(args: any): Promise<ToolResponse> { try { const validated = ChannelsListSchema.parse(args); const client = new WebClient(validated.accessToken); console.log('Listing channels of types:', validated.channel_types); // Fetch channels const result = await client.conversations.list({ types: validated.channel_types, limit: validated.limit || 100, cursor: validated.cursor }); let channels = result.channels || []; // Sort by popularity (member count) if requested if (validated.sort === 'popularity') { channels = channels.sort((a: any, b: any) => { const aCount = a.num_members || 0; const bCount = b.num_members || 0; return bCount - aCount; }); } return { success: true, data: { channels: channels.map((ch: any) => ({ id: ch.id, name: ch.name, topic: ch.topic?.value, purpose: ch.purpose?.value, member_count: ch.num_members, is_private: ch.is_private, is_channel: ch.is_channel, is_im: ch.is_im, is_mpim: ch.is_mpim })), has_more: Boolean(result.response_metadata?.next_cursor), cursor: result.response_metadata?.next_cursor } }; } catch (error: any) { if (error.name === 'ZodError') { return { success: false, error: `Validation error: ${error.errors.map((e: any) => e.message).join(', ')}` }; } return handleSlackError(error); } }
  • Zod input schema for the channels_list tool, defining required accessToken and channel_types, with optional sort, limit, and cursor parameters.
    /** * Schema for channels_list tool * Lists workspace channels with optional sorting */ export const ChannelsListSchema = z.object({ accessToken: z.string().describe("Slack OAuth token (xoxp-... or xoxb-...)"), channel_types: z.string().describe("Comma-separated channel types: mpim, im, public_channel, private_channel"), sort: z.enum(['popularity']).optional().describe("Sort by member count (popularity)"), limit: z.number().optional().describe("Number of results (max: 999, default: 100)"), cursor: z.string().optional().describe("Pagination cursor from previous response") });
  • src/index.ts:110-114 (registration)
    Registration of the channels_list tool in the MCP server's listTools handler, including name, description, and input schema converted from Zod.
    { name: 'channels_list', description: 'Lists workspace channels by type (public, private, DMs, group DMs) with optional popularity sorting. Supports pagination.', inputSchema: zodToMCPSchema(ChannelsListSchema) }
  • src/index.ts:141-143 (registration)
    Dispatch handler in the MCP server's callToolRequest that routes calls to the channels_list tool to the channelsList function.
    case 'channels_list': result = await channelsList(args); break;

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/oregpt/Agenticledger_MCP_Slack'

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