Files
fil/docs/snippets/php/mcp/mcp_server_start.md
Henrik Jess Nielsen b4c07d3693
All checks were successful
Deploy fil (kreuzberg) / deploy (push) Successful in 49s
Nomad changes
2026-06-01 23:40:55 +02:00

811 B

<?php

declare(strict_types=1);

use Symfony\Component\Process\Process;

// Start the Kreuzberg MCP server as a background process
$process = new Process(['kreuzberg', 'mcp']);
$process->start();

$pid = $process->getPid();
echo "MCP server started with PID: {$pid}\n";

// Wait for server to initialize
sleep(1);

if ($process->isRunning()) {
    echo "Server is running, listening for connections\n";
    echo "Server output: " . $process->getOutput() . "\n";
} else {
    echo "Server failed to start\n";
    echo "Error: " . $process->getErrorOutput() . "\n";
}

// Keep process running or register shutdown handler
register_shutdown_function(function () use ($process): void {
    if ($process->isRunning()) {
        $process->stop();
        echo "MCP server stopped\n";
    }
});