Testing Guide: Slack MCP Client

This guide provides comprehensive information about testing the Slack MCP Client implementation.

✅ Current Test Coverage

Unit Tests

The project includes comprehensive unit tests for core components:

  1. Formatter Tests (internal/slack/formatter/formatter_test.go)

    • Message format detection

    • Markdown to Slack mrkdwn conversion

    • Block Kit JSON parsing and validation

    • Quoted string conversion

    • Field truncation handling

  2. Configuration Tests

    • MCP server configuration loading

    • LLM provider configuration

    • Environment variable overrides

    • Validation logic

  3. Handler Tests

    • Tool handler interface compliance

    • Registry functionality

    • Error handling scenarios

Integration Tests

  1. MCP Client Integration

    • Connection to stdio MCP servers

    • Connection to HTTP/SSE MCP servers

    • Tool discovery and invocation

    • Error handling and recovery

  2. LLM Provider Integration

    • Provider factory registration

    • Registry initialization

    • Fallback mechanisms

    • Configuration parsing

  3. Slack Integration

    • Socket Mode connection

    • Message handling

    • Formatting pipeline

    • Error responses

🧪 Running Tests

All Tests

# Run all tests with coverage
go test -v -cover ./...

# Run tests with detailed coverage report
go test -v -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html

Specific Components

# Test formatter functionality
go test -v ./internal/slack/formatter/

# Test MCP client
go test -v ./internal/mcp/

# Test LLM providers
go test -v ./internal/llm/

# Test configuration loading
go test -v ./internal/config/

Performance Tests

# Run performance benchmarks
go test -bench=. ./internal/slack/formatter/

# Memory profiling
go test -memprofile=mem.prof ./internal/slack/formatter/
go tool pprof mem.prof

🔧 Manual Testing

MCP Server Testing

  1. Test with Filesystem MCP Server

    # Start the client with filesystem server
    ./slack-mcp-client -config mcp-servers.json
    
    # In Slack, test file operations:
    # "@bot list files in /tmp"
    # "@bot read file /etc/hosts"
  2. Test with Custom MCP Server

    # Create a test server configuration
    {
      "mcpServers": {
        "test-server": {
          "command": "your-test-server",
          "args": ["stdio"]
        }
      }
    }

LLM Provider Testing

  1. OpenAI Provider

    # Set environment variables
    export OPENAI_API_KEY="your-key"
    export LLM_PROVIDER="openai"
    
    # Test in Slack: "@bot What is the weather?"
  2. Ollama Provider

    # Start Ollama locally
    ollama serve
    ollama pull llama3
    
    # Configure client
    export LLM_PROVIDER="ollama"
    
    # Test in Slack: "@bot Explain quantum computing"
  3. Anthropic Provider

    # Set environment variables
    export ANTHROPIC_API_KEY="your-key"
    export LLM_PROVIDER="anthropic"
    
    # Test in Slack: "@bot Help me debug this code"

Slack Formatting Testing

  1. Test Markdown Conversion

    # In Slack, send:
    "@bot Format this: **bold** _italic_ `code` [link](https://example.com)"
  2. Test Block Kit Messages

    # Send structured data:
    "@bot Status: Running, CPU: 45%, Memory: 60%"
  3. Test Code Blocks

    # Send code example:
    "@bot Show me Python code for sorting a list"

🏗️ Test Environment Setup

Local Development

  1. Install Dependencies

    go mod download
    go install golang.org/x/tools/cmd/cover@latest
  2. Set Up Test MCP Servers

    # Install filesystem server
    npm install -g @modelcontextprotocol/server-filesystem
    
    # Test server availability
    npx @modelcontextprotocol/server-filesystem /tmp
  3. Configure Test Slack App

    • Create a test Slack workspace

    • Set up a bot with required permissions

    • Use test tokens for development

CI/CD Testing

The project includes GitHub Actions workflows for:

  1. Continuous Integration

    • Unit test execution

    • Code coverage reporting

    • Linting and formatting checks

  2. Integration Testing

    • Docker container testing

    • Multi-platform builds

    • Dependency security scanning

📊 Test Data and Fixtures

Test Configurations

  1. Test MCP Server Config (test-fixtures/mcp-servers-test.json)

    {
      "mcpServers": {
        "test-filesystem": {
          "command": "echo",
          "args": ["test-mode"]
        }
      }
    }
  2. Test LLM Config (test-fixtures/config-test.yml)

    llm_provider: "test"
    llm_providers:
      test:
        type: "mock"
        model: "test-model"

Mock Objects

The test suite includes mock implementations for:

  • Mock MCP Server: Simulates MCP server responses

  • Mock LLM Provider: Returns predictable responses for testing

  • Mock Slack Client: Captures sent messages for verification

🐛 Debugging Tests

Verbose Test Output

# Enable verbose logging in tests
LOG_LEVEL=debug go test -v ./...

# Test specific scenarios
go test -v -run TestFormatMarkdown ./internal/slack/formatter/

Test Debugging

# Run with race detection
go test -race ./...

# Debug specific test
go test -v -run TestSpecificFunction ./package/

# Use debugger (with delve)
dlv test ./internal/slack/formatter/ -- -test.run TestFormatMarkdown

📈 Coverage Targets

Component
Target Coverage
Current Status

Formatter

95%+

✅ 98%

Config

90%+

✅ 92%

MCP Client

85%+

✅ 87%

LLM Providers

85%+

✅ 89%

Slack Client

80%+

✅ 83%

Overall

85%+

✅ 88%

🚀 Test Best Practices

  1. Write Tests First: Use TDD for new features

  2. Test Edge Cases: Include error conditions and boundary values

  3. Use Table Tests: For testing multiple input/output scenarios

  4. Mock External Dependencies: Don't rely on external services in unit tests

  5. Keep Tests Fast: Unit tests should complete in milliseconds

  6. Test Real Scenarios: Integration tests should use realistic data

📋 Test Checklist

Before deploying:

This comprehensive testing approach ensures the Slack MCP Client is reliable, maintainable, and ready for production use.

Last updated

Was this helpful?