Skip to content

[Server] Compatibility of Capabilities with Symfony's Container #67

Description

@chr-hertel

Passing container and using ->get() won't work with Symfony by default since services are private.

The \"App\\Tools\\PythonTool\" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.

only way to make it work is to set service public.

Activity

  1. added
    ServerIssues & PRs related to the Server component
    on Sep 14, 2025
  2. ineersa commented on Sep 14, 2025

    @ineersa
    Contributor

    It's slightly different from what was in PHP-MCP package (for some reason I was using it before swapping to this one), but it still persists.

     "exception": {
            "class": "ArgumentCountError",
            "message": "Too few arguments to function App\\Tools\\SearchTool::__construct(), 0 passed in /home/ineersa/mcp-servers/browser-mcp/vendor/mcp/sdk/src/Capability/Registry/ReferenceHandler.php on line 75 and exactly 1 expected",
            "code": 0,
            "file": "/home/ineersa/mcp-servers/browser-mcp/src/Tools/SearchTool.php:17",
            "trace": [
                "/home/ineersa/mcp-servers/browser-mcp/vendor/mcp/sdk/src/Capability/Registry/ReferenceHandler.php:75",
                "/home/ineersa/mcp-servers/browser-mcp/vendor/mcp/sdk/src/Capability/Registry/ReferenceHandler.php:36",
                "/home/ineersa/mcp-servers/browser-mcp/vendor/mcp/sdk/src/Capability/Registry.php:232",
                "/home/ineersa/mcp-servers/browser-mcp/vendor/mcp/sdk/src/Server/RequestHandler/CallToolHandler.php:47",
                "/home/ineersa/mcp-servers/browser-mcp/vendor/mcp/sdk/src/JsonRpc/Handler.php:160",
                "/home/ineersa/mcp-servers/browser-mcp/vendor/mcp/sdk/src/JsonRpc/Handler.php:106",
                "/home/ineersa/mcp-servers/browser-mcp/vendor/mcp/sdk/src/Server.php:50",
                "/home/ineersa/mcp-servers/browser-mcp/src/Command/BrowserMcpCommand.php:91",
                "/home/ineersa/mcp-servers/browser-mcp/vendor/symfony/console/Command/Command.php:318",
                "/home/ineersa/mcp-servers/browser-mcp/vendor/symfony/console/Application.php:1110",
                "/home/ineersa/mcp-servers/browser-mcp/vendor/symfony/framework-bundle/Console/Application.php:123",
                "/home/ineersa/mcp-servers/browser-mcp/vendor/symfony/console/Application.php:359",
                "/home/ineersa/mcp-servers/browser-mcp/vendor/symfony/framework-bundle/Console/Application.php:77",
                "/home/ineersa/mcp-servers/browser-mcp/vendor/symfony/console/Application.php:194",
                "/home/ineersa/mcp-servers/browser-mcp/vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:49",
                "/home/ineersa/mcp-servers/browser-mcp/vendor/autoload_runtime.php:29",
                "/home/ineersa/mcp-servers/browser-mcp/bin/browser-mcp:15"
            ]
        }

    When we try to resolve how to get tool handler we will call ->container->has(CLASSNAME)

    private function getClassInstance(string $className): object
    {
        if (null !== $this->container && $this->container->has($className)) {
            return $this->container->get($className);
        }
    
        return new $className();
    }

    While this will work with containers like PHP-DI for example, it won't work with Symfony.
    All services inside Symfony container are private, so ->container->has(CLASSNAME) will return false unless it explicitly set as public.

    I don't really see how to fix it, since it's not a bug.
    Maybe there should be Symfony specific documentation which will explicitly say that Tools/Resources/Prompts must be public if they have any dependencies:

    For example this in services.yaml will fix those issues

    services:
        ...
        # Make ALL services in App\Tools\ public
        App\Tools\:
            resource: '../src/Tools'
            public: true
  3. chr-hertel commented on Sep 14, 2025

    @chr-hertel
    MemberAuthor

    That's alright, we can use a locator build with the services that have the attributes on them - that'll work :)
    I'll take care while patching up the mcp-bundle

  4. self-assigned this
    on Sep 14, 2025
  5. chr-hertel commented on Nov 11, 2025

    @chr-hertel
    MemberAuthor

    This should be solved with the bundle - fair to close @ineersa?

  6. ineersa commented on Nov 12, 2025

    @ineersa
    Contributor

    This should be solved with the bundle - fair to close @ineersa?

    Sure! I need to try bundle =)

  7. chr-hertel commented on Nov 14, 2025

    @chr-hertel
    MemberAuthor

    Closing for now - feel free to re-open if there are issues with the bundle.

  8. axi commented on Nov 18, 2025

    @axi

    Hi,
    I'm facing the same error, for others reading this, I think the discussion mentions the "bundle".

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

Metadata

Metadata

Assignees

Labels

ServerIssues & PRs related to the Server component

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions