php-sdk/tests/Integration/Fixture/retry.php
Christopher Hertel d8cc21a345
[Client] Implement setMaxRetries connection retries (#413)
* [Client] Implement setMaxRetries connection retries

* [Client] Reject a negative retry count in Configuration

* [Client] Use a positive init timeout in the retry test

* [Client] Drop redundant docblock note on setMaxRetries

* [Client] Clear the initialized flag on a failed connection

* [Client] Trim comments to the non-obvious ones

* [Client] Cover retries and timeout cleanup with integration tests

The retry fixture counts the processes it was started as, which is what
separates a real retry from a second call into the same server. The timeout
fixture outlives the client's patience and then goes idle, so the next
request runs on a connection the client already gave up on once.
2026-08-15 02:43:50 +02:00

46 lines
1.1 KiB
PHP

<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*
* Server for {@see \Mcp\Tests\Integration\RetryTest}.
*
* Dies before speaking a frame while the spawn counter is below the configured
* number of failures, so the counter file records how many processes the client
* actually started.
*/
use Mcp\Server;
use Mcp\Server\Transport\StdioTransport;
require_once dirname(__DIR__, 3).'/vendor/autoload.php';
$counter = getenv('MCP_SPAWN_COUNTER');
if (!is_string($counter) || '' === $counter) {
exit(1);
}
$spawns = 1 + (int) file_get_contents($counter);
file_put_contents($counter, (string) $spawns);
if ($spawns <= (int) getenv('MCP_FAIL_SPAWNS')) {
exit(1);
}
Server::builder()
->setServerInfo('integration-server', '1.0.0')
->addTool(
static fn (): string => 'quick',
name: 'fast',
description: 'Returns at once.',
)
->build()
->run(new StdioTransport());