Skip to content

Commit 80da7cb

Browse files
Add doc explaination
1 parent e5824b5 commit 80da7cb

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

docs/bundles/mcp-bundle.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,44 @@ Creating MCP Capabilities
2929

3030
MCP capabilities are automatically discovered using PHP attributes.
3131

32+
.. warning::
33+
34+
The MCP Bundle currently **only supports the invokable pattern** where attributes are placed on classes
35+
with an ``__invoke()`` method. The method pattern (attributes on individual methods) is **not supported**.
36+
37+
This is because Symfony's ``registerAttributeForAutoconfiguration()`` only detects class-level attributes,
38+
not method-level attributes. While the underlying MCP SDK supports both patterns, the Bundle's
39+
autoconfiguration mechanism requires the invokable pattern.
40+
41+
**Supported pattern** (invokable)::
42+
43+
#[McpTool(name: 'my-tool')]
44+
class MyTool
45+
{
46+
public function __invoke(string $param): string
47+
{
48+
// Implementation
49+
}
50+
}
51+
52+
**Not supported pattern** (method-based)::
53+
54+
class MyTools
55+
{
56+
#[McpTool(name: 'tool-one')] // Discovered but no DI support
57+
public function toolOne(): string { }
58+
59+
#[McpTool(name: 'tool-two')] // Discovered but no DI support
60+
public function toolTwo(): string { }
61+
}
62+
63+
Method-based attributes are discovered by the MCP SDK, but the class is not registered as a
64+
Symfony service. This means **constructor dependencies will not be injected** and the tool will
65+
fail if it requires any services.
66+
67+
This limitation applies to all MCP capability attributes: ``#[McpTool]``, ``#[McpPrompt]``,
68+
``#[McpResource]``, and ``#[McpResourceTemplate]``.
69+
3270
Tools
3371
^^^^^
3472

0 commit comments

Comments
 (0)