Project Structure & Organization
This document provides an overview of the Slack MCP Server project structure, source code organization, and architectural design patterns.
Directory Structure
slack-mcp-server/
├── slack_mcp/ # Main package directory
│ ├── mcp/ # MCP server implementation
│ │ ├── model/ # Data models and schemas
│ │ ├── cli/ # Command-line interface
│ │ ├── server.py # MCP server implementation
│ │ └── __init__.py
│ ├── webhook/ # Webhook server implementation
│ │ ├── event/ # Event handling and models
│ │ ├── cli/ # Webhook CLI interface
│ │ ├── server.py # FastAPI webhook server
│ │ ├── models.py # Pydantic models for Slack events
│ │ └── entry.py # Entry points and runners
│ ├── client/ # Slack client management
│ │ ├── factory.py # Client factory patterns
│ │ └── manager.py # Client lifecycle management
│ ├── backends/ # Queue backend abstractions
│ │ ├── base/ # Base backend interfaces
│ │ └── queue/ # Queue backend implementations
│ ├── integrated_server.py # Integrated MCP + webhook server
│ └── __init__.py
├── test/ # Test suite
│ ├── unit_test/ # Unit tests
│ ├── integration_test/ # Integration tests
│ ├── contract_test/ # Contract tests
│ └── e2e_test/ # End-to-end tests
├── examples/ # Usage examples
├── scripts/ # Build and deployment scripts
├── docs/ # Documentation (Docusaurus)
└── pyproject.toml # Project configuration
Core Components
MCP Server (slack_mcp/mcp/)
The MCP server implements the Model Context Protocol for Slack integration:
server.py: Main MCP server implementation with tool registrationmodel/: Pydantic models for MCP requests and responsescli/: Command-line interface for running the MCP server
Key Features:
- Multiple transport support (stdio, SSE, HTTP)
- Slack API integration through registered tools
- Async/await patterns for non-blocking operations
- Comprehensive error handling and logging
Webhook Server (slack_mcp/webhook/)
FastAPI-based webhook server for receiving Slack events:
server.py: FastAPI application with webhook endpointsmodels.py: Pydantic models for Slack event payloadsevent/: Event processing and handler managemententry.py: Server runners and entry points
Key Features:
- Request signature verification for security
- Event publishing to queue backends
- URL verification challenge handling
- Standalone and integrated deployment modes
Client Management (slack_mcp/client/)
Centralized Slack client management:
factory.py: Factory patterns for client creationmanager.py: Client lifecycle and token management
Backend Abstraction (slack_mcp/backends/)
Queue backend abstraction layer:
base/: Abstract base classes and interfacesqueue/: Concrete queue backend implementations
Design Patterns
Factory Pattern
Used extensively for creating clients and server instances:
# Client factory
from slack_mcp.client.factory import create_slack_client
# Server factory functions
from slack_mcp.integrate.integrated_server import create_integrated_app
Strategy Pattern
Transport mechanism selection and queue backend selection:
# Transport strategy
if transport == "sse":
mcp_app = server.sse_app(mount_path=mount_path)
elif transport == "streamable-http":
mcp_app = server.streamable_http_app()
Repository Pattern
Backend abstraction for different queue systems:
# Queue backend strategy
backend = get_backend(backend_type)
await backend.publish(topic, event_data)
Command Pattern
MCP tools as command objects:
@server.list_tools()
async def handle_list_tools() -> list[types.Tool]:
return [
types.Tool(name="slack_post_message", description="..."),
# ... other tools
]
Configuration Management
Environment-Based Configuration
.envfiles for local development- Environment variables for production
- Centralized configuration validation
CLI Integration
- Comprehensive command-line interfaces
- Argument parsing with validation
- Help text and documentation
Testing Strategy
Test Organization
- Unit Tests: Component-level testing with mocks
- Integration Tests: Cross-component interaction testing
- Contract Tests: API contract validation
- End-to-End Tests: Full workflow testing
Test Utilities
- Shared fixtures and test data
- Mock factories for external dependencies
- Test configuration management
Development Workflow
Code Organization Principles
- Separation of Concerns: Clear boundaries between MCP, webhook, and client code
- Dependency Injection: Loose coupling through factory patterns
- Async/Await: Non-blocking operations throughout
- Type Hints: Comprehensive type annotations for better IDE support
- Error Handling: Consistent error patterns and logging
Package Management
- UV: Fast Python package management
- Lock Files: Reproducible dependency resolution
- Development Dependencies: Separate dev/test requirements
Code Quality
- Linting: Pylint, MyPy type checking
- Formatting: Consistent code style
- Pre-commit Hooks: Automated quality checks
Extension Points
Adding New MCP Tools
- Create tool function in
slack_mcp/mcp/server.py - Define input/output models in
slack_mcp/mcp/model/ - Register tool with MCP server
- Add comprehensive tests
Adding New Event Handlers
- Extend event models in
slack_mcp/webhook/event/ - Implement handler logic
- Register with webhook server
- Add queue publishing logic
Adding New Queue Backends
- Implement backend interface in
slack_mcp/backends/queue/ - Add backend selection logic
- Update configuration options
- Add backend-specific tests
This modular architecture ensures maintainability, testability, and extensibility while providing clear boundaries between different system components.