php-sdk/examples/stdio-discovery-calculator/server.php
2025-10-04 19:45:40 +02:00

34 lines
848 B
PHP

#!/usr/bin/env 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.
*/
require_once dirname(__DIR__).'/bootstrap.php';
chdir(__DIR__);
use Mcp\Server;
use Mcp\Server\Transport\StdioTransport;
logger()->info('Starting MCP Stdio Calculator Server...');
$server = Server::builder()
->setServerInfo('Stdio Calculator', '1.1.0', 'Basic Calculator over STDIO transport.')
->setContainer(container())
->setLogger(logger())
->setDiscovery(__DIR__, ['.'])
->build();
$transport = new StdioTransport(logger: logger());
$server->connect($transport);
$transport->listen();
logger()->info('Server listener stopped gracefully.');