Skip to content

Stdio Transport Processes Not Terminating, Causing Multiple Running Instances #1

@alifawadhassan

Description

@alifawadhassan

When using the Stdio transport, server processes don't terminate after requests complete. Each new request spawns another process, causing resource leaks.

We patched the vendor files with a cleanup routine that forcibly kills the subprocess:

Added getter to "/vendor/php-mcp/client/src/Client.php":

public function getTransport(): ?TransportInterface {
    return $this->transport;
}

Added getter to "/vendor/php-mcp/client/src/Transport/Stdio/StdioClientTransport.php":

public function getProcess(): ?Process {
    return $this->process;
}

Used SIGKILL in the finally block of our request wrapper:

finally {
    if (isset($stdioClient)) {
        $transport = $stdioClient->getTransport();

        if ($transport instanceof \PhpMcp\Client\Transport\Stdio\StdioClientTransport) {
            $process = $transport->getProcess();
            if ($process && $process->isRunning()) {
                $process->terminate(SIGKILL); // Forcibly terminate
            }
        }

        $stdioClient->disconnect();
        return $response;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions