1313
1414use Mcp \Capability \Attribute \McpResource ;
1515use Mcp \Capability \Attribute \McpTool ;
16- use Mcp \Capability \Logger \McpLogger ;
16+ use Mcp \Capability \Logger \ClientLogger ;
17+ use Psr \Log \LoggerInterface ;
18+ use Psr \Log \NullLogger ;
1719
1820/**
1921 * @phpstan-type Config array{precision: int, allow_negative: bool}
@@ -28,6 +30,11 @@ final class McpElements
2830 'allow_negative ' => true ,
2931 ];
3032
33+ public function __construct (
34+ private readonly LoggerInterface $ logger = new NullLogger (),
35+ ) {
36+ }
37+
3138 /**
3239 * Performs a calculation based on the operation.
3340 *
@@ -37,19 +44,14 @@ final class McpElements
3744 * @param float $a the first operand
3845 * @param float $b the second operand
3946 * @param string $operation the operation ('add', 'subtract', 'multiply', 'divide')
40- * @param McpLogger $logger Auto-injected MCP logger
47+ * @param ClientLogger $logger Auto-injected MCP logger
4148 *
4249 * @return float|string the result of the calculation, or an error message string
4350 */
4451 #[McpTool(name: 'calculate ' )]
45- public function calculate (float $ a , float $ b , string $ operation , McpLogger $ logger ): float |string
52+ public function calculate (float $ a , float $ b , string $ operation , ClientLogger $ logger ): float |string
4653 {
47- $ logger ->info ('🧮 Calculate tool called ' , [
48- 'operand_a ' => $ a ,
49- 'operand_b ' => $ b ,
50- 'operation ' => $ operation ,
51- 'auto_injection ' => 'McpLogger auto-injected successfully ' ,
52- ]);
54+ $ this ->logger ->info (\sprintf ('Calculating: %f %s %f ' , $ a , $ operation , $ b ));
5355
5456 $ op = strtolower ($ operation );
5557
@@ -105,7 +107,7 @@ public function calculate(float $a, float $b, string $operation, McpLogger $logg
105107 * Provides the current calculator configuration.
106108 * Can be read by clients to understand precision etc.
107109 *
108- * @param McpLogger $logger Auto-injected MCP logger for demonstration
110+ * @param ClientLogger $logger Auto-injected MCP logger for demonstration
109111 *
110112 * @return Config the configuration array
111113 */
@@ -115,11 +117,11 @@ public function calculate(float $a, float $b, string $operation, McpLogger $logg
115117 description: 'Current settings for the calculator tool (precision, allow_negative). ' ,
116118 mimeType: 'application/json ' ,
117119 )]
118- public function getConfiguration (McpLogger $ logger ): array
120+ public function getConfiguration (ClientLogger $ logger ): array
119121 {
120122 $ logger ->info ('📊 Resource config://calculator/settings accessed via auto-injection! ' , [
121123 'current_config ' => $ this ->config ,
122- 'auto_injection_demo ' => 'McpLogger was automatically injected into this resource handler ' ,
124+ 'auto_injection_demo ' => 'ClientLogger was automatically injected into this resource handler ' ,
123125 ]);
124126
125127 return $ this ->config ;
@@ -131,7 +133,7 @@ public function getConfiguration(McpLogger $logger): array
131133 *
132134 * @param string $setting the setting key ('precision' or 'allow_negative')
133135 * @param mixed $value the new value (int for precision, bool for allow_negative)
134- * @param McpLogger $logger Auto-injected MCP logger
136+ * @param ClientLogger $logger Auto-injected MCP logger
135137 *
136138 * @return array{
137139 * success: bool,
@@ -140,14 +142,9 @@ public function getConfiguration(McpLogger $logger): array
140142 * } success message or error
141143 */
142144 #[McpTool(name: 'update_setting ' )]
143- public function updateSetting (string $ setting , mixed $ value , McpLogger $ logger ): array
145+ public function updateSetting (string $ setting , mixed $ value , ClientLogger $ logger ): array
144146 {
145- $ logger ->info ('🔧 Update setting tool called ' , [
146- 'setting ' => $ setting ,
147- 'value ' => $ value ,
148- 'current_config ' => $ this ->config ,
149- 'auto_injection ' => 'McpLogger auto-injected successfully ' ,
150- ]);
147+ $ this ->logger ->info (\sprintf ('Setting tool called: setting=%s, value=%s ' , $ setting , var_export ($ value , true )));
151148 if (!\array_key_exists ($ setting , $ this ->config )) {
152149 $ logger ->error ('Unknown setting requested ' , [
153150 'setting ' => $ setting ,
0 commit comments