-
Notifications
You must be signed in to change notification settings - Fork 81
[Server] Feat: Add comprehensive HTTP inspector tests with improved framework #125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
CodeWithKyrian
merged 2 commits into
modelcontextprotocol:main
from
CodeWithKyrian:feat/inspector-tests-for-http
Oct 30, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| <?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. | ||
| */ | ||
|
|
||
| namespace Mcp\Tests\Inspector\Http; | ||
|
|
||
| final class HttpClientCommunicationTest extends HttpInspectorSnapshotTestCase | ||
| { | ||
| protected function setUp(): void | ||
| { | ||
| $this->markTestSkipped('Test skipped: SDK cannot handle logging/setLevel requests required by logging capability, and built-in PHP server does not support sampling.'); | ||
| } | ||
|
|
||
| public static function provideMethods(): array | ||
| { | ||
| return [ | ||
| ...parent::provideMethods(), | ||
| 'Prepare Project Briefing (Simple)' => [ | ||
| 'method' => 'tools/call', | ||
| 'options' => [ | ||
| 'toolName' => 'prepare_project_briefing', | ||
| 'toolArgs' => [ | ||
| 'projectName' => 'Website Redesign', | ||
| 'milestones' => ['Discovery', 'Design', 'Development', 'Testing'], | ||
| ], | ||
| ], | ||
| 'testName' => 'prepare_project_briefing_simple', | ||
| ], | ||
| 'Prepare Project Briefing (Complex)' => [ | ||
| 'method' => 'tools/call', | ||
| 'options' => [ | ||
| 'toolName' => 'prepare_project_briefing', | ||
| 'toolArgs' => [ | ||
| 'projectName' => 'Mobile App Launch', | ||
| 'milestones' => ['Market Research', 'UI/UX Design', 'MVP Development', 'Beta Testing', 'Marketing Campaign', 'Public Launch'], | ||
| ], | ||
| ], | ||
| 'testName' => 'prepare_project_briefing_complex', | ||
| ], | ||
| 'Run Service Maintenance' => [ | ||
| 'method' => 'tools/call', | ||
| 'options' => [ | ||
| 'toolName' => 'run_service_maintenance', | ||
| 'toolArgs' => [ | ||
| 'serviceName' => 'Payment Gateway API', | ||
| ], | ||
| ], | ||
| 'testName' => 'run_service_maintenance', | ||
| ], | ||
| ]; | ||
| } | ||
|
|
||
| protected function getServerScript(): string | ||
| { | ||
| return \dirname(__DIR__, 3).'/examples/http-client-communication/server.php'; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <?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. | ||
| */ | ||
|
|
||
| namespace Mcp\Tests\Inspector\Http; | ||
|
|
||
| final class HttpCombinedRegistrationTest extends HttpInspectorSnapshotTestCase | ||
| { | ||
| public static function provideMethods(): array | ||
| { | ||
| return [ | ||
| ...parent::provideMethods(), | ||
| 'Manual Greeter Tool' => [ | ||
| 'method' => 'tools/call', | ||
| 'options' => [ | ||
| 'toolName' => 'manualGreeter', | ||
| 'toolArgs' => ['user' => 'HTTP Test User'], | ||
| ], | ||
| 'testName' => 'manual_greeter', | ||
| ], | ||
| 'Discovered Status Check Tool' => [ | ||
| 'method' => 'tools/call', | ||
| 'options' => [ | ||
| 'toolName' => 'discovered_status_check', | ||
| 'toolArgs' => [], | ||
| ], | ||
| 'testName' => 'discovered_status_check', | ||
| ], | ||
| 'Read Priority Config (Manual Override)' => [ | ||
| 'method' => 'resources/read', | ||
| 'options' => [ | ||
| 'uri' => 'config://priority', | ||
| ], | ||
| 'testName' => 'config_priority', | ||
| ], | ||
| ]; | ||
| } | ||
|
|
||
| protected function getServerScript(): string | ||
| { | ||
| return \dirname(__DIR__, 3).'/examples/http-combined-registration/server.php'; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| <?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. | ||
| */ | ||
|
|
||
| namespace Mcp\Tests\Inspector\Http; | ||
|
|
||
| final class HttpComplexToolSchemaTest extends HttpInspectorSnapshotTestCase | ||
| { | ||
| public static function provideMethods(): array | ||
| { | ||
| return [ | ||
| ...parent::provideMethods(), | ||
| 'Schedule Event (Meeting with Time)' => [ | ||
| 'method' => 'tools/call', | ||
| 'options' => [ | ||
| 'toolName' => 'schedule_event', | ||
| 'toolArgs' => [ | ||
| 'title' => 'Team Standup', | ||
| 'date' => '2024-12-01', | ||
| 'type' => 'meeting', | ||
| 'time' => '09:00', | ||
| 'priority' => 'normal', | ||
| 'attendees' => ['[email protected]', '[email protected]'], | ||
| 'sendInvites' => true, | ||
| ], | ||
| ], | ||
| 'testName' => 'schedule_event_meeting_with_time', | ||
| ], | ||
| 'Schedule Event (All Day Reminder)' => [ | ||
| 'method' => 'tools/call', | ||
| 'options' => [ | ||
| 'toolName' => 'schedule_event', | ||
| 'toolArgs' => [ | ||
| 'title' => 'Project Deadline', | ||
| 'date' => '2024-12-15', | ||
| 'type' => 'reminder', | ||
| 'priority' => 'high', | ||
| ], | ||
| ], | ||
| 'testName' => 'schedule_event_all_day_reminder', | ||
| ], | ||
| 'Schedule Event (Call with High Priority)' => [ | ||
| 'method' => 'tools/call', | ||
| 'options' => [ | ||
| 'toolName' => 'schedule_event', | ||
| 'toolArgs' => [ | ||
| 'title' => 'Client Call', | ||
| 'date' => '2024-12-02', | ||
| 'type' => 'call', | ||
| 'time' => '14:30', | ||
| 'priority' => 'high', | ||
| 'attendees' => ['[email protected]'], | ||
| 'sendInvites' => false, | ||
| ], | ||
| ], | ||
| 'testName' => 'schedule_event_high_priority', | ||
| ], | ||
| 'Schedule Event (Other Event with Low Priority)' => [ | ||
| 'method' => 'tools/call', | ||
| 'options' => [ | ||
| 'toolName' => 'schedule_event', | ||
| 'toolArgs' => [ | ||
| 'title' => 'Office Party', | ||
| 'date' => '2024-12-20', | ||
| 'type' => 'other', | ||
| 'time' => '18:00', | ||
| 'priority' => 'low', | ||
| 'attendees' => ['[email protected]'], | ||
| ], | ||
| ], | ||
| 'testName' => 'schedule_event_low_priority', | ||
| ], | ||
| ]; | ||
| } | ||
|
|
||
| protected function getServerScript(): string | ||
| { | ||
| return \dirname(__DIR__, 3).'/examples/http-complex-tool-schema/server.php'; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| <?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. | ||
| */ | ||
|
|
||
| namespace Mcp\Tests\Inspector\Http; | ||
|
|
||
| final class HttpDiscoveryUserProfileTest extends HttpInspectorSnapshotTestCase | ||
| { | ||
| public static function provideMethods(): array | ||
| { | ||
| return [ | ||
| ...parent::provideMethods(), | ||
| 'Send Welcome Tool' => [ | ||
| 'method' => 'tools/call', | ||
| 'options' => [ | ||
| 'toolName' => 'send_welcome', | ||
| 'toolArgs' => ['userId' => '101', 'customMessage' => 'Welcome to our platform!'], | ||
| ], | ||
| 'testName' => 'send_welcome', | ||
| ], | ||
| 'Test Tool Without Params' => [ | ||
| 'method' => 'tools/call', | ||
| 'options' => [ | ||
| 'toolName' => 'test_tool_without_params', | ||
| 'toolArgs' => [], | ||
| ], | ||
| 'testName' => 'test_tool_without_params', | ||
| ], | ||
| 'Read User Profile 101' => [ | ||
| 'method' => 'resources/read', | ||
| 'options' => [ | ||
| 'uri' => 'user://101/profile', | ||
| ], | ||
| 'testName' => 'read_user_profile_101', | ||
| ], | ||
| 'Read User Profile 102' => [ | ||
| 'method' => 'resources/read', | ||
| 'options' => [ | ||
| 'uri' => 'user://102/profile', | ||
| ], | ||
| 'testName' => 'read_user_profile_102', | ||
| ], | ||
| 'Read User ID List' => [ | ||
| 'method' => 'resources/read', | ||
| 'options' => [ | ||
| 'uri' => 'user://list/ids', | ||
| ], | ||
| 'testName' => 'read_user_id_list', | ||
| ], | ||
| 'Generate Bio Prompt (Formal)' => [ | ||
| 'method' => 'prompts/get', | ||
| 'options' => [ | ||
| 'promptName' => 'generate_bio_prompt', | ||
| 'promptArgs' => ['userId' => '101', 'tone' => 'formal'], | ||
| ], | ||
| 'testName' => 'generate_bio_prompt', | ||
| ], | ||
| ]; | ||
| } | ||
|
|
||
| protected function getServerScript(): string | ||
| { | ||
| return \dirname(__DIR__, 3).'/examples/http-discovery-userprofile/server.php'; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| <?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. | ||
| */ | ||
|
|
||
| namespace Mcp\Tests\Inspector\Http; | ||
|
|
||
| use Mcp\Tests\Inspector\InspectorSnapshotTestCase; | ||
| use Symfony\Component\Process\Process; | ||
|
|
||
| abstract class HttpInspectorSnapshotTestCase extends InspectorSnapshotTestCase | ||
| { | ||
| private Process $serverProcess; | ||
| private int $serverPort; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
| $this->startServer(); | ||
| } | ||
|
|
||
| protected function tearDown(): void | ||
| { | ||
| $this->stopServer(); | ||
| parent::tearDown(); | ||
| } | ||
|
|
||
| abstract protected function getServerScript(): string; | ||
|
|
||
| protected function getServerConnectionArgs(): array | ||
| { | ||
| return [\sprintf('http://127.0.0.1:%d', $this->serverPort)]; | ||
| } | ||
|
|
||
| protected function getTransport(): string | ||
| { | ||
| return 'http'; | ||
| } | ||
|
|
||
| private function startServer(): void | ||
| { | ||
| $this->serverPort = 8000 + (getmypid() % 1000); | ||
|
|
||
| $this->serverProcess = new Process([ | ||
| 'php', | ||
| '-S', | ||
| \sprintf('127.0.0.1:%d', $this->serverPort), | ||
| $this->getServerScript(), | ||
| ]); | ||
|
|
||
| $this->serverProcess->start(); | ||
|
|
||
| $timeout = 5; // seconds | ||
| $startTime = time(); | ||
|
|
||
| while (time() - $startTime < $timeout) { | ||
| if ($this->serverProcess->isRunning() && $this->isServerReady()) { | ||
| return; | ||
| } | ||
| usleep(100000); // 100ms | ||
| } | ||
|
|
||
| $this->fail(\sprintf('Server failed to start on port %d within %d seconds', $this->serverPort, $timeout)); | ||
| } | ||
|
|
||
| private function stopServer(): void | ||
| { | ||
| if (isset($this->serverProcess)) { | ||
| $this->serverProcess->stop(1, \SIGTERM); | ||
| } | ||
| } | ||
|
|
||
| private function isServerReady(): bool | ||
| { | ||
| $context = stream_context_create([ | ||
| 'http' => [ | ||
| 'timeout' => 1, | ||
| 'method' => 'GET', | ||
| ], | ||
| ]); | ||
|
|
||
| // Try a simple health check - this will likely fail with MCP but should respond | ||
| $response = @file_get_contents(\sprintf('http://127.0.0.1:%d', $this->serverPort), false, $context); | ||
|
|
||
| // We don't care about the response content, just that the server is accepting connections | ||
| return false !== $response || false === str_contains(error_get_last()['message'] ?? '', 'Connection refused'); | ||
| } | ||
|
|
||
| protected function getSnapshotFilePath(string $method, ?string $testName = null): string | ||
| { | ||
| $className = substr(static::class, strrpos(static::class, '\\') + 1); | ||
| $suffix = $testName ? '-'.preg_replace('/[^a-zA-Z0-9_]/', '_', $testName) : ''; | ||
|
|
||
| return __DIR__.'/snapshots/'.$className.'-'.str_replace('/', '_', $method).$suffix.'.json'; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any ideas how to deal with this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the logging part, since logging doesn't need to wait for response, the Built in PHP server still works, we just need to implement handling of
logging/setLevelmethod in the SDK and we're good to go (In another PR obviously)As for sampling, I honestly don't know just yet.