Skip to content

Commit a7b8b8f

Browse files
committed
fixes
1 parent 03f9cb3 commit a7b8b8f

File tree

13 files changed

+72
-41
lines changed

13 files changed

+72
-41
lines changed

src/Mcp/Capability/Registry/Loader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
use ApiPlatform\Metadata\McpTool;
2121
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
2222
use ApiPlatform\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
23-
use ApiPlatform\Symfony\Controller\McpController;
2423
use Mcp\Capability\Registry\Loader\LoaderInterface;
2524
use Mcp\Capability\RegistryInterface;
2625
use Mcp\Schema\Annotations;
2726
use Mcp\Schema\Resource;
2827
use Mcp\Schema\Tool;
28+
use Mcp\Schema\ToolAnnotations;
2929

3030
final class Loader implements LoaderInterface
3131
{
@@ -53,7 +53,7 @@ public function load(RegistryInterface $registry): void
5353
name: $mcp->getName(),
5454
inputSchema: $schema->getDefinitions()[$schema->getRootDefinitionKey()]->getArrayCopy(),
5555
description: $mcp->getDescription(),
56-
annotations: $mcp->getAnnotations() ? Annotations::fromArray($mcp->getAnnotations()) : null,
56+
annotations: $mcp->getAnnotations() ? ToolAnnotations::fromArray($mcp->getAnnotations()) : null,
5757
icons: $mcp->getIcons(),
5858
meta: $mcp->getMeta()
5959
),

src/Mcp/Routing/IriConverter.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
<?php
22

3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
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+
declare(strict_types=1);
13+
314
namespace ApiPlatform\Mcp\Routing;
415

516
use ApiPlatform\Metadata\IriConverterInterface;

src/Mcp/Server/Handler.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
<?php
22

3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
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+
declare(strict_types=1);
13+
314
/*
415
* This file is part of the official PHP MCP SDK.
516
*
@@ -11,15 +22,11 @@
1122

1223
namespace ApiPlatform\Mcp\Server;
1324

14-
use ApiPlatform\Mcp\State\ToolProvider;
25+
use ApiPlatform\Metadata\Exception\RuntimeException;
26+
use ApiPlatform\Metadata\HttpOperation;
1527
use ApiPlatform\Metadata\Operation\Factory\OperationMetadataFactoryInterface;
1628
use ApiPlatform\State\ProcessorInterface;
1729
use ApiPlatform\State\ProviderInterface;
18-
use Mcp\Capability\Registry\ReferenceHandlerInterface;
19-
use Mcp\Capability\RegistryInterface;
20-
use Mcp\Exception\ToolCallException;
21-
use Mcp\Exception\ToolNotFoundException;
22-
use Mcp\Schema\Content\TextContent;
2330
use Mcp\Schema\JsonRpc\Error;
2431
use Mcp\Schema\JsonRpc\Request;
2532
use Mcp\Schema\JsonRpc\Response;
@@ -64,6 +71,10 @@ public function handle(Request $request, SessionInterface $session): Response|Er
6471

6572
$operation = $this->operationMetadataFactory->create($toolName);
6673

74+
if (!$operation instanceof HttpOperation) {
75+
throw new RuntimeException(\sprintf('Operation "%s" must be an instance of HttpOperation.', $toolName));
76+
}
77+
6778
$uriVariables = [];
6879
foreach ($operation->getUriVariables() ?? [] as $key => $link) {
6980
if (isset($arguments[$key])) {

src/Mcp/State/StructuredContentProcessor.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Mcp\Schema\Content\TextContent;
2020
use Mcp\Schema\JsonRpc\Response;
2121
use Mcp\Schema\Result\CallToolResult;
22-
use Symfony\Component\Serializer\Encoder\ContextAwareEncoderInterface;
2322
use Symfony\Component\Serializer\Encoder\EncoderInterface;
2423
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
2524
use Symfony\Component\Serializer\SerializerInterface;
@@ -60,12 +59,12 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
6059
$structuredContent = $this->serializer->normalize($data, $format = $request->getRequestFormat(), $serializerContext);
6160

6261
return new Response(
63-
$context['mcp_request']->getId(),
64-
new CallToolResult(
65-
[new TextContent($this->serializer->encode($structuredContent, $format, $serializerContext))],
66-
false,
67-
$structuredContent,
68-
),
69-
);
62+
$context['mcp_request']->getId(),
63+
new CallToolResult(
64+
[new TextContent($this->serializer->encode($structuredContent, $format, $serializerContext))],
65+
false,
66+
$structuredContent,
67+
),
68+
);
7069
}
7170
}

src/Mcp/State/ToolProvider.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
<?php
22

3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
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+
declare(strict_types=1);
13+
314
namespace ApiPlatform\Mcp\State;
415

516
use ApiPlatform\Metadata\Operation;
@@ -23,6 +34,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
2334

2435
$data = (object) $context['mcp_data'];
2536
$class = $operation->getInput()['class'] ?? $operation->getClass();
37+
2638
return $this->objectMapper->map($data, $class);
2739
}
2840
}

src/Metadata/ApiResource.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,9 +1031,6 @@ class: $class,
10311031
}
10321032
}
10331033

1034-
/**
1035-
* @return Operations<HttpOperation>|null
1036-
*/
10371034
public function getMcp(): ?array
10381035
{
10391036
return $this->mcp;
@@ -1047,6 +1044,9 @@ public function withMcp(array $mcp): static
10471044
return $self;
10481045
}
10491046

1047+
/**
1048+
* @return Operations<HttpOperation>|null
1049+
*/
10501050
public function getOperations(): ?Operations
10511051
{
10521052
return $this->operations;

src/Metadata/McpResource.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
final class McpResource extends HttpOperation
2424
{
2525
/**
26-
* @param string $uri The specific URI identifying this resource instance. Must be unique within the server.
27-
* @param ?string $name A human-readable name for this resource. If null, a default might be generated from the method name.
28-
* @param ?string $description An optional description of the resource. Defaults to class DocBlock summary.
29-
* @param ?string $mimeType the MIME type, if known and constant for this resource
30-
* @param ?int $size the size in bytes, if known and constant
31-
* @param mixed|null $annotations optional annotations describing the resource
32-
* @param array|null $icons Optional list of icon URLs representing the resource
33-
* @param array<string, mixed>|null $meta Optional metadata
26+
* @param string $uri The specific URI identifying this resource instance. Must be unique within the server.
27+
* @param ?string $name A human-readable name for this resource. If null, a default might be generated from the method name.
28+
* @param ?string $description An optional description of the resource. Defaults to class DocBlock summary.
29+
* @param ?string $mimeType the MIME type, if known and constant for this resource
30+
* @param ?int $size the size in bytes, if known and constant
31+
* @param mixed|null $annotations optional annotations describing the resource
32+
* @param array|null $icons Optional list of icon URLs representing the resource
33+
* @param array<string, mixed>|null $meta Optional metadata
3434
* @param string[]|null $types the RDF types of this property
3535
* @param array<int|string, string|string[]>|string|null $formats {@see https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation}
3636
* @param array<int|string, string|string[]>|string|null $inputFormats {@see https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation}

src/Metadata/McpTool.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
final class McpTool extends HttpOperation
2424
{
2525
/**
26-
* @param string|null $name The name of the tool (defaults to the method name)
27-
* @param string|null $description The description of the tool (defaults to the DocBlock/inferred)
28-
* @param mixed|null $annotations Optional annotations describing tool behavior
29-
* @param array|null $icons Optional list of icon URLs representing the tool
30-
* @param array<string, mixed>|null $meta Optional metadata
26+
* @param string|null $name The name of the tool (defaults to the method name)
27+
* @param string|null $description The description of the tool (defaults to the DocBlock/inferred)
28+
* @param mixed|null $annotations Optional annotations describing tool behavior
29+
* @param array|null $icons Optional list of icon URLs representing the tool
30+
* @param array<string, mixed>|null $meta Optional metadata
3131
* @param string[]|null $types the RDF types of this property
3232
* @param array<int|string, string|string[]>|string|null $formats {@see https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation}
3333
* @param array<int|string, string|string[]>|string|null $inputFormats {@see https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation}

src/Metadata/Metadata.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ public function __construct(
8383
protected ?bool $jsonStream = null,
8484
protected ?bool $map = null,
8585
protected array $extraProperties = [],
86-
8786
) {
8887
if (\is_array($parameters) && $parameters) {
8988
$parameters = new Parameters($parameters);
@@ -92,10 +91,6 @@ public function __construct(
9291
$this->parameters = $parameters;
9392
}
9493

95-
96-
97-
98-
9994
public function canMap(): ?bool
10095
{
10196
return $this->map;

src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
use Doctrine\Persistence\ManagerRegistry;
6868
use PHPStan\PhpDocParser\Parser\PhpDocParser;
6969
use Ramsey\Uuid\Uuid;
70+
use Symfony\AI\McpBundle\McpBundle;
7071
use Symfony\Bundle\FrameworkBundle\Command\TranslationExtractCommand;
7172
use Symfony\Bundle\FrameworkBundle\Controller\ControllerHelper;
7273
use Symfony\Component\Config\FileLocator;
@@ -88,7 +89,6 @@
8889
use Symfony\Component\Uid\AbstractUid;
8990
use Symfony\Component\Validator\Validator\ValidatorInterface;
9091
use Symfony\Component\Yaml\Yaml;
91-
use Symfony\AI\McpBundle\McpBundle;
9292
use Twig\Environment;
9393

9494
/**

0 commit comments

Comments
 (0)