This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Model Context Protocol (MCP) server that provides AI assistants with standardized access to Slack APIs. It's written in TypeScript and supports both stdio (process-based) and HTTP transport methods.
npm run build- Compile TypeScript to JavaScript in/distnpm run dev- Start server in development mode with hot reloadingnpm start- Run the production build
npm run lint- Run both ESLint and Prettier checksnpm run fix- Auto-fix all linting issuesnpm run lint:eslint- Run ESLint onlynpm run lint:prettier- Run Prettier only
npm run examples- Run stdio transport examplenpm run examples:http- Run HTTP transport example
The server follows a schema-driven design pattern:
-
Request/Response Schemas (
src/schemas.ts):- All Slack API interactions are validated with Zod schemas
- Request schemas define input parameters
- Response schemas filter API responses to only necessary fields
-
Main Server (
src/index.ts):- Dual transport support via command-line flag
- Tool registration and request handling
- Environment variable validation
- Stdio (default): For CLI integration (Claude Desktop, etc.)
- HTTP: For web applications via
-portflag
All tools follow the pattern: validate request → call Slack API → parse response → return JSON
- Channel operations: list, post message, get history
- Thread operations: reply, get replies
- User operations: get users, profiles, bulk profiles
- Message operations: search, add reactions
When to use slack_search_messages:
- You need to find messages with specific criteria (keywords, user, date range, channel)
- You want to filter/narrow down results based on conditions
- You're looking for targeted information rather than browsing
When to use slack_get_channel_history:
- You want to see the latest conversation flow without specific filters
- You need ALL messages including bot/automation messages (search excludes these)
- You want to browse messages chronologically with pagination
- You don't have specific search criteria and just want to understand recent activity
Must set in environment or .env file:
SLACK_BOT_TOKEN: Bot User OAuth TokenSLACK_USER_TOKEN: User OAuth Token (for search)
-
No Test Suite: Currently no tests implemented (
"test": "echo \"No tests yet\"") -
Type Safety: All Slack API responses are parsed through Zod schemas to ensure type safety and limit response size
-
Error Handling: The server validates tokens on startup and provides clear error messages
-
Publishing: Uses GitHub Package Registry - requires PAT for installation
-
ES Modules: Project uses
"type": "module"- use ES import syntax
- Define request/response schemas in
src/schemas.ts - Add tool registration in
src/index.tsserver setup - Implement handler following existing pattern: validate → API call → parse → return
- Update README.md with new tool documentation
- Query Field: The
queryfield accepts plain text search terms only. Modifiers likefrom:,in:,before:etc. are NOT allowed in the query field - use the dedicated fields instead - Date Search: The
on:modifier may not find results due to timezone differences between the Slack workspace and the user's local time - ID-Only Fields: All search modifier fields require proper Slack IDs for consistency and reliability:
in_channel: Channel ID (e.g.,C1234567) - useslack_list_channelsto find channel IDs. The server automatically converts channel IDs to channel names for search compatibility.from_user: User ID (e.g.,U1234567) - useslack_get_usersto find user IDs
- Required Workflow: Always use the appropriate listing tools first to convert names to IDs before searching
- Debug: Search queries are logged to console for troubleshooting
- Bot Message Exclusion: The
search.messagesAPI excludes bot/automation messages by default, unlike the Slack UI - Indexing Delays: Messages are not indexed immediately; there can be delays between posting and searchability
- Proximity Filtering: When multiple messages match in close proximity, only one result may be returned
- Rate Limiting: Non-Marketplace apps have severe rate limits (1 request/minute, 15 messages max as of 2025)
- Comprehensive Alternative: Use
conversations.historyfor retrieving all messages including bot messages
When updating schemas, ensure backward compatibility and update both request validation and response filtering to maintain efficiency.