Skip to main content
Glama
Stig-Johnny

Slack Notifications MCP Server

by Stig-Johnny

list_channels

Retrieve a list of Slack channels that the bot can access, with an optional limit on the number of channels returned.

Instructions

List available Slack channels the bot has access to

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of channels to list (default: 50)

Implementation Reference

  • Handler function that executes the 'list_channels' tool logic. Calls slack.conversations.list() with a limit (default 50, max 200), maps results to {id, name, is_private, is_member, topic}, and returns JSON-formatted channels.
    case "list_channels": {
      const limit = Math.min(args?.limit || 50, 200);
    
      const result = await slack.conversations.list({
        types: "public_channel,private_channel",
        limit: limit,
      });
    
      const channels = (result.channels || []).map((ch) => ({
        id: ch.id,
        name: ch.name,
        is_private: ch.is_private,
        is_member: ch.is_member,
        topic: ch.topic?.value?.substring(0, 100),
      }));
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify({ channels }, null, 2),
          },
        ],
      };
    }
  • Schema/definition for the 'list_channels' tool. Includes optional 'limit' parameter (number, default 50) in the inputSchema.
    {
      name: "list_channels",
      description: "List available Slack channels the bot has access to",
      inputSchema: {
        type: "object",
        properties: {
          limit: {
            type: "number",
            description: "Maximum number of channels to list (default: 50)",
            default: 50,
          },
        },
        required: [],
      },
    },
  • index.js:46-141 (registration)
    Tool registration via server.setRequestHandler(ListToolsRequestSchema). The 'list_channels' tool is registered alongside other tools (check_build_status, get_channel_messages, search_messages, send_message).
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: "check_build_status",
            description: "Get the latest Xcode Cloud build status from Slack notifications. Returns recent build messages including status, workflow name, duration, and timestamp.",
            inputSchema: {
              type: "object",
              properties: {
                limit: {
                  type: "number",
                  description: "Number of recent build messages to retrieve (default: 5, max: 20)",
                  default: 5,
                },
                workflow: {
                  type: "string",
                  description: "Filter by workflow name (e.g., 'Cuti-E-Admin', 'Nutri-E'). Case-insensitive partial match.",
                },
              },
              required: [],
            },
          },
          {
            name: "get_channel_messages",
            description: "Read recent messages from a specific Slack channel",
            inputSchema: {
              type: "object",
              properties: {
                channel_id: {
                  type: "string",
                  description: "Slack channel ID (e.g., C01234567). If not provided, uses the build channel.",
                },
                limit: {
                  type: "number",
                  description: "Number of messages to retrieve (default: 10, max: 100)",
                  default: 10,
                },
              },
              required: [],
            },
          },
          {
            name: "search_messages",
            description: "Search for messages in Slack containing specific text",
            inputSchema: {
              type: "object",
              properties: {
                query: {
                  type: "string",
                  description: "Search query (e.g., 'build failed', 'Cuti-E-Admin')",
                },
                limit: {
                  type: "number",
                  description: "Maximum number of results (default: 10)",
                  default: 10,
                },
              },
              required: ["query"],
            },
          },
          {
            name: "send_message",
            description: "Send a message to a Slack channel",
            inputSchema: {
              type: "object",
              properties: {
                channel_id: {
                  type: "string",
                  description: "Slack channel ID. If not provided, uses the build channel.",
                },
                text: {
                  type: "string",
                  description: "Message text to send",
                },
              },
              required: ["text"],
            },
          },
          {
            name: "list_channels",
            description: "List available Slack channels the bot has access to",
            inputSchema: {
              type: "object",
              properties: {
                limit: {
                  type: "number",
                  description: "Maximum number of channels to list (default: 50)",
                  default: 50,
                },
              },
              required: [],
            },
          },
        ],
      };
    });
  • index.js:143-485 (registration)
    Handler registration via server.setRequestHandler(CallToolRequestSchema). The switch-case on line 148 dispatches to the 'list_channels' case on line 437.
    // Handle tool calls
    server.setRequestHandler(CallToolRequestSchema, async (request) => {
      const { name, arguments: args } = request.params;
    
      try {
        switch (name) {
          case "check_build_status": {
            if (!buildChannelId) {
              return {
                content: [
                  {
                    type: "text",
                    text: "Error: SLACK_BUILD_CHANNEL_ID not configured. Please set it in your MCP config.",
                  },
                ],
              };
            }
    
            const workflowFilter = args?.workflow?.toLowerCase();
            // Fetch more messages if filtering, to ensure we get enough matches
            const fetchLimit = workflowFilter ? Math.min((args?.limit || 5) * 4, 100) : Math.min(args?.limit || 5, 20);
            const result = await slack.conversations.history({
              channel: buildChannelId,
              limit: fetchLimit,
            });
    
            if (!result.messages || result.messages.length === 0) {
              return {
                content: [
                  {
                    type: "text",
                    text: "No build messages found in the channel.",
                  },
                ],
              };
            }
    
            // Helper function to extract duration from text
            const extractDuration = (text, attachments) => {
              // Common patterns for duration in Xcode Cloud messages
              const patterns = [
                /duration[:\s]+(\d+)\s*(?:min(?:ute)?s?)?(?:\s*(\d+)\s*(?:sec(?:ond)?s?)?)?/i,
                /took\s+(\d+)\s*(?:min(?:ute)?s?)?(?:\s*(\d+)\s*(?:sec(?:ond)?s?)?)?/i,
                /completed\s+in\s+(\d+)\s*(?:min(?:ute)?s?)?(?:\s*(\d+)\s*(?:sec(?:ond)?s?)?)?/i,
                /(\d+)\s*(?:min(?:ute)?s?)\s*(?:(\d+)\s*(?:sec(?:ond)?s?)?)?/i,
                /(\d+):(\d+)\s*(?:min)?/i, // MM:SS format
              ];
    
              const allText = text + ' ' + (attachments?.map(a => `${a.title || ''} ${a.text || ''}`).join(' ') || '');
    
              for (const pattern of patterns) {
                const match = allText.match(pattern);
                if (match) {
                  const mins = parseInt(match[1]) || 0;
                  const secs = parseInt(match[2]) || 0;
                  const totalSeconds = mins * 60 + secs;
                  return {
                    minutes: mins,
                    seconds: secs,
                    totalSeconds,
                    formatted: mins > 0 ? `${mins}m ${secs}s` : `${secs}s`,
                  };
                }
              }
              return null;
            };
    
            // Helper function to extract workflow name
            const extractWorkflow = (text, attachments) => {
              // Look for workflow name in text or attachments
              const allText = text + ' ' + (attachments?.map(a => `${a.title || ''} ${a.text || ''}`).join(' ') || '');
    
              // Common patterns: "Workflow: Name", title of attachment often contains workflow
              const patterns = [
                /workflow[:\s]+([^\n\r,]+)/i,
                /^([A-Z][a-zA-Z0-9-]+(?:\s+[A-Z][a-zA-Z0-9-]+)*)\s+(?:build|workflow)/i,
              ];
    
              for (const pattern of patterns) {
                const match = allText.match(pattern);
                if (match) {
                  return match[1].trim();
                }
              }
    
              // Check attachment titles - often contains workflow name
              if (attachments && attachments.length > 0) {
                const title = attachments[0].title;
                if (title && title.length > 0 && title.length < 50) {
                  return title;
                }
              }
    
              return null;
            };
    
            // Parse build messages - Xcode Cloud messages have specific format
            let buildMessages = result.messages.map((msg) => {
              const timestamp = new Date(parseFloat(msg.ts) * 1000).toISOString();
    
              // Try to extract build status from message
              let status = "unknown";
              const text = msg.text || "";
    
              if (text.toLowerCase().includes("succeeded") || text.toLowerCase().includes("success")) {
                status = "succeeded";
              } else if (text.toLowerCase().includes("failed") || text.toLowerCase().includes("failure")) {
                status = "failed";
              } else if (text.toLowerCase().includes("started") || text.toLowerCase().includes("running")) {
                status = "running";
              } else if (text.toLowerCase().includes("cancelled") || text.toLowerCase().includes("canceled")) {
                status = "cancelled";
              }
    
              const workflow = extractWorkflow(text, msg.attachments);
              const duration = extractDuration(text, msg.attachments);
    
              return {
                timestamp,
                status,
                workflow,
                duration,
                text: text.substring(0, 500), // Truncate long messages
                attachments: msg.attachments?.map(a => ({
                  title: a.title,
                  text: a.text?.substring(0, 200),
                  color: a.color,
                })),
              };
            });
    
            // Apply workflow filter if specified
            if (workflowFilter) {
              buildMessages = buildMessages.filter((msg) => {
                const workflow = msg.workflow?.toLowerCase() || '';
                const text = msg.text?.toLowerCase() || '';
                const attachmentText = msg.attachments?.map(a => `${a.title || ''} ${a.text || ''}`).join(' ').toLowerCase() || '';
                return workflow.includes(workflowFilter) || text.includes(workflowFilter) || attachmentText.includes(workflowFilter);
              });
            }
    
            // Apply limit after filtering
            const limit = Math.min(args?.limit || 5, 20);
            buildMessages = buildMessages.slice(0, limit);
    
            return {
              content: [
                {
                  type: "text",
                  text: JSON.stringify({
                    builds: buildMessages,
                    filter: workflowFilter ? { workflow: args.workflow } : null,
                    count: buildMessages.length,
                  }, null, 2),
                },
              ],
            };
          }
    
          case "get_channel_messages": {
            const channelId = args?.channel_id || buildChannelId;
            if (!channelId) {
              return {
                content: [
                  {
                    type: "text",
                    text: "Error: No channel_id provided and SLACK_BUILD_CHANNEL_ID not configured.",
                  },
                ],
              };
            }
    
            const limit = Math.min(args?.limit || 10, 100);
            const result = await slack.conversations.history({
              channel: channelId,
              limit: limit,
            });
    
            const messages = (result.messages || []).map((msg) => ({
              timestamp: new Date(parseFloat(msg.ts) * 1000).toISOString(),
              user: msg.user,
              text: msg.text?.substring(0, 500),
              bot_id: msg.bot_id,
            }));
    
            return {
              content: [
                {
                  type: "text",
                  text: JSON.stringify({ messages }, null, 2),
                },
              ],
            };
          }
    
          case "search_messages": {
            const query = args?.query;
            if (!query) {
              return {
                content: [
                  {
                    type: "text",
                    text: "Error: query parameter is required",
                  },
                ],
              };
            }
    
            const limit = Math.min(args?.limit || 10, 100);
    
            try {
              const result = await slack.search.messages({
                query: query,
                count: limit,
                sort: "timestamp",
                sort_dir: "desc",
              });
    
              const matches = (result.messages?.matches || []).map((match) => ({
                timestamp: new Date(parseFloat(match.ts) * 1000).toISOString(),
                channel: match.channel?.name,
                text: match.text?.substring(0, 500),
                user: match.user,
              }));
    
              return {
                content: [
                  {
                    type: "text",
                    text: JSON.stringify({ results: matches, total: result.messages?.total || 0 }, null, 2),
                  },
                ],
              };
            } catch (error) {
              // Search requires additional OAuth scopes
              if (error.data?.error === "missing_scope") {
                return {
                  content: [
                    {
                      type: "text",
                      text: "Error: Bot token missing 'search:read' scope. Add it in your Slack App settings.",
                    },
                  ],
                };
              }
              throw error;
            }
          }
    
          case "send_message": {
            const channelId = args?.channel_id || buildChannelId;
            const text = args?.text;
    
            if (!channelId) {
              return {
                content: [
                  {
                    type: "text",
                    text: "Error: No channel_id provided and SLACK_BUILD_CHANNEL_ID not configured.",
                  },
                ],
              };
            }
    
            if (!text) {
              return {
                content: [
                  {
                    type: "text",
                    text: "Error: text parameter is required",
                  },
                ],
              };
            }
    
            const result = await slack.chat.postMessage({
              channel: channelId,
              text: text,
            });
    
            return {
              content: [
                {
                  type: "text",
                  text: JSON.stringify({
                    success: result.ok,
                    timestamp: result.ts,
                    channel: result.channel,
                  }, null, 2),
                },
              ],
            };
          }
    
          case "list_channels": {
            const limit = Math.min(args?.limit || 50, 200);
    
            const result = await slack.conversations.list({
              types: "public_channel,private_channel",
              limit: limit,
            });
    
            const channels = (result.channels || []).map((ch) => ({
              id: ch.id,
              name: ch.name,
              is_private: ch.is_private,
              is_member: ch.is_member,
              topic: ch.topic?.value?.substring(0, 100),
            }));
    
            return {
              content: [
                {
                  type: "text",
                  text: JSON.stringify({ channels }, null, 2),
                },
              ],
            };
          }
    
          default:
            return {
              content: [
                {
                  type: "text",
                  text: `Unknown tool: ${name}`,
                },
              ],
              isError: true,
            };
        }
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Slack API error: ${error.message}`,
            },
          ],
          isError: true,
        };
      }
    });
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description only hints at read-only behavior ('the bot has access to') but fails to disclose pagination, rate limits, or error handling, leaving significant gaps.

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?

A single sentence with clear subject, verb, and scope—concise and front-loaded with no extraneous content.

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 the tool's simplicity (one optional parameter, no output schema, no nested objects), the description is nearly complete, though it omits mention of return format or pagination behavior.

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

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema covers 100% of parameters (including default and description for 'limit'), so the description adds no extra semantics beyond what the input schema already provides.

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', the resource 'Slack channels', and the scope 'the bot has access to', differentiating it from sibling tools like get_channel_messages and search_messages.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives, nor are there any when-not or context clues for the agent to decide.

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/Stig-Johnny/slack-notifications-mcp'

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