slack_list_channels
Retrieve public Slack channels from your workspace with pagination support to manage large lists efficiently.
Instructions
List public channels in the workspace with pagination
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "slack_list_channels"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of channels to return (default 100, max 200) | |
| cursor | No | Pagination cursor for next page of results |
Implementation Reference
- index.ts:421-431 (handler)Handler logic for the slack_list_channels tool within the CallToolRequest switch statement. Extracts arguments and invokes the SlackClient.getChannels method.
case "slack_list_channels": { const args = request.params .arguments as unknown as ListChannelsArgs; const response = await slackClient.getChannels( args.limit, args.cursor, ); return { content: [{ type: "text", text: JSON.stringify(response) }], }; } - index.ts:54-72 (schema)Tool schema definition for slack_list_channels, including name, description, and input schema.
const listChannelsTool: Tool = { name: "slack_list_channels", description: "List public channels in the workspace with pagination", inputSchema: { type: "object", properties: { limit: { type: "number", description: "Maximum number of channels to return (default 100, max 200)", default: 100, }, cursor: { type: "string", description: "Pagination cursor for next page of results", }, }, }, }; - index.ts:567-582 (registration)Registration of slack_list_channels tool in the ListToolsRequest handler by including listChannelsTool in the returned tools array.
server.setRequestHandler(ListToolsRequestSchema, async () => { console.log("Received ListToolsRequest"); return { tools: [ listChannelsTool, postMessageTool, replyToThreadTool, addReactionTool, getChannelHistoryTool, getThreadRepliesTool, getUsersTool, getUserProfileTool, lookupUserByEmailTool, ], }; }); - index.ts:253-271 (helper)SlackClient.getChannels method implementing the core logic to fetch public channels from Slack API using conversations.list endpoint.
async getChannels(limit: number = 100, cursor?: string): Promise<any> { const params = new URLSearchParams({ types: "public_channel", exclude_archived: "true", limit: Math.min(limit, 200).toString(), team_id: process.env.SLACK_TEAM_ID!, }); if (cursor) { params.append("cursor", cursor); } const response = await fetch( `https://slack.com/api/conversations.list?${params}`, { headers: this.botHeaders }, ); return response.json(); }