|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the official PHP MCP SDK. |
| 5 | + * |
| 6 | + * A collaboration between Symfony and the PHP Foundation. |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +use Http\Discovery\Psr17Factory; |
| 13 | +use Laminas\HttpHandlerRunner\Emitter\SapiEmitter; |
| 14 | +use Mcp\Schema\Content\AudioContent; |
| 15 | +use Mcp\Schema\Content\ImageContent; |
| 16 | +use Mcp\Server; |
| 17 | +use Mcp\Server\Session\FileSessionStore; |
| 18 | +use Mcp\Server\Transport\StreamableHttpTransport; |
| 19 | + |
| 20 | +require_once dirname(__DIR__, 3).'/vendor/autoload.php'; |
| 21 | + |
| 22 | +// Sample base64 encoded 1x1 red PNG pixel for testing |
| 23 | +const TEST_IMAGE_BASE64 = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg=='; |
| 24 | +// Sample base64 encoded minimal WAV file for testing |
| 25 | +const TEST_AUDIO_BASE64 = 'UklGRiYAAABXQVZFZm10IBAAAAABAAEAQB8AAAB9AAACABAAZGF0YQIAAAA='; |
| 26 | + |
| 27 | +$server = Server::builder() |
| 28 | + ->setServerInfo('mcp-conformance-test-server', '1.0.0') |
| 29 | + ->setSession(new FileSessionStore(__DIR__.'/sessions')) |
| 30 | + ->addTool(fn () => 'This is a simple text response for testing.', 'test_simple_text', 'Tests simple text content response') |
| 31 | + ->addTool(fn () => new ImageContent(TEST_IMAGE_BASE64, 'image/png'), 'test_image_content', 'Tests image content response') |
| 32 | + ->addTool(fn () => new AudioContent(TEST_AUDIO_BASE64, 'audio/wav'), 'test_audio_content', 'Tests audio content response') |
| 33 | + ->build(); |
| 34 | + |
| 35 | +$transport = new StreamableHttpTransport( |
| 36 | + (new Psr17Factory())->createServerRequestFromGlobals(), |
| 37 | +); |
| 38 | + |
| 39 | +$result = $server->run($transport); |
| 40 | + |
| 41 | +(new SapiEmitter())->emit($result); |
0 commit comments