Commit 5b86a53
committed
bug #757 [MCP Bundle] Fix dependency injection and method-based / invokable support (camilleislasse)
This PR was squashed before being merged into the main branch.
Discussion
----------
[MCP Bundle] Fix dependency injection and method-based / invokable support
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| Docs? | yes
| Issues | symfony/ai#755
| License | MIT
** [MCP Bundle] Fix dependency injection and method-based / invokable support**
This commit fixes critical issues preventing MCP tools with constructor
dependencies from working and enables method-based attributes support.
Changes:
- Fix McpPass to use Reference objects for ServiceLocator registration
Previously passed tag arrays directly, causing crashes when tools had
constructor dependencies
- Fix McpBundle::registerMcpAttributes() closure signature
Added missing object $attribute and \Reflector $reflector parameters.
Without these parameters, Symfony's AttributeAutoconfigurationPass only
scans class-level attributes and skips method-level ones entirely
- Add LoggerInterface to CurrentTimeTool to demonstrate DI works
- Update documentation to reflect both patterns are supported
Added examples showing invokable and method-based patterns both work
with full DI support
- Improve McpPassTest to verify ServiceLocator uses References
Previous tests only checked presence, not type of values
Commits
-------
bdd050c6 [MCP Bundle] Fix dependency injection and method-based / invokable supportFile tree
3 files changed
+30
-2
lines changed- src
- DependencyInjection
- tests/DependencyInjection
3 files changed
+30
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
38 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
39 | 45 | | |
40 | 46 | | |
41 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
| 78 | + | |
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
56 | 70 | | |
57 | 71 | | |
58 | 72 | | |
| |||
115 | 129 | | |
116 | 130 | | |
117 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
118 | 140 | | |
119 | 141 | | |
0 commit comments