php-container-test-mcp

php-container-test-mcp

An MCP server that lets AI agents run PHP unit and integration tests inside Docker containers without local PHP or Composer.

Category
访问服务器

README

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.

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

Via npm (recommended)

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

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选