Skip to content

Conversation

@chr-hertel
Copy link
Member

Not exactly ideal and doesn't solve the trouble i have with that service slicing at this point, but would enable the concerns of #74, doesn't it? @camilleislasse

cc @soyuka

@chr-hertel chr-hertel added the Server Issues & PRs related to the Server component label Nov 11, 2025
@camilleislasse
Copy link

camilleislasse commented Nov 12, 2025

Hi @chr-hertel

I've been working on the Symfony profiler integration (the use case from #74), and I found a solution using the loader pattern that @soyuka suggested in PR #75.

My approach:

I created a ProfilingLoader that implements LoaderInterface to capture the Registry reference:

  final class ProfilingLoader implements LoaderInterface
  {
      private ?ReferenceRegistryInterface $registry = null;

      public function load(ReferenceRegistryInterface $registry): void
      {
          // Capture the registry reference for profiling
          $this->registry = $registry;
      }

      public function getRegistry(): ?ReferenceRegistryInterface
      {
          return $this->registry;
      }
  }

Then register it in the Symfony container and add it to the ServerBuilder:

  ->set('ai.mcp.profiling_loader', ProfilingLoader::class)

  ->set('mcp.server.builder', ServerBuilder::class)
      ->factory([Server::class, 'builder'])
      // ... 
      ->call('addLoaders', [service('ai.mcp.profiling_loader')])

The Symfony DataCollector then reads from this ProfilingLoader in lateCollect():

  public function lateCollect(): void
  {
      $registry = $this->profilingLoader->getRegistry();

      if (null === $registry) {
          // Handle case where Registry wasn't built yet
          return;
      }

      // Collect tools, prompts, resources, templates
      foreach ($registry->getTools()->references as $tool) {
          // ...
      }
  }

This approach solves my use case. If you think your PR #146 is "not exactly ideal" and this loader approach (following the pattern from #111) suits you, maybe this PR becomes less necessary? I'll let you and @soyuka decide what's best 🙂

@chr-hertel
Copy link
Member Author

yea, i can see that working, you really dug for a solution & found one👍

i think this PR would enable us to manage the Registry service via dependency injection container and have a traceable decorator for the profiler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Server Issues & PRs related to the Server component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants