npm package: @jwikman/al-test-runner-mcp-server
Description: MCP server for running AL tests in Business Central
Author: James Pearson
Latest version: 1.0.8

# AL Test Runner MCP Server

A Model Context Protocol (MCP) server that exposes AL test execution capabilities for Business Central development. This server allows AI agents and MCP clients to discover AL tests in source code and run them against Business Central environments.

## Features

- **Test Discovery**: Automatically scans AL workspace for test codeunits and methods
- **Test Execution**: Runs AL tests via PowerShell and returns structured results
- **Configuration Management**: Reads settings from `.altestrunner/config.json` and `launch.json`

## Prerequisites

- Node.js >= 18.0.0
- PowerShell (Windows)
- Business Central environment (local container or remote)
- AL Test Runner VS Code extension PowerShell modules
- Pre-configured `.altestrunner.json` with credentials

## Installation

```bash
npm install al-test-runner-mcp-server
```

### Configuration with MCP Clients

Add to your MCP client configuration (e.g., Claude Desktop):

```json
{
  "mcpServers": {
    "al-test-runner": {
      "command": "npx",
      "args": ["al-test-runner-mcp-server@1.0.0"]
    }
  }
}
```

## Available Tools

### 1. `discover_al_tests`

Discovers all AL test codeunits and methods in a workspace.

**Parameters:**
- `workspacePath` (string, required): Absolute path to the AL workspace directory

**Example Request:**
```json
{
  "name": "discover_al_tests",
  "arguments": {
    "workspacePath": "C:\\Projects\\MyBCApp"
  }
}
```

**Example Response:**
```json
{
  "success": true,
  "testCodeunitsFound": 5,
  "totalTestMethods": 42,
  "testCodeunits": [
    {
      "id": 50100,
      "name": "Sales Invoice Tests",
      "filePath": "C:\\Projects\\MyBCApp\\test\\SalesInvoiceTests.al",
      "methods": [
        {
          "name": "TestCreateSalesInvoice",
          "lineNumber": 15
        },
        {
          "name": "TestPostSalesInvoice",
          "lineNumber": 28
        }
      ]
    }
  ]
}
```

### 2. `run_al_tests`

Executes AL tests in Business Central and returns results.

**Parameters:**
- `workspacePath` (string, required): Absolute path to the AL workspace directory
- `codeunitId` (number, optional): ID of specific test codeunit to run
- `methodName` (string, optional): Name of specific test method (requires codeunitId)
- `containerName` (string, optional): Name of the Docker container to run tests against
- `userName` (string, optional): Username for BC authentication
- `companyName` (string, optional): Company name to run tests against

**Example Request (Run All Tests):**
```json
{
  "name": "run_al_tests",
  "arguments": {
    "workspacePath": "C:\\Projects\\MyBCApp"
  }
}
```

**Example Request (Run Specific Test):**
```json
{
  "name": "run_al_tests",
  "arguments": {
    "workspacePath": "C:\\Projects\\MyBCApp",
    "codeunitId": 50100,
    "methodName": "TestCreateSalesInvoice"
  }
}
```

**Example Response:**
```json
{
  "success": true,
  "exitCode": 0,
  "stdout": "Running tests...\nTests completed.",
  "stderr": "",
  "results": {
    "total": 2,
    "passed": 2,
    "failed": 0,
    "skipped": 0,
    "duration": 1.234,
    "results": [
      {
        "codeunitId": 50100,
        "codeunitName": "Sales Invoice Tests",
        "methodName": "TestCreateSalesInvoice",
        "result": "Pass",
        "duration": 0.567
      },
      {
        "codeunitId": 50100,
        "codeunitName": "Sales Invoice Tests",
        "methodName": "TestPostSalesInvoice",
        "result": "Pass",
        "duration": 0.667
      }
    ]
  }
}
```

### 3. `get_test_configuration`

Retrieves the current test configuration from workspace files.

**Parameters:**
- `workspacePath` (string, required): Absolute path to the AL workspace directory

**Example Request:**
```json
{
  "name": "get_test_configuration",
  "arguments": {
    "workspacePath": "C:\\Projects\\MyBCApp"
  }
}
```

**Example Response:**
```json
{
  "success": true,
  "alTestRunnerConfig": {
    "containerName": "bcserver",
    "userName": "admin",
    "password": "password"
    "companyName": "CRONUS International Ltd.",
  },
  "appJson": {
    "id": "12345678-1234-1234-1234-123456789012",
    "name": "My BC App",
    "version": "1.0.0.0"
  }
}
```

## Configuration Files

### .altestrunner.json

Required configuration file in your AL workspace:

```json
{
  "containerName": "bcserver",
  "userName": "admin",
  "password": "password for NavUserPassword auth",
  "companyName": "Company Name to run tests in"
}
```

## License

MIT

## Author

James Pearson