Skip to content

Commit 4614dc5

Browse files
committed
Renamed McpLogger to ClientLogger
1 parent 11cfb16 commit 4614dc5

File tree

13 files changed

+74
-76
lines changed

13 files changed

+74
-76
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,12 @@ Automatically inject PSR-3 compatible logger into your registered handlers:
236236
```php
237237
// Enable logging in server
238238
$server = Server::builder()
239-
->enableMcpLogging()
239+
->enableClientLogging()
240240
->build();
241241

242242
// Use in any handler - logger is auto-injected
243243
#[McpTool]
244-
public function processData(string $input, McpLogger $logger): array {
244+
public function processData(string $input, ClientLogger $logger): array {
245245
$logger->info('Processing data', ['input' => $input]);
246246
return ['result' => 'processed'];
247247
}

examples/stdio-discovery-calculator/McpElements.php

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
use Mcp\Capability\Attribute\McpResource;
1515
use 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,

examples/stdio-discovery-calculator/server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
->setInstructions('This server supports basic arithmetic operations: add, subtract, multiply, and divide. Send JSON-RPC requests to perform calculations.')
2424
->setContainer(container())
2525
->setLogger(logger())
26-
->enableMcpLogging() // Enable MCP logging capability and auto-injection!
26+
->enableClientLogging() // Enable Client logging capability and auto-injection!
2727
->setDiscovery(__DIR__, ['.'])
2828
->build();
2929

examples/stdio-logging-showcase/LoggingShowcaseHandlers.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@
1212
namespace Mcp\Example\StdioLoggingShowcase;
1313

1414
use Mcp\Capability\Attribute\McpTool;
15-
use Mcp\Capability\Logger\McpLogger;
15+
use Mcp\Capability\Logger\ClientLogger;
1616

1717
/**
1818
* Example handlers showcasing auto-injected MCP logging capabilities.
1919
*
20-
* This demonstrates how handlers can receive McpLogger automatically
20+
* This demonstrates how handlers can receive ClientLogger automatically
2121
* without any manual configuration - just declare it as a parameter!
2222
*/
2323
final class LoggingShowcaseHandlers
2424
{
2525
/**
26-
* Tool that demonstrates different logging levels with auto-injected McpLogger.
26+
* Tool that demonstrates different logging levels with auto-injected ClientLogger.
2727
*
2828
* @param string $message The message to log
2929
* @param string $level The logging level (debug, info, warning, error)
30-
* @param McpLogger $logger Auto-injected MCP logger
30+
* @param ClientLogger $logger Auto-injected MCP logger
3131
*
3232
* @return array<string, mixed>
3333
*/
3434
#[McpTool(name: 'log_message', description: 'Demonstrates MCP logging with different levels')]
35-
public function logMessage(string $message, string $level, McpLogger $logger): array
35+
public function logMessage(string $message, string $level, ClientLogger $logger): array
3636
{
3737
$logger->info('🚀 Starting log_message tool', [
3838
'requested_level' => $level,

examples/stdio-logging-showcase/server.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
->setServerInfo('Stdio Logging Showcase', '1.0.0', 'Demonstration of auto-injected MCP logging in capability handlers.')
2424
->setContainer(container())
2525
->setLogger(logger())
26-
->enableMcpLogging() // Enable MCP logging capability and auto-injection!
26+
->enableClientLogging() // Enable MCP logging capability and auto-injection!
2727
->setDiscovery(__DIR__, ['.'])
2828
->build();
2929

@@ -32,4 +32,4 @@
3232
$server->run($transport);
3333

3434
logger()->info('Logging Showcase Server is ready!');
35-
logger()->info('This example demonstrates auto-injection of McpLogger into capability handlers.');
35+
logger()->info('This example demonstrates auto-injection of ClientLogger into capability handlers.');

src/Capability/Discovery/SchemaGenerator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ private function mapSimpleTypeToJsonSchema(string $type): string
792792
/**
793793
* Determines if a parameter was auto-injected and should be excluded from schema generation.
794794
*
795-
* Parameters that are auto-injected by the framework (like McpLogger) should not appear
795+
* Parameters that are auto-injected by the framework (like ClientLogger) should not appear
796796
* in the tool schema since they're not provided by the client.
797797
*/
798798
private function isAutoInjectedParameter(\ReflectionParameter $parameter): bool
@@ -805,8 +805,8 @@ private function isAutoInjectedParameter(\ReflectionParameter $parameter): bool
805805

806806
$typeName = $type->getName();
807807

808-
// Auto-inject for McpLogger or LoggerInterface types
809-
return 'Mcp\\Capability\\Logger\\McpLogger' === $typeName
808+
// Auto-inject for ClientLogger or LoggerInterface types
809+
return 'Mcp\\Capability\\Logger\\ClientLogger' === $typeName
810810
|| 'Psr\\Log\\LoggerInterface' === $typeName;
811811
}
812812
}

src/Capability/Logger/McpLogger.php renamed to src/Capability/Logger/ClientLogger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
* @author Adam Jamiu <[email protected]>
2727
*/
28-
final class McpLogger extends AbstractLogger
28+
final class ClientLogger extends AbstractLogger
2929
{
3030
public function __construct(
3131
private readonly NotificationSender $notificationSender,

src/Capability/Registry/ReferenceHandler.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Mcp\Capability\Registry;
1313

14-
use Mcp\Capability\Logger\McpLogger;
14+
use Mcp\Capability\Logger\ClientLogger;
1515
use Mcp\Exception\InvalidArgumentException;
1616
use Mcp\Exception\RegistryException;
1717
use Psr\Container\ContainerInterface;
@@ -23,7 +23,7 @@ final class ReferenceHandler implements ReferenceHandlerInterface
2323
{
2424
public function __construct(
2525
private readonly ?ContainerInterface $container = null,
26-
private readonly ?McpLogger $mcpLogger = null,
26+
private readonly ?ClientLogger $clientLogger = null,
2727
) {
2828
}
2929

@@ -91,16 +91,16 @@ private function prepareArguments(\ReflectionFunctionAbstract $reflection, array
9191
$paramName = $parameter->getName();
9292
$paramPosition = $parameter->getPosition();
9393

94-
// Auto-inject McpLogger if parameter expects it
95-
if ($this->shouldInjectMcpLogger($parameter)) {
96-
if (null !== $this->mcpLogger) {
97-
$finalArgs[$paramPosition] = $this->mcpLogger;
94+
// Auto-inject ClientLogger if parameter expects it
95+
if ($this->shouldInjectClientLogger($parameter)) {
96+
if (null !== $this->clientLogger) {
97+
$finalArgs[$paramPosition] = $this->clientLogger;
9898
continue;
9999
} elseif ($parameter->allowsNull() || $parameter->isOptional()) {
100100
$finalArgs[$paramPosition] = null;
101101
continue;
102102
}
103-
// If McpLogger is required but not available, fall through to normal handling
103+
// If ClientLogger is required but not available, fall through to normal handling
104104
}
105105

106106
if (isset($arguments[$paramName])) {
@@ -130,9 +130,9 @@ private function prepareArguments(\ReflectionFunctionAbstract $reflection, array
130130
}
131131

132132
/**
133-
* Determines if the parameter should receive auto-injected McpLogger.
133+
* Determines if the parameter should receive auto-injected ClientLogger.
134134
*/
135-
private function shouldInjectMcpLogger(\ReflectionParameter $parameter): bool
135+
private function shouldInjectClientLogger(\ReflectionParameter $parameter): bool
136136
{
137137
$type = $parameter->getType();
138138

@@ -142,8 +142,8 @@ private function shouldInjectMcpLogger(\ReflectionParameter $parameter): bool
142142

143143
$typeName = $type->getName();
144144

145-
// Auto-inject for McpLogger or LoggerInterface types
146-
return McpLogger::class === $typeName || \Psr\Log\LoggerInterface::class === $typeName;
145+
// Auto-inject for ClientLogger or LoggerInterface types
146+
return ClientLogger::class === $typeName || \Psr\Log\LoggerInterface::class === $typeName;
147147
}
148148

149149
/**

src/Server/Builder.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use Mcp\Capability\Discovery\DocBlockParser;
2121
use Mcp\Capability\Discovery\HandlerResolver;
2222
use Mcp\Capability\Discovery\SchemaGenerator;
23-
use Mcp\Capability\Logger\McpLogger;
23+
use Mcp\Capability\Logger\ClientLogger;
2424
use Mcp\Capability\Registry;
2525
use Mcp\Capability\Registry\Container;
2626
use Mcp\Capability\Registry\ElementReference;
@@ -241,13 +241,13 @@ public function addNotificationHandlers(iterable $handlers): self
241241
}
242242

243243
/**
244-
* Enables MCP logging capability for the server.
244+
* Enables Client logging capability for the server.
245245
*
246246
* When enabled, the server will advertise logging capability to clients,
247247
* indicating that it can emit structured log messages according to the MCP specification.
248-
* This enables auto-injection of McpLogger into capability handlers.
248+
* This enables auto-injection of ClientLogger into capability handlers.
249249
*/
250-
public function enableMcpLogging(): self
250+
public function enableClientLogging(): self
251251
{
252252
$this->loggingMessageNotificationEnabled = true;
253253

@@ -421,9 +421,9 @@ public function build(): Server
421421
$notificationHandler = NotificationHandler::make($registry, $logger);
422422
$notificationSender = new NotificationSender($notificationHandler, null, $logger);
423423

424-
// Create McpLogger for components that should send logs via MCP
425-
$mcpLogger = new McpLogger($notificationSender, $logger);
426-
$referenceHandler = new ReferenceHandler($container, $mcpLogger);
424+
// Create ClientLogger for components that should send logs via MCP
425+
$clientLogger = new ClientLogger($notificationSender, $logger);
426+
$referenceHandler = new ReferenceHandler($container, $clientLogger);
427427

428428
$requestHandlers = array_merge($this->requestHandlers, [
429429
new Handler\Request\PingHandler(),
@@ -448,6 +448,7 @@ public function build(): Server
448448
messageFactory: $messageFactory,
449449
sessionFactory: $sessionFactory,
450450
sessionStore: $sessionStore,
451+
logger: $logger,
451452
);
452453

453454
return new Server($protocol, $notificationSender, $logger);

tests/Unit/Capability/Discovery/SchemaGeneratorFixture.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,12 @@ public function parameterSchemaInferredType(
414414
}
415415

416416
/**
417-
* Method with McpLogger that should be excluded from schema.
417+
* Method with ClientLogger that should be excluded from schema.
418418
*
419419
* @param string $message The message to process
420-
* @param \Mcp\Capability\Logger\McpLogger $logger Auto-injected logger
420+
* @param \Mcp\Capability\Logger\ClientLogger $logger Auto-injected logger
421421
*/
422-
public function withMcpLogger(string $message, \Mcp\Capability\Logger\McpLogger $logger): string
422+
public function withClientLogger(string $message, \Mcp\Capability\Logger\ClientLogger $logger): string
423423
{
424424
return $message;
425425
}

0 commit comments

Comments
 (0)