Skip to content

Commit c327112

Browse files
committed
Kicking off adoption of conformance testing
1 parent 50ece31 commit c327112

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Http\Discovery\Psr17Factory;
4+
use Laminas\HttpHandlerRunner\Emitter\SapiEmitter;
5+
use Mcp\Schema\Content\AudioContent;
6+
use Mcp\Schema\Content\ImageContent;
7+
use Mcp\Server;
8+
use Mcp\Server\Session\FileSessionStore;
9+
use Mcp\Server\Transport\StreamableHttpTransport;
10+
11+
require_once dirname(__DIR__, 3).'/vendor/autoload.php';
12+
13+
// Sample base64 encoded 1x1 red PNG pixel for testing
14+
const TEST_IMAGE_BASE64 = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg==';
15+
// Sample base64 encoded minimal WAV file for testing
16+
const TEST_AUDIO_BASE64 = 'UklGRiYAAABXQVZFZm10IBAAAAABAAEAQB8AAAB9AAACABAAZGF0YQIAAAA=';
17+
18+
$server = Server::builder()
19+
->setServerInfo('mcp-conformance-test-server', '1.0.0')
20+
->setSession(new FileSessionStore(__DIR__.'/sessions'))
21+
->addTool(fn () => 'This is a simple text response for testing.', 'test_simple_text', 'Tests simple text content response')
22+
->addTool(fn () => new ImageContent(TEST_IMAGE_BASE64, 'image/png'), 'test_image_content', 'Tests image content response')
23+
->addTool(fn () => new AudioContent(TEST_AUDIO_BASE64, 'audio/wav'), 'test_audio_content', 'Tests audio content response')
24+
->build();
25+
26+
$transport = new StreamableHttpTransport(
27+
(new Psr17Factory())->createServerRequestFromGlobals(),
28+
);
29+
30+
$result = $server->run($transport);
31+
32+
(new SapiEmitter())->emit($result);

0 commit comments

Comments
 (0)