Configuration

Customize MCP Jest to fit your testing workflow with powerful configuration options.

Configuration Sources

MCP Jest loads configuration from multiple sources in order of priority:

1. Command line arguments (highest priority)
2. Test file configuration
3. mcp-jest.config.json
4. package.json "mcpJest" field
5. Default values (lowest priority)

Global Configuration File

Create mcp-jest.config.json in your project root:

{
  "timeout": 30000,
  "retries": 1,
  "bail": false,
  "verbose": false,
  "colors": true,
  "parallel": true,
  "maxWorkers": 4,
  "watch": false,
  "updateSnapshots": false,
  "snapshotDir": "__snapshots__",
  "coverage": {
    "enabled": false,
    "outputDir": "coverage",
    "reporters": ["text", "html"]
  },
  "reporters": [
    "default",
    {
      "name": "junit",
      "outputFile": "test-results.xml"
    }
  ],
  "testMatch": [
    "**/test/**/*.json",
    "**/*.test.json"
  ],
  "testIgnore": [
    "**/node_modules/**",
    "**/.*"
  ]
}

Package.json Configuration

Alternatively, add configuration to your package.json:

{
  "name": "my-mcp-server",
  "scripts": {
    "test": "mcp-jest",
    "test:watch": "mcp-jest --watch",
    "test:update": "mcp-jest --update-snapshots"
  },
  "mcpJest": {
    "timeout": 15000,
    "testMatch": ["tests/*.json"],
    "coverage": {
      "enabled": true
    }
  }
}

Test File Configuration

Configure settings specific to individual test files:

{
  "name": "Integration Tests",
  "config": {
    "timeout": 60000,
    "retries": 3,
    "parallel": false,
    "setupTimeout": 10000,
    "teardownTimeout": 5000
  },
  "server": { ... },
  "tests": [ ... ]
}

Environment-Specific Configuration

Use different configurations for different environments:

{
  "environments": {
    "development": {
      "timeout": 10000,
      "verbose": true,
      "watch": true
    },
    "ci": {
      "timeout": 30000,
      "retries": 2,
      "bail": true,
      "colors": false,
      "reporters": ["junit", "default"]
    },
    "production": {
      "timeout": 5000,
      "retries": 0,
      "parallel": true,
      "maxWorkers": 8
    }
  }
}

Select environment with:

mcp-jest --env=ci tests/*.json

Server Configuration Options

Command Configuration

"server": {
  "command": "node",
  "args": ["dist/server.js", "--port", "3000"],
  "cwd": "./server",
  "shell": false,
  "detached": false
}

Environment Variables

"server": {
  "command": "python",
  "args": ["-m", "my_server"],
  "env": {
    "NODE_ENV": "test",
    "LOG_LEVEL": "error",
    "DATABASE_URL": "sqlite::memory:",
    "API_KEY": "${TEST_API_KEY}"
  },
  "inheritEnv": true
}

Startup Configuration

"server": {
  "command": "./my-server",
  "timeout": 30000,
  "readyPattern": "Server listening on",
  "readyTimeout": 10000,
  "killSignal": "SIGTERM",
  "killTimeout": 5000,
  "stdio": ["ignore", "pipe", "pipe"]
}

Parallel Execution

Configure parallel test execution for faster results:

{
  "parallel": true,
  "maxWorkers": 4,           // Number of worker processes
  "workerIdleTimeout": 5000, // Kill idle workers after 5s
  "workerMemoryLimit": "500MB",
  "isolateWorkers": true,    // Each test gets fresh worker
  "sharedSetup": {
    "script": "./setup-shared.js",
    "timeout": 30000
  }
}

Reporting Configuration

Customize test output and reporting:

{
  "reporters": [
    "default",
    {
      "name": "junit",
      "outputFile": "reports/junit.xml"
    },
    {
      "name": "html",
      "outputDir": "reports/html",
      "title": "MCP Jest Test Results"
    },
    {
      "name": "json",
      "outputFile": "reports/results.json"
    }
  ],
  "verbose": true,
  "colors": true,
  "emoji": true,
  "summary": true,
  "timing": true
}

Watch Mode Configuration

Configure file watching behavior:

{
  "watch": {
    "enabled": false,
    "patterns": [
      "src/**/*.js",
      "tests/**/*.json",
      "server/**/*.py"
    ],
    "ignore": [
      "node_modules/**",
      "dist/**",
      "*.log"
    ],
    "delay": 1000,         // Debounce delay in ms
    "runOnStart": true,    // Run tests when watch starts
    "notify": true         // System notifications
  }
}

Coverage Configuration

Set up test coverage reporting:

{
  "coverage": {
    "enabled": true,
    "outputDir": "coverage",
    "reporters": ["text", "html", "lcov"],
    "thresholds": {
      "global": {
        "branches": 80,
        "functions": 80,
        "lines": 80,
        "statements": 80
      },
      "per-file": {
        "branches": 70,
        "functions": 70,
        "lines": 70,
        "statements": 70
      }
    },
    "include": ["src/**/*.js"],
    "exclude": [
      "src/**/*.test.js",
      "src/mocks/**"
    ]
  }
}

Plugin Configuration

Extend MCP Jest with plugins:

{
  "plugins": [
    "mcp-jest-plugin-retry",
    {
      "name": "mcp-jest-plugin-performance",
      "config": {
        "thresholds": {
          "p95": 500,
          "p99": 1000
        }
      }
    },
    {
      "name": "./custom-plugin.js",
      "config": {
        "customOption": "value"
      }
    }
  ]
}

Advanced Configuration

Custom Matchers

{
  "matchers": {
    "customValidators": {
      "email": "^[\\w.-]+@[\\w.-]+\\.[a-zA-Z]{2,}$",
      "uuid": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$",
      "phoneNumber": "^\\+?[1-9]\\d{1,14}$"
    },
    "customTypes": [
      {
        "name": "timestamp",
        "validator": "./validators/timestamp.js"
      }
    ]
  }
}

Setup and Teardown

{
  "setup": {
    "global": "./setup/global-setup.js",
    "beforeAll": "./setup/before-all.js",
    "beforeEach": "./setup/before-each.js"
  },
  "teardown": {
    "afterEach": "./teardown/after-each.js", 
    "afterAll": "./teardown/after-all.js",
    "global": "./teardown/global-teardown.js"
  }
}

Configuration Validation

Validate your configuration with:

mcp-jest --validate-config

Example validation output:

✅ Configuration valid!

Loaded from:
  - mcp-jest.config.json
  - package.json (mcpJest field)

Settings:
  - Timeout: 30000ms
  - Retries: 1  
  - Parallel: true (4 workers)
  - Snapshots: __snapshots__/
  - Reporters: default, junit

⚙️ Configuration Mastery

With proper configuration, MCP Jest adapts to any testing workflow and scales with your project.

Explore CLI Commands →