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

api-platform / core / 21001095414

14 Jan 2026 04:10PM UTC coverage: 0.0% (-29.1%) from 29.095%
21001095414

Pull #7595

github

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

0 of 476 new or added lines in 16 files covered. (0.0%)

15042 existing lines in 491 files now uncovered.

0 of 58241 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/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\Operation;
17
use ApiPlatform\State\ProcessorInterface;
18
use ApiPlatform\State\SerializerContextBuilderInterface;
19
use Mcp\Schema\Content\TextContent;
20
use Mcp\Schema\JsonRpc\Response;
21
use Mcp\Schema\Result\CallToolResult;
22
use Mcp\Schema\Result\ReadResourceResult;
23
use Symfony\Component\Serializer\Encoder\EncoderInterface;
24
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
25
use Symfony\Component\Serializer\SerializerInterface;
26

27
final class StructuredContentProcessor implements ProcessorInterface
28
{
29
    public function __construct(
30
        private readonly SerializerInterface $serializer,
31
        private readonly SerializerContextBuilderInterface $serializerContextBuilder,
32
        public readonly ProcessorInterface $decorated,
33
    ) {
NEW
34
    }
×
35

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

NEW
47
        $result = $this->decorated->process($data, $operation, $uriVariables, $context);
×
48

NEW
49
        if ($result instanceof CallToolResult || $result instanceof ReadResourceResult) {
×
NEW
50
            return new Response($context['mcp_request']->getId(), $result);
×
51
        }
52

NEW
53
        $context['original_data'] = $result;
×
NEW
54
        $class = $operation->getClass();
×
NEW
55
        $serializerContext = $this->serializerContextBuilder->createFromRequest($request, true, [
×
NEW
56
            'resource_class' => $class,
×
NEW
57
            'operation' => $operation,
×
NEW
58
        ]);
×
59

NEW
60
        $serializerContext['uri_variables'] = $uriVariables;
×
61

NEW
62
        $format = $request->getRequestFormat('') ?: 'json';
×
NEW
63
        $structuredContent = $this->serializer->normalize($result, $format, $serializerContext);
×
NEW
64
        $textContent = $this->serializer->encode($structuredContent, $format, $serializerContext);
×
65

NEW
66
        return new Response(
×
NEW
67
            $context['mcp_request']->getId(),
×
NEW
68
            new CallToolResult(
×
NEW
69
                [new TextContent($textContent)],
×
NEW
70
                false,
×
NEW
71
                \is_array($structuredContent) ? $structuredContent : null,
×
NEW
72
            ),
×
NEW
73
        );
×
74
    }
75
}
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