🤖 AI Tools
· 1 min read

Build a Slack MCP Server — Step-by-Step Tutorial


Build an MCP server that connects AI to Slack — send messages, read channels, and search history from Claude Code or Cursor.

Setup

mkdir slack-mcp && cd slack-mcp
npm init -y
npm install @modelcontextprotocol/sdk @slack/web-api zod

The server

import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { WebClient } from '@slack/web-api';
import { z } from 'zod';

const slack = new WebClient(process.env.SLACK_TOKEN);
const server = new McpServer({ name: 'slack', version: '1.0.0' });

server.tool('send_message', {
  channel: z.string().describe('Channel name or ID'),
  text: z.string().describe('Message text')
}, async ({ channel, text }) => {
  await slack.chat.postMessage({ channel, text });
  return { content: [{ type: 'text', text: `Sent to ${channel}` }] };
});

server.tool('search_messages', {
  query: z.string().describe('Search query'),
  count: z.number().default(5)
}, async ({ query, count }) => {
  const result = await slack.search.messages({ query, count });
  const messages = result.messages.matches
    .map(m => `[${m.channel.name}] ${m.username}: ${m.text}`)
    .join('\n');
  return { content: [{ type: 'text', text: messages || 'No results' }] };
});

await server.connect(new StdioServerTransport());

Connect to Claude Code

claude mcp add slack node /path/to/slack-mcp/index.js -e SLACK_TOKEN=xoxb-...

Now ask Claude: “Search Slack for messages about the deployment issue” or “Send a message to #engineering about the fix.”

Security

Only grant the Slack bot the permissions it needs. Use read-only scopes unless you need to send messages. See our MCP Security Checklist.

Related: Build MCP Server (TypeScript) · Best MCP Servers · MCP + Claude Code