• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 21031030191

15 Jan 2026 12:18PM UTC coverage: 29.582% (+0.5%) from 29.097%
21031030191

Pull #7595

github

web-flow
Merge cc5f55cf5 into 73402fc61
Pull Request #7595: feat: mcp bundle tool integration

407 of 486 new or added lines in 16 files covered. (83.74%)

424 existing lines in 19 files now uncovered.

17417 of 58878 relevant lines covered (29.58%)

81.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.67
/src/Mcp/State/StructuredContentProcessor.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
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

14
namespace ApiPlatform\Mcp\State;
15

16
use ApiPlatform\Metadata\McpResource;
17
use ApiPlatform\Metadata\McpTool;
18
use ApiPlatform\Metadata\Operation;
19
use ApiPlatform\State\ProcessorInterface;
20
use ApiPlatform\State\SerializerContextBuilderInterface;
21
use Mcp\Schema\Content\TextContent;
22
use Mcp\Schema\JsonRpc\Response;
23
use Mcp\Schema\Result\CallToolResult;
24
use Mcp\Schema\Result\ReadResourceResult;
25
use Symfony\Component\Serializer\Encoder\EncoderInterface;
26
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
27
use Symfony\Component\Serializer\SerializerInterface;
28

29
final class StructuredContentProcessor implements ProcessorInterface
30
{
31
    public function __construct(
32
        private readonly SerializerInterface $serializer,
33
        private readonly SerializerContextBuilderInterface $serializerContextBuilder,
34
        public readonly ProcessorInterface $decorated,
35
    ) {
36
    }
24✔
37

38
    public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = [])
39
    {
40
        if (
41
            !$this->serializer instanceof NormalizerInterface
22✔
42
            || !$this->serializer instanceof EncoderInterface
22✔
43
            || !isset($context['mcp_request'])
22✔
44
            || !($request = $context['request'])
22✔
45
        ) {
NEW
46
            return $this->decorated->process($data, $operation, $uriVariables, $context);
×
47
        }
48

49
        $result = $this->decorated->process($data, $operation, $uriVariables, $context);
22✔
50

51
        if ($result instanceof CallToolResult || $result instanceof ReadResourceResult) {
22✔
52
            return new Response($context['mcp_request']->getId(), $result);
10✔
53
        }
54

55
        $context['original_data'] = $result;
12✔
56
        $class = $operation->getClass();
12✔
57
        $includeStructuredContent = $operation instanceof McpTool || $operation instanceof McpResource ? $operation->getStructuredContent() ?? true : false;
12✔
58
        $structuredContent = null;
12✔
59

60
        if ($includeStructuredContent) {
12✔
61
            $serializerContext = $this->serializerContextBuilder->createFromRequest($request, true, [
12✔
62
                'resource_class' => $class,
12✔
63
                'operation' => $operation,
12✔
64
            ]);
12✔
65
            $serializerContext['uri_variables'] = $uriVariables;
12✔
66
            $format = $request->getRequestFormat('') ?: 'json';
12✔
67
            $structuredContent = $this->serializer->normalize($result, $format, $serializerContext);
12✔
68
            $result = $this->serializer->encode($structuredContent, $format, $serializerContext);
12✔
69
        }
70

71
        return new Response(
12✔
72
            $context['mcp_request']->getId(),
12✔
73
            new CallToolResult(
12✔
74
                [new TextContent($result)],
12✔
75
                false,
12✔
76
                $structuredContent
12✔
77
            ),
12✔
78
        );
12✔
79
    }
80
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc