Add more inspector tests for functionality tests of STDIO examples (#115)

This commit is contained in:
Christopher Hertel 2025-10-27 01:09:25 +01:00 • committed by GitHub
commit 7190bee153
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 286 additions and 15 deletions

View file

@ -13,8 +13,8 @@ namespace Mcp\Example\StdioCustomDependencies;
use Mcp\Capability\Attribute\McpResource;
use Mcp\Capability\Attribute\McpTool;
use Mcp\Example\DependenciesStdioExample\Service\StatsServiceInterface;
use Mcp\Example\DependenciesStdioExample\Service\TaskRepositoryInterface;
use Mcp\Example\StdioCustomDependencies\Service\StatsServiceInterface;
use Mcp\Example\StdioCustomDependencies\Service\TaskRepositoryInterface;
use Psr\Log\LoggerInterface;
/**

View file

@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
namespace Mcp\Example\DependenciesStdioExample\Service;
namespace Mcp\Example\StdioCustomDependencies\Service;
use Psr\Log\LoggerInterface;

View file

@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
namespace Mcp\Example\DependenciesStdioExample\Service;
namespace Mcp\Example\StdioCustomDependencies\Service;
interface StatsServiceInterface
{

View file

@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
namespace Mcp\Example\DependenciesStdioExample\Service;
namespace Mcp\Example\StdioCustomDependencies\Service;
final class SystemStatsService implements StatsServiceInterface
{

View file

@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
namespace Mcp\Example\DependenciesStdioExample\Service;
namespace Mcp\Example\StdioCustomDependencies\Service;
/**
* @phpstan-type Task array{id: int, userId: string, description: string, completed: bool, createdAt: string}

View file

@ -13,10 +13,10 @@
require_once dirname(__DIR__).'/bootstrap.php';
chdir(__DIR__);
use Mcp\Example\DependenciesStdioExample\Service\InMemoryTaskRepository;
use Mcp\Example\DependenciesStdioExample\Service\StatsServiceInterface;
use Mcp\Example\DependenciesStdioExample\Service\SystemStatsService;
use Mcp\Example\DependenciesStdioExample\Service\TaskRepositoryInterface;
use Mcp\Example\StdioCustomDependencies\Service\InMemoryTaskRepository;
use Mcp\Example\StdioCustomDependencies\Service\StatsServiceInterface;
use Mcp\Example\StdioCustomDependencies\Service\SystemStatsService;
use Mcp\Example\StdioCustomDependencies\Service\TaskRepositoryInterface;
use Mcp\Server;
use Mcp\Server\Transport\StdioTransport;

View file

@ -0,0 +1,29 @@
<?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 Inspector;
use Mcp\Tests\Inspector\InspectorSnapshotTestCase;
final class StdioCachedDiscoveryTest extends InspectorSnapshotTestCase
{
public static function provideMethods(): array
{
return [
...parent::provideListMethods(),
];
}
protected function getServerScript(): string
{
return \dirname(__DIR__, 2).'/examples/stdio-cached-discovery/server.php';
}
}

View file

@ -0,0 +1,29 @@
<?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 Inspector;
use Mcp\Tests\Inspector\InspectorSnapshotTestCase;
final class StdioCustomDependenciesTest extends InspectorSnapshotTestCase
{
public static function provideMethods(): array
{
return [
...parent::provideListMethods(),
];
}
protected function getServerScript(): string
{
return \dirname(__DIR__, 2).'/examples/stdio-custom-dependencies/server.php';
}
}

View file

@ -0,0 +1,38 @@
<?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;
final class StdioDiscoveryCalculatorTest extends InspectorSnapshotTestCase
{
public static function provideMethods(): array
{
return [
...parent::provideListMethods(),
'Calculate Sum' => [
'method' => 'tools/call',
'toolName' => 'calculate',
'toolArgs' => ['a' => 12.5, 'b' => 7.3, 'operation' => 'add'],
],
'Read Config' => [
'method' => 'resources/read',
'toolName' => null, // can be removed with newer PHPUnit versions
'toolArgs' => [], // can be removed with newer PHPUnit versions
'uri' => 'config://calculator/settings',
],
];
}
protected function getServerScript(): string
{
return \dirname(__DIR__, 2).'/examples/stdio-discovery-calculator/server.php';
}
}

View file

@ -0,0 +1,29 @@
<?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 Inspector;
use Mcp\Tests\Inspector\InspectorSnapshotTestCase;
final class StdioEnvVariablesTest extends InspectorSnapshotTestCase
{
public static function provideMethods(): array
{
return [
...parent::provideListMethods(),
];
}
protected function getServerScript(): string
{
return \dirname(__DIR__, 2).'/examples/stdio-env-variables/server.php';
}
}

View file

@ -0,0 +1,29 @@
<?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 Inspector;
use Mcp\Tests\Inspector\InspectorSnapshotTestCase;
final class StdioExplicitRegistrationTest extends InspectorSnapshotTestCase
{
public static function provideMethods(): array
{
return [
...parent::provideListMethods(),
];
}
protected function getServerScript(): string
{
return \dirname(__DIR__, 2).'/examples/stdio-explicit-registration/server.php';
}
}

View file

@ -0,0 +1,3 @@
{
"prompts": []
}

View file

@ -0,0 +1,3 @@
{
"resources": []
}

View file

@ -0,0 +1,3 @@
{
"resourceTemplates": []
}

View file

@ -0,0 +1,76 @@
{
"tools": [
{
"name": "add_numbers",
"inputSchema": {
"type": "object",
"properties": {
"a": {
"type": "integer"
},
"b": {
"type": "integer"
}
},
"required": [
"a",
"b"
]
}
},
{
"name": "multiply_numbers",
"inputSchema": {
"type": "object",
"properties": {
"a": {
"type": "integer"
},
"b": {
"type": "integer"
}
},
"required": [
"a",
"b"
]
}
},
{
"name": "divide_numbers",
"inputSchema": {
"type": "object",
"properties": {
"a": {
"type": "integer"
},
"b": {
"type": "integer"
}
},
"required": [
"a",
"b"
]
}
},
{
"name": "power",
"inputSchema": {
"type": "object",
"properties": {
"base": {
"type": "integer"
},
"exponent": {
"type": "integer"
}
},
"required": [
"base",
"exponent"
]
}
}
]
}

View file

@ -0,0 +1,3 @@
{
"prompts": []
}

View file

@ -0,0 +1,10 @@
{
"resources": [
{
"name": "system_stats",
"uri": "stats://system/overview",
"description": "Provides current system statistics.",
"mimeType": "application/json"
}
]
}

View file

@ -0,0 +1,3 @@
{
"resourceTemplates": []
}

View file

@ -0,0 +1,57 @@
{
"tools": [
{
"name": "add_task",
"description": "Adds a new task for a given user.",
"inputSchema": {
"type": "object",
"properties": {
"userId": {
"type": "string",
"description": "the ID of the user"
},
"description": {
"type": "string",
"description": "the task description"
}
},
"required": [
"userId",
"description"
]
}
},
{
"name": "list_user_tasks",
"description": "Lists pending tasks for a specific user.",
"inputSchema": {
"type": "object",
"properties": {
"userId": {
"type": "string",
"description": "the ID of the user"
}
},
"required": [
"userId"
]
}
},
{
"name": "complete_task",
"description": "Marks a task as complete.",
"inputSchema": {
"type": "object",
"properties": {
"taskId": {
"type": "integer",
"description": "the ID of the task to complete"
}
},
"required": [
"taskId"
]
}
}
]
}

View file

@ -0,0 +1,3 @@
{
"prompts": []
}

Some files were not shown because too many files have changed in this diff Show more