Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ jobs:
- api-platform/openapi
- api-platform/graphql
- api-platform/http-cache
- api-platform/mcp
- api-platform/ramsey-uuid
- api-platform/serializer
- api-platform/state
Expand Down
2 changes: 1 addition & 1 deletion src/Mcp/State/ToolProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(private readonly ObjectMapperInterface $objectMapper

public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
{
if (!isset($context['mcp_request'])) {
if (!isset($context['mcp_request'], $context['mcp_data'])) {
return null;
}

Expand Down
42 changes: 42 additions & 0 deletions src/Mcp/Tests/State/ToolProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Mcp\Tests\State;

use ApiPlatform\Mcp\State\ToolProvider;
use ApiPlatform\Metadata\McpResource;
use Mcp\Schema\Request\ReadResourceRequest;
use PHPUnit\Framework\TestCase;
use Symfony\Component\ObjectMapper\ObjectMapperInterface;

class ToolProviderTest extends TestCase
{
/**
* The handler installs this provider on every MCP operation that declares none,
* MCP resources included, but it only fills `mcp_data` for a tool call: reading
* a resource must not be mapped from a payload that does not exist.
*/
public function testProvideReturnsNullWhenTheRequestCarriesNoToolPayload(): void
{
$objectMapper = $this->createMock(ObjectMapperInterface::class);
$objectMapper->expects($this->never())->method('map');

$provider = new ToolProvider($objectMapper);

$operation = new McpResource(uri: 'dummy://docs', name: 'docs', class: \stdClass::class);

$this->assertNull($provider->provide($operation, [], [
'mcp_request' => new ReadResourceRequest('dummy://docs'),
]));
}
}
15 changes: 13 additions & 2 deletions src/Mcp/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@
"php": ">=8.2",
"api-platform/metadata": "^5.0@alpha",
"api-platform/json-schema": "^5.0@alpha",
"api-platform/state": "^5.0@alpha",
"mcp/sdk": "^0.8",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"symfony/http-foundation": "^7.4 || ^8.0",
"symfony/object-mapper": "^7.4 || ^8.0",
"symfony/polyfill-php85": "^1.32"
"symfony/polyfill-php85": "^1.32",
"symfony/serializer": "^7.4 || ^8.0"
},
"require-dev": {
"phpunit/phpunit": "^11.5 || ^12.2"
"phpunit/phpunit": "^11.5 || ^12.2",
"symfony/expression-language": "^7.4 || ^8.0"
},
"autoload": {
"psr-4": {
Expand All @@ -60,6 +65,12 @@
"url": "https://github.com/api-platform/api-platform"
}
},
"suggest": {
"symfony/expression-language": "To use the operation-level \"security\" expressions."
},
"scripts": {
"test": "./vendor/bin/phpunit"
},
"minimum-stability": "beta",
"prefer-stable": true
}
Loading