-
-
Notifications
You must be signed in to change notification settings - Fork 119
[MCP Bundle] Add MCP profiler support to display server capabilities #866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
camilleislasse
wants to merge
3
commits into
symfony:main
Choose a base branch
from
camilleislasse:add-profiler
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Symfony package. | ||
| * | ||
| * (c) Fabien Potencier <[email protected]> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Symfony\AI\McpBundle\Profiler; | ||
|
|
||
| use Mcp\Schema\Prompt; | ||
| use Mcp\Schema\Resource; | ||
| use Mcp\Schema\ResourceTemplate; | ||
| use Mcp\Schema\Tool; | ||
| use Symfony\AI\McpBundle\Profiler\Loader\ProfilingLoader; | ||
| use Symfony\Bundle\FrameworkBundle\DataCollector\AbstractDataCollector; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
| use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface; | ||
|
|
||
| /** | ||
| * Collects MCP server capabilities for the Web Profiler. | ||
| * | ||
| * @author Camille Islasse <[email protected]> | ||
| */ | ||
| final class DataCollector extends AbstractDataCollector implements LateDataCollectorInterface | ||
| { | ||
| public function __construct( | ||
| private readonly ProfilingLoader $profilingLoader, | ||
| ) { | ||
| } | ||
|
|
||
| public function collect(Request $request, Response $response, ?\Throwable $exception = null): void | ||
| { | ||
| } | ||
|
|
||
| public function lateCollect(): void | ||
| { | ||
| $registry = $this->profilingLoader->getRegistry(); | ||
|
|
||
| if (null === $registry) { | ||
| $this->data = [ | ||
| 'tools' => [], | ||
| 'prompts' => [], | ||
| 'resources' => [], | ||
| 'resourceTemplates' => [], | ||
| ]; | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| $tools = []; | ||
| foreach ($registry->getTools()->references as $item) { | ||
| if (!$item instanceof Tool) { | ||
| continue; | ||
| } | ||
|
|
||
| $tools[] = [ | ||
| 'name' => $item->name, | ||
| 'description' => $item->description, | ||
| 'inputSchema' => $item->inputSchema, | ||
| ]; | ||
| } | ||
|
|
||
| $prompts = []; | ||
| foreach ($registry->getPrompts()->references as $item) { | ||
| if (!$item instanceof Prompt) { | ||
| continue; | ||
| } | ||
|
|
||
| $prompts[] = [ | ||
| 'name' => $item->name, | ||
| 'description' => $item->description, | ||
| 'arguments' => array_map(fn ($arg) => [ | ||
| 'name' => $arg->name, | ||
| 'description' => $arg->description, | ||
| 'required' => $arg->required, | ||
| ], $item->arguments ?? []), | ||
| ]; | ||
| } | ||
|
|
||
| $resources = []; | ||
| foreach ($registry->getResources()->references as $item) { | ||
| if (!$item instanceof Resource) { | ||
| continue; | ||
| } | ||
|
|
||
| $resources[] = [ | ||
| 'uri' => $item->uri, | ||
| 'name' => $item->name, | ||
| 'description' => $item->description, | ||
| 'mimeType' => $item->mimeType, | ||
| ]; | ||
| } | ||
|
|
||
| $resourceTemplates = []; | ||
| foreach ($registry->getResourceTemplates()->references as $item) { | ||
| if (!$item instanceof ResourceTemplate) { | ||
| continue; | ||
| } | ||
|
|
||
| $resourceTemplates[] = [ | ||
| 'uriTemplate' => $item->uriTemplate, | ||
| 'name' => $item->name, | ||
| 'description' => $item->description, | ||
| 'mimeType' => $item->mimeType, | ||
| ]; | ||
| } | ||
|
|
||
| $this->data = [ | ||
| 'tools' => $tools, | ||
| 'prompts' => $prompts, | ||
| 'resources' => $resources, | ||
| 'resourceTemplates' => $resourceTemplates, | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * @return array<array{name: string, description: ?string, inputSchema: array<mixed>}> | ||
| */ | ||
| public function getTools(): array | ||
| { | ||
| return $this->data['tools'] ?? []; | ||
| } | ||
|
|
||
| /** | ||
| * @return array<array{name: string, description: ?string, arguments: array<mixed>}> | ||
| */ | ||
| public function getPrompts(): array | ||
| { | ||
| return $this->data['prompts'] ?? []; | ||
| } | ||
|
|
||
| /** | ||
| * @return array<array{uri: string, name: string, description: ?string, mimeType: ?string}> | ||
| */ | ||
| public function getResources(): array | ||
| { | ||
| return $this->data['resources'] ?? []; | ||
| } | ||
|
|
||
| /** | ||
| * @return array<array{uriTemplate: string, name: string, description: ?string, mimeType: ?string}> | ||
| */ | ||
| public function getResourceTemplates(): array | ||
| { | ||
| return $this->data['resourceTemplates'] ?? []; | ||
| } | ||
|
|
||
| public function getTotalCount(): int | ||
| { | ||
| return \count($this->getTools()) + \count($this->getPrompts()) + \count($this->getResources()) + \count($this->getResourceTemplates()); | ||
| } | ||
|
|
||
| public static function getTemplate(): string | ||
| { | ||
| return '@Mcp/data_collector.html.twig'; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Symfony package. | ||
| * | ||
| * (c) Fabien Potencier <[email protected]> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Symfony\AI\McpBundle\Profiler\Loader; | ||
|
|
||
| use Mcp\Capability\Registry\Loader\LoaderInterface; | ||
| use Mcp\Capability\Registry\ReferenceProviderInterface; | ||
| use Mcp\Capability\Registry\ReferenceRegistryInterface; | ||
|
|
||
| /** | ||
| * @author Camille Islasse <[email protected]> | ||
| */ | ||
| final class ProfilingLoader implements LoaderInterface | ||
| { | ||
| private ?ReferenceProviderInterface $registry = null; | ||
|
|
||
| public function load(ReferenceRegistryInterface $registry): void | ||
| { | ||
| $this->registry = $registry instanceof ReferenceProviderInterface ? $registry : null; | ||
| } | ||
|
|
||
| public function getRegistry(): ?ReferenceProviderInterface | ||
| { | ||
| return $this->registry; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| {% extends '@WebProfiler/Profiler/layout.html.twig' %} | ||
|
|
||
| {% block toolbar %} | ||
| {% if collector.totalCount > 0 %} | ||
| {% set icon %} | ||
| {{ include('@Mcp/icon.svg', { y: 18 }) }} | ||
| <span class="sf-toolbar-value">{{ collector.totalCount }}</span> | ||
| <span class="sf-toolbar-info-piece-additional-detail"> | ||
| <span class="sf-toolbar-label">capabilities</span> | ||
| </span> | ||
| {% endset %} | ||
|
|
||
| {% set text %} | ||
| <div class="sf-toolbar-info-piece"> | ||
| <b class="label">Tools</b> | ||
| <span class="sf-toolbar-status">{{ collector.tools|length }}</span> | ||
| </div> | ||
| <div class="sf-toolbar-info-piece"> | ||
| <b class="label">Prompts</b> | ||
| <span class="sf-toolbar-status">{{ collector.prompts|length }}</span> | ||
| </div> | ||
| <div class="sf-toolbar-info-piece"> | ||
| <b class="label">Resources</b> | ||
| <span class="sf-toolbar-status">{{ collector.resources|length }}</span> | ||
| </div> | ||
| <div class="sf-toolbar-info-piece"> | ||
| <b class="label">Resource Templates</b> | ||
| <span class="sf-toolbar-status">{{ collector.resourceTemplates|length }}</span> | ||
| </div> | ||
| {% endset %} | ||
|
|
||
| {{ include('@WebProfiler/Profiler/toolbar_item.html.twig', { 'link': true }) }} | ||
| {% endif %} | ||
| {% endblock %} | ||
|
|
||
| {% block menu %} | ||
| <span class="label"> | ||
| <span class="icon">{{ include('@Mcp/icon.svg', { y: 16 }) }}</span> | ||
| <strong>MCP</strong> | ||
| <span class="count">{{ collector.totalCount }}</span> | ||
| </span> | ||
| {% endblock %} | ||
|
|
||
| {% block panel %} | ||
| <h2>MCP Capabilities</h2> | ||
| <section class="metrics"> | ||
| <div class="metric-group"> | ||
| <div class="metric"> | ||
| <span class="value">{{ collector.tools|length }}</span> | ||
| <span class="label">Tools</span> | ||
| </div> | ||
| <div class="metric"> | ||
| <span class="value">{{ collector.prompts|length }}</span> | ||
| <span class="label">Prompts</span> | ||
| </div> | ||
| </div> | ||
| <div class="metric-divider"></div> | ||
| <div class="metric-group"> | ||
| <div class="metric"> | ||
| <span class="value">{{ collector.resources|length }}</span> | ||
| <span class="label">Resources</span> | ||
| </div> | ||
| <div class="metric"> | ||
| <span class="value">{{ collector.resourceTemplates|length }}</span> | ||
| <span class="label">Resource Templates</span> | ||
| </div> | ||
| </div> | ||
| </section> | ||
|
|
||
| <div class="sf-tabs"> | ||
| <div class="tab {{ collector.tools is empty ? 'disabled' }}"> | ||
| <h3 class="tab-title">Tools <span class="badge">{{ collector.tools|length }}</span></h3> | ||
| <div class="tab-content"> | ||
| {{ include('@Mcp/tools.html.twig') }} | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="tab {{ collector.prompts is empty ? 'disabled' }}"> | ||
| <h3 class="tab-title">Prompts <span class="badge">{{ collector.prompts|length }}</span></h3> | ||
| <div class="tab-content"> | ||
| {{ include('@Mcp/prompts.html.twig') }} | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="tab {{ collector.resources is empty ? 'disabled' }}"> | ||
| <h3 class="tab-title">Resources <span class="badge">{{ collector.resources|length }}</span></h3> | ||
| <div class="tab-content"> | ||
| {{ include('@Mcp/resources.html.twig') }} | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="tab {{ collector.resourceTemplates is empty ? 'disabled' }}"> | ||
| <h3 class="tab-title">Resource Templates <span class="badge">{{ collector.resourceTemplates|length }}</span></h3> | ||
| <div class="tab-content"> | ||
| {{ include('@Mcp/resource_templates.html.twig') }} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| {% endblock %} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| {% if collector.prompts|length %} | ||
| <div class="sf-tabs"> | ||
| {% for prompt in collector.prompts %} | ||
| <div class="tab"> | ||
| <h3 class="tab-title">{{ prompt.name }}</h3> | ||
| <div class="tab-content"> | ||
| {% if prompt.description %} | ||
| <p><strong>Description:</strong> {{ prompt.description }}</p> | ||
| {% endif %} | ||
|
|
||
| {% if prompt.arguments|length %} | ||
| <h4>Arguments</h4> | ||
| <table> | ||
| <thead> | ||
| <tr> | ||
| <th>Name</th> | ||
| <th>Required</th> | ||
| <th>Description</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {% for arg in prompt.arguments %} | ||
| <tr> | ||
| <td><code>{{ arg.name }}</code></td> | ||
| <td> | ||
| {% if arg.required %} | ||
| <span class="label status-error">Yes</span> | ||
| {% else %} | ||
| <span class="label">No</span> | ||
| {% endif %} | ||
| </td> | ||
| <td>{{ arg.description ?? '-' }}</td> | ||
| </tr> | ||
| {% endfor %} | ||
| </tbody> | ||
| </table> | ||
| {% else %} | ||
| <div class="empty"> | ||
| <p>This prompt has no arguments.</p> | ||
| </div> | ||
| {% endif %} | ||
| </div> | ||
| </div> | ||
| {% endfor %} | ||
| </div> | ||
| {% else %} | ||
| <div class="empty"> | ||
| <p>No prompts were registered.</p> | ||
| </div> | ||
| {% endif %} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.