Skip to content

Commit 2153bad

Browse files
committed
Moving conformance server to examples and adding more elements
1 parent 9d9cf75 commit 2153bad

File tree

6 files changed

+129
-44
lines changed

6 files changed

+129
-44
lines changed

.github/workflows/pipeline.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
uses: "ramsey/composer-install@v3"
9191

9292
- name: Run server
93-
run: php -S localhost:8000 tests/Conformance/Server/server.php &
93+
run: php -S localhost:8000 examples/server/conformance/server.php &
9494

9595
- name: Wait for server to start
9696
run: sleep 5
@@ -105,7 +105,7 @@ jobs:
105105
passedTests=$(echo "$OUTPUT" | sed -nE 's/.*Total: ([0-9]+) passed.*/\1/p')
106106
passedTests=${passedTests:-0}
107107
108-
REQUIRED_TESTS_TO_PASS=8
108+
REQUIRED_TESTS_TO_PASS=15
109109
echo "Required tests to pass: $REQUIRED_TESTS_TO_PASS"
110110
[ "$passedTests" -ge "$REQUIRED_TESTS_TO_PASS" ] || exit $exit_code
111111

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ inspector-tests:
2222
vendor/bin/phpunit --testsuite=inspector
2323

2424
conformance-server:
25-
php -S localhost:8000 tests/Conformance/Server/server.php
25+
php -S localhost:8000 examples/server/conformance/server.php
2626

2727
conformance-tests:
2828
npx @modelcontextprotocol/conformance server --url http://localhost:8000/

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"Mcp\\Example\\Server\\ClientLogging\\": "examples/server/client-logging/",
5757
"Mcp\\Example\\Server\\CombinedRegistration\\": "examples/server/combined-registration/",
5858
"Mcp\\Example\\Server\\ComplexToolSchema\\": "examples/server/complex-tool-schema/",
59+
"Mcp\\Example\\Server\\Conformance\\": "examples/server/conformance/",
5960
"Mcp\\Example\\Server\\CustomDependencies\\": "examples/server/custom-dependencies/",
6061
"Mcp\\Example\\Server\\CustomMethodHandlers\\": "examples/server/custom-method-handlers/",
6162
"Mcp\\Example\\Server\\DiscoveryCalculator\\": "examples/server/discovery-calculator/",
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
namespace Mcp\Example\Server\Conformance;
13+
14+
use Mcp\Schema\Content\EmbeddedResource;
15+
use Mcp\Schema\Content\ImageContent;
16+
use Mcp\Schema\Content\PromptMessage;
17+
use Mcp\Schema\Content\TextContent;
18+
use Mcp\Schema\Content\TextResourceContents;
19+
use Mcp\Schema\Enum\Role;
20+
21+
final class Elements
22+
{
23+
// Sample base64 encoded 1x1 red PNG pixel for testing
24+
public const TEST_IMAGE_BASE64 = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg==';
25+
// Sample base64 encoded minimal WAV file for testing
26+
public const TEST_AUDIO_BASE64 = 'UklGRiYAAABXQVZFZm10IBAAAAABAAEAQB8AAAB9AAACABAAZGF0YQIAAAA=';
27+
28+
/**
29+
* @param string $arg1 First test argument
30+
* @param string $arg2 Second test argument
31+
*
32+
* @return PromptMessage[]
33+
*/
34+
public function promptWithArguments(string $arg1, string $arg2): array
35+
{
36+
return [
37+
new PromptMessage(Role::User, new TextContent(\sprintf('Prompt with arguments: arg1="%s", arg2="%s"', $arg1, $arg2))),
38+
];
39+
}
40+
41+
/**
42+
* @param string $resourceUri URI of the resource to embed
43+
*
44+
* @return PromptMessage[]
45+
*/
46+
public function promptWithEmbeddedResource(string $resourceUri): array
47+
{
48+
return [
49+
new PromptMessage(Role::User, EmbeddedResource::fromText($resourceUri, 'Embedded resource content for testing.')),
50+
new PromptMessage(Role::User, new TextContent('Please process the embedded resource above.')),
51+
];
52+
}
53+
54+
/**
55+
* @return PromptMessage[]
56+
*/
57+
public function promptWithImage(): array
58+
{
59+
return [
60+
new PromptMessage(Role::User, new ImageContent(self::TEST_IMAGE_BASE64, 'image/png')),
61+
new PromptMessage(Role::User, new TextContent('Please analyze the image above.')),
62+
];
63+
}
64+
65+
public function resourceTemplate(string $id): TextResourceContents
66+
{
67+
return new TextResourceContents(
68+
uri: 'test://template/{id}/data',
69+
mimeType: 'application/json',
70+
text: json_encode([
71+
'id' => $id,
72+
'templateTest' => true,
73+
'data' => \sprintf('Data for ID: %s', $id),
74+
]),
75+
);
76+
}
77+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
require_once dirname(__DIR__).'/bootstrap.php';
13+
chdir(__DIR__);
14+
15+
use Mcp\Example\Server\Conformance\Elements;
16+
use Mcp\Schema\Content\AudioContent;
17+
use Mcp\Schema\Content\ImageContent;
18+
use Mcp\Server;
19+
use Mcp\Server\Session\FileSessionStore;
20+
21+
logger()->info('Starting MCP Custom Dependencies Server...');
22+
23+
$server = Server::builder()
24+
->setServerInfo('mcp-conformance-test-server', '1.0.0')
25+
->setSession(new FileSessionStore(__DIR__.'/sessions'))
26+
->setLogger(logger())
27+
// Tools
28+
->addTool(fn () => 'This is a simple text response for testing.', 'test_simple_text', 'Tests simple text content response')
29+
->addTool(fn () => new ImageContent(Elements::TEST_IMAGE_BASE64, 'image/png'), 'test_image_content', 'Tests image content response')
30+
->addTool(fn () => new AudioContent(Elements::TEST_AUDIO_BASE64, 'audio/wav'), 'test_audio_content', 'Tests audio content response')
31+
// Resources
32+
->addResource(fn () => 'This is the content of the static text resource.', 'test://static-text', 'static-text', 'A static text resource for testing')
33+
->addResource(fn () => ''/* TODO: Missing Support for Binary? */, 'test://static-binary', 'static-binary', 'A static binary resource (image) for testing')
34+
->addResourceTemplate([Elements::class, 'resourceTemplate'], 'test://template/{id}/data', 'template', 'A resource template with parameter substitution', 'application/json')
35+
// TODO: Handler for resources/subscribe and resources/unsubscribe
36+
->addResource(fn () => 'Watched resource content', 'test://watched-resource', 'watched-resource', 'A resource that auto-updates every 3 seconds')
37+
// Prompts
38+
->addPrompt(fn () => [['role' => 'user', 'content' => 'This is a simple prompt for testing.']], 'test_simple_prompt', 'A simple prompt without arguments')
39+
->addPrompt([Elements::class, 'promptWithArguments'], 'test_prompt_with_arguments', 'A prompt with required arguments')
40+
->addPrompt([Elements::class, 'promptWithEmbeddedResource'], 'test_prompt_with_embedded_resource', 'A prompt that includes an embedded resource')
41+
->addPrompt([Elements::class, 'promptWithImage'], 'test_prompt_with_image', 'A prompt that includes image content')
42+
->build();
43+
44+
$result = $server->run(transport());
45+
46+
logger()->info('Server listener stopped gracefully.', ['result' => $result]);
47+
48+
shutdown($result);

tests/Conformance/Server/server.php

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)