Skip to main content
Glama
php-container-test-mcp

php-container-test-mcp

php-container-test-mcp

An MCP (Model Context Protocol) server that lets AI agents run PHP unit and integration tests inside Docker containers — no local PHP or Composer installation required on the host.

What it does

Exposes two MCP tools:

  • run_php_tests — runs the full test suite

  • run_php_test_file — runs a single test file

Both execute docker run --rm -v <host_path>:<container_path> -w <container_path> <image> composer <command> [-- <test_file>] and return the full stdout + stderr so the caller can evaluate pass/fail.

Related MCP server: taw-computer

Prerequisites

  • Node.js ≥ 18

  • Docker installed and running on the host

  • A Docker image that includes PHP, Composer, and a Composer script for running tests (e.g. phpunit, pest)

Example composer.json scripts section inside your PHP image

"scripts": {
  "test": "vendor/bin/phpunit",
  "test:unit": "vendor/bin/phpunit --testsuite unit",
  "test:integration": "vendor/bin/phpunit --testsuite integration"
}

Installation

npm install -g php-container-test-mcp

From source

git clone https://github.com/your-user/php-container-test-mcp
cd php-container-test-mcp
npm install

Registering with Claude Code

Add the server to your project's .mcp.json for project-scoped access, or to ~/.claude/claude_desktop_config.json for global access.

The server accepts named arguments to configure defaults. All three can also be overridden per tool call.

Argument

Description

Default

--container

Docker image name

(required)

--command

Composer script name to execute

test

--host-path

Host project path to mount

current working directory

--container-path

Mount path inside the container

/var/www

Using the npm package (after npm install -g)

{
  "mcpServers": {
    "php-container-test": {
      "command": "php-container-test-mcp",
      "args": ["--container=my-php-app:latest", "--command=test", "--host-path=/home/user/my-project", "--container-path=/var/www"]
    }
  }
}

Using npx (no install required)

{
  "mcpServers": {
    "php-container-test": {
      "command": "npx",
      "args": ["-y", "php-container-test-mcp", "--container=my-php-app:latest", "--command=test", "--host-path=/home/user/my-project", "--container-path=/var/www"]
    }
  }
}

From source (local path)

{
  "mcpServers": {
    "php-container-test": {
      "command": "node",
      "args": ["/absolute/path/to/php-container-test-mcp/src/index.js", "--container=my-php-app:latest", "--command=test", "--host-path=/home/user/my-project", "--container-path=/var/www"]
    }
  }
}

Then restart Claude Code. The run_php_tests and run_php_test_file tools will be available automatically.

Tool reference

run_php_tests — run the full test suite

Parameter

Type

Required

Default

Description

container_name

string

Yes

server arg

Docker image to run (e.g. my-php-app:latest)

command

string

No

"test"

Composer script name to execute

host_path

string

No

server arg or cwd

Absolute path to the project on the host to mount into the container

container_path

string

No

server arg or /var/www

Path inside the container where the project will be mounted

run_php_test_file — run a single test file

Parameter

Type

Required

Default

Description

container_name

string

Yes

server arg

Docker image to run (e.g. my-php-app:latest)

test_file

string

Yes

—

Path to the test file inside the container (e.g. tests/Unit/UserTest.php)

command

string

No

"test"

Composer script name to execute

host_path

string

No

server arg or cwd

Absolute path to the project on the host to mount into the container

container_path

string

No

server arg or /var/www

Path inside the container where the project will be mounted

Example prompts

Run all tests:

Run the tests for the my-php-app:latest container.

Run only unit tests using a specific Composer script:

Run only the unit tests using the test:unit script for container my-php-app:latest.

Run a single test file:

Run tests/Unit/UserTest.php in the my-php-app:latest container.

Override mount paths:

Run the tests for my-php-app:latest, mounting /home/user/my-project on the host to /app inside the container.

Example tool calls

run_php_tests — full suite with defaults:

{
  "container_name": "my-php-app:latest"
}

run_php_tests — specific Composer script:

{
  "container_name": "my-php-app:latest",
  "command": "test:unit"
}

run_php_test_file — single test file:

{
  "container_name": "my-php-app:latest",
  "test_file": "tests/Unit/UserTest.php"
}

run_php_tests — override mount paths:

{
  "container_name": "my-php-app:latest",
  "host_path": "/home/user/my-project",
  "container_path": "/app"
}

How it works

  1. The server is launched by the MCP host (Claude Code) and communicates over stdin/stdout using the JSON-RPC 2.0 MCP protocol.

  2. When a tool is called, the server executes:

    docker run --rm -v <host_path>:<container_path> -w <container_path> <image> composer <command> [-- <test_file>]
  3. --rm ensures the container is automatically removed after each run.

  4. The combined stdout + stderr is returned to the calling agent.

Troubleshooting

Problem

Solution

docker: command not found

Ensure Docker is installed and in $PATH for the user running the MCP server

Unable to find image '...' locally

Pull the image first: docker pull <image>

Script "test" is not defined

Add a test script to composer.json inside your Docker image

No output returned

The container may have exited immediately — check the image entrypoint

Tests time out for large suites

The server uses a 10 MB output buffer; the process itself has no hard timeout — Docker will run until the suite finishes

License

MIT

Available Tools

2 tools
run_php_test_fileRun a Specific PHP Test FileA

ALWAYS use this tool to run a single PHP test file inside a Docker container — never run phpunit directly on the host. Use when the user says: run this test, test this file, run UserTest, run tests for this class, rodar esse teste, testar esse arquivo, rodar o teste do UserController. Returns the full test output (stdout + stderr) so you can evaluate pass/fail.

Inputs: test_file (required), container_name (required), command, host_path, +1 more.

run_php_testsRun All PHP TestsA

ALWAYS use this tool to run the full PHP test suite inside a Docker container — never run composer or phpunit directly on the host. Use when the user says: run tests, run all tests, run unit tests, run integration tests, execute tests, check if tests pass, make sure nothing broke, validate the feature, verify the fix, rodar testes, rodar todos os testes, executar testes, verificar se os testes passam. Returns the full test output (stdout + stderr) so you can evaluate pass/fail.

Inputs: container_name (required), command, host_path, container_path.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.1/5.0

    Scored across 2 tools

    Disambiguation5/5

    The two tools have clearly distinct purposes: one runs a single specific test file, the other runs the entire test suite. There is no overlap, and the descriptions reinforce the distinction.

    Naming Consistency5/5

    Both tools follow a consistent verb_noun pattern using snake_case: run_php_test_file and run_php_tests. The naming is predictable and clear.

    Tool Count4/5

    With only two tools, the server is very focused on running PHP tests in a container. While it could benefit from additional tools (e.g., for coverage or test selection), the count is reasonable for a narrow, specialized purpose.

    Completeness2/5

    The tool surface lacks common test runner capabilities such as running specific test methods, filtering tests by group, or enabling coverage. The server only supports two coarse-grained operations, leaving significant gaps for typical testing workflows.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      D
      maintenance
      An MCP server that provides AI agents with a full Ubuntu desktop environment inside Docker, enabling them to perform complex computer tasks like browsing, coding, testing, and GUI automation.
      36
      11
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      A local MCP server that provides tools for AI coding agents to execute, evaluate, and diff regression tests for LLM agents.
      3 npm
      MIT