Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 1.74 KB

logging.md

File metadata and controls

43 lines (31 loc) · 1.74 KB

Logging

Deprecated since protocol revision 2026-07-28 (SEP-2577), earliest removal 2027-07-28. Logging keeps working until then; new integrations should log to stderr (stdio) or use OpenTelemetry instead.

The SDK provides support to send log messages to clients. All standard PSR-3 log levels are supported. Level warning is the default level, so anything below it is dropped until the client lowers the level with logging/setLevel.

!!! note On revision 2026-07-28 there is no logging/setLevel: the client names its level in each request's _meta["io.modelcontextprotocol/logLevel"], and a request naming none receives no log notifications at all.

!!! note A server without sessions doesn't offer logging to handshake-era clients and drops their log messages.

!!! note Only the message is forwarded to the client. A PSR-3 $context array is accepted for interface compatibility but is not sent — interpolate anything you need into the message itself.

Usage

The SDK automatically injects a RequestContext instance into handlers. This can be used to create a ClientLogger.

use Mcp\Server\Capability\Attribute\McpTool;
use Mcp\Server\RequestContext;

#[McpTool]
public function processData(string $input, RequestContext $context): array {
    $logger = $context->getClientLogger();

    $logger->info(\sprintf('Processing started for "%s"', $input));
    $logger->warning('Deprecated API used');
    
    // ... processing logic ...
    
    $logger->info('Processing completed');
    return ['result' => 'processed'];
}