Skip to content

Commit 71276c0

Browse files
committed
refactor(notifications): use proper Log facade imports
- Replace \Log:: with Log:: facade usage - Add use Illuminate\Support\Facades\Log; imports - Apply to all notification handlers and MCPProtocol - Update notification stub template with proper import
1 parent 5e305fb commit 71276c0

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

src/Protocol/MCPProtocol.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace OPGG\LaravelMcpServer\Protocol;
44

55
use Exception;
6+
use Illuminate\Support\Facades\Log;
67
use OPGG\LaravelMcpServer\Data\ProcessMessageData;
78
use OPGG\LaravelMcpServer\Data\Requests\NotificationData;
89
use OPGG\LaravelMcpServer\Data\Requests\RequestData;
@@ -215,7 +216,7 @@ private function processNotification(string $clientId, NotificationData $notific
215216
} catch (Exception $e) {
216217
// Log notification execution errors but don't send error response to client
217218
// per JSON-RPC specification for notifications
218-
\Log::error('MCP Notification Handler Error', [
219+
Log::error('MCP Notification Handler Error', [
219220
'method' => $method,
220221
'client_id' => $clientId,
221222
'params' => $notificationData->params,
@@ -231,7 +232,7 @@ private function processNotification(string $clientId, NotificationData $notific
231232
}
232233

233234
// Log unknown notification methods
234-
\Log::warning('MCP Unknown Notification Method', [
235+
Log::warning('MCP Unknown Notification Method', [
235236
'method' => $method,
236237
'client_id' => $clientId,
237238
'params' => $notificationData->params,

src/Server/Notification/CancelledHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace OPGG\LaravelMcpServer\Server\Notification;
44

5+
use Illuminate\Support\Facades\Log;
56
use OPGG\LaravelMcpServer\Enums\ProcessMessageType;
67
use OPGG\LaravelMcpServer\Protocol\Handlers\NotificationHandler;
78

@@ -20,7 +21,7 @@ public function execute(?array $params = null): void
2021
$reason = $params['reason'] ?? 'No reason provided';
2122

2223
if ($requestId) {
23-
\Log::info('MCP Request Cancelled', [
24+
Log::info('MCP Request Cancelled', [
2425
'request_id' => $requestId,
2526
'reason' => $reason,
2627
'timestamp' => now()->toISOString(),

src/Server/Notification/InitializedHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace OPGG\LaravelMcpServer\Server\Notification;
44

5+
use Illuminate\Support\Facades\Log;
56
use OPGG\LaravelMcpServer\Enums\ProcessMessageType;
67
use OPGG\LaravelMcpServer\Protocol\Handlers\NotificationHandler;
78

@@ -22,7 +23,7 @@ public function execute(?array $params = null): void
2223
// - Triggering initialization events
2324
// - Recording session start times
2425

25-
\Log::info('MCP Client Initialized', [
26+
Log::info('MCP Client Initialized', [
2627
'params' => $params,
2728
'initialized_at' => now()->toISOString(),
2829
]);

src/Server/Notification/MessageHandler.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace OPGG\LaravelMcpServer\Server\Notification;
44

5+
use Illuminate\Support\Facades\Log;
56
use OPGG\LaravelMcpServer\Enums\ProcessMessageType;
67
use OPGG\LaravelMcpServer\Protocol\Handlers\NotificationHandler;
78

@@ -22,10 +23,10 @@ public function execute(?array $params = null): void
2223

2324
// Log the message with appropriate level
2425
match ($level) {
25-
'error' => \Log::error("MCP Client Message [{$logger}]", $data),
26-
'warning' => \Log::warning("MCP Client Message [{$logger}]", $data),
27-
'debug' => \Log::debug("MCP Client Message [{$logger}]", $data),
28-
default => \Log::info("MCP Client Message [{$logger}]", $data),
26+
'error' => Log::error("MCP Client Message [{$logger}]", $data),
27+
'warning' => Log::warning("MCP Client Message [{$logger}]", $data),
28+
'debug' => Log::debug("MCP Client Message [{$logger}]", $data),
29+
default => Log::info("MCP Client Message [{$logger}]", $data),
2930
};
3031

3132
// You can implement custom logic here, such as:

src/Server/Notification/ProgressHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace OPGG\LaravelMcpServer\Server\Notification;
44

5+
use Illuminate\Support\Facades\Log;
56
use OPGG\LaravelMcpServer\Enums\ProcessMessageType;
67
use OPGG\LaravelMcpServer\Protocol\Handlers\NotificationHandler;
78

@@ -23,7 +24,7 @@ public function execute(?array $params = null): void
2324

2425
// Log progress update for debugging/monitoring
2526
if ($progressToken && $progress !== null) {
26-
\Log::info('MCP Progress Update', [
27+
Log::info('MCP Progress Update', [
2728
'token' => $progressToken,
2829
'progress' => $progress,
2930
'total' => $total,

src/stubs/notification.stub

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace {{ namespace }};
44

5+
use Illuminate\Support\Facades\Log;
56
use OPGG\LaravelMcpServer\Enums\ProcessMessageType;
67
use OPGG\LaravelMcpServer\Protocol\Handlers\NotificationHandler;
78
use stdClass;
@@ -73,7 +74,7 @@ class {{ class }} extends NotificationHandler
7374
// $data = $params['data'] ?? [];
7475

7576
// Example: Log the notification for debugging
76-
\Log::info('{{ class }} notification received', [
77+
Log::info('{{ class }} notification received', [
7778
'method' => '{{ method }}',
7879
'params' => $params,
7980
'timestamp' => now()->toISOString(),

0 commit comments

Comments
 (0)