Skip to content

Commit 3fdd800

Browse files
committed
Kicking off adoption of conformance testing
1 parent 32757f6 commit 3fdd800

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ vendor
66
examples/**/dev.log
77
examples/**/cache
88
examples/**/sessions
9+
results
10+
tests/Conformance/**/sessions

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ unit-tests:
2121
inspector-tests:
2222
vendor/bin/phpunit --testsuite=inspector
2323

24+
conformance-server:
25+
php -S localhost:8000 tests/Conformance/Server/server.php
26+
27+
conformance-tests:
28+
npx @modelcontextprotocol/conformance server --url http://localhost:8000/
29+
2430
coverage:
2531
XDEBUG_MODE=coverage vendor/bin/phpunit --testsuite=unit --coverage-html=coverage
2632

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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

Comments
 (0)