Skip to content

[Mate] Ask for the PHP binary in init and support containerized setups#2271

Open
fatonh wants to merge 1 commit into
symfony:mainfrom
fatonh:mate-init-php-binary
Open

[Mate] Ask for the PHP binary in init and support containerized setups#2271
fatonh wants to merge 1 commit into
symfony:mainfrom
fatonh:mate-init-php-binary

Conversation

@fatonh

@fatonh fatonh commented Jul 2, 2026

Copy link
Copy Markdown
Q A
Bug fix? no
New feature? yes
Docs? yes
Issues Fix #2264
License MIT

mate init generates an mcp.json that the coding agent launches on the host. In a
containerized setup (DDEV, and Docker-based envs generally) PHP only exists inside the
container, so the default ./vendor/bin/mate command can't start and Claude Code shows the
server as failed. Reported in #2264.

This makes init ask which PHP binary the agent should use to launch Mate, and detects a
sensible default from the environment:

  • if a .ddev/ directory is present → default ddev exec php
  • otherwise → default php

The prompt is offered interactively (accept the default or override); under
--no-interaction the detected default is used, so CI/scripted runs don't block. The
answer is written into the generated mcp.json — the first token becomes command and the
rest are prepended to args.

Example

DDEV project (.ddev/ detected):

  $ vendor/bin/mate init
   PHP binary to run Mate for your coding agent [ddev exec php]:
   >

produces:

{
    "mcpServers": {
        "symfony-ai-mate": {
            "command": "ddev",
            "args": ["exec", "php", "vendor/bin/mate", "serve", "--force-keep-alive"]
        }
    }
}

A plain Docker Compose user can instead type e.g. docker compose exec php php.

Note

The non-container default now emits php vendor/bin/mate … rather than the previous
./vendor/bin/mate …. It's functionally equivalent (and a bit more portable), but happy to
special-case plain php back to ./vendor/bin/mate if you'd prefer zero change for the
common case.

I don't use DDEV enough to be sure the detection covers every layout — the .ddev/ check is
deliberately minimal; generic Docker/Sail/Lando are left to the manual override for now.

@carsonbot

Copy link
Copy Markdown
Collaborator

Hey!

To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done?

Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review.

Cheers!

Carsonbot

@fatonh fatonh marked this pull request as ready for review July 2, 2026 20:44
@carsonbot carsonbot added Feature New feature Mate Issues & PRs about the AI Mate component Status: Needs Review labels Jul 2, 2026
@fatonh fatonh force-pushed the mate-init-php-binary branch from 0e09cc8 to ad25eb2 Compare July 2, 2026 20:56
@fatonh

fatonh commented Jul 2, 2026

Copy link
Copy Markdown
Author

@wachterjohannes Heads up: the PHPStan / Demo check fails on a pre-existing error in demo/src/Crop/Image/Resampler.php, which this PR doesn't touch — looks unrelated to the Mate change.

@wachterjohannes

Copy link
Copy Markdown
Contributor

@fatonh already fixed in #2270 😂

@wachterjohannes wachterjohannes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this contribution 🎉

// Create symlink from .mcp.json to mcp.json for compatibility
$mcpJsonPath = $this->rootDir.'/mcp.json';
if (file_exists($mcpJsonPath)) {
$phpBinary = $this->resolvePhpBinary($io);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like the idea of resolving the PHP-Binary here and put that into the mcp.json!

But i would add a replacer to the resource file for mcp.json ##PHP_BINARY## or whatever :) and replace that here.

Comment thread src/mate/src/Command/InitCommand.php Outdated
@fatonh

fatonh commented Jul 4, 2026

Copy link
Copy Markdown
Author

@wachterjohannes thanks! Addressed both issues :)

@fatonh fatonh requested a review from wachterjohannes July 6, 2026 17:10
*
* @return bool whether the file was modified
*/
private function applyPhpBinaryToMcpJson(string $mcpJsonPath, string $phpBinary): bool

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does not realy replace ist parses the json - i thaught about file_get_contents & str_replace & file_put_contents

  mate init generates an mcp.json that the coding agent launches on the
  host. For containerized setups (e.g. DDEV) PHP only exists in the
  container, so the default command fails. init now detects a .ddev/
  directory and offers a sensible default PHP binary (ddev exec php,
  otherwise php), which the user can confirm or override.

  The mcp.json template carries a ##PHP_BINARY## placeholder; init injects
  the resolved binary, splitting a multi-word wrapper (e.g. "ddev exec
  php") into command and args.

  Fix symfony#2264
@fatonh fatonh force-pushed the mate-init-php-binary branch from 3443704 to ed4cfb6 Compare July 6, 2026 19:22
@fatonh fatonh requested a review from wachterjohannes July 6, 2026 19:39
$parts
);
$argsLine = $indent.implode(",\n".$indent, $encoded).",\n";
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks a bit weird especially the $indent thing ... is this realy neccesary?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New feature Mate Issues & PRs about the AI Mate component Status: Needs Work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Mate] mate init generates an .mcp.json that fails under DDEV/Docker (no host PHP)

3 participants