-
Notifications
You must be signed in to change notification settings - Fork 75
[Server] Implemented MCP logging specification with auto-injection #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[Server] Implemented MCP logging specification with auto-injection #104
Conversation
34ae3c3 to
035b75e
Compare
|
Why you use Yoda style? Is it necessary? |
|
I was only trying to follow the project convention and ensure the PR focuses on the feature, rather than refactoring. The Yoda style is not necessary, but that's what the project mostly uses at the moment. I believe refactoring is an implementation that is worthy of its own PR |
953aca7 to
30f8f42
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Adebayo120 - thanks a lot for giving this a try!
I did a first round of review, and didn't tackle all yet - since this is a larger feature, i guess we will need a couple of rounds and discussions - also with @CodeWithKyrian.
Just want to be transparent about that from the start, but we'll guide you through it, if you're up for that.
Please have a look at my comments, and also have a look at the examples here with Inspector:

at first glance i found two issues here:
- the logger appears as tool argument in the schema
- setting a higher log level raises errors
let me know if you have some questions!
|
Going through comments and updating, thank you so much @chr-hertel |
|
e6e49b3 to
0eecd64
Compare
|
@chr-hertel, I have updated the PR as suggested and tested as shown in the attached screenshot. It works great for me
|
|
@Adebayo120 thanks for following up - can you extend one of the HTTP examples to include client logging as well? |
| return 'Mcp\\Capability\\Logger\\ClientLogger' === $typeName | ||
| || 'Psr\\Log\\LoggerInterface' === $typeName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use ::class instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually you could simplify this to sth like
| return 'Mcp\\Capability\\Logger\\ClientLogger' === $typeName | |
| || 'Psr\\Log\\LoggerInterface' === $typeName; | |
| return in_array($type->getName(), [ClientLogger::class, LoggerInterface::class], true); |
| * @param string $message The message to process | ||
| * @param \Mcp\Capability\Logger\ClientLogger $logger Auto-injected logger | ||
| */ | ||
| public function withClientLogger(string $message, \Mcp\Capability\Logger\ClientLogger $logger): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use an import instead of FQCN inline
| // Should include the message parameter | ||
| $this->assertArrayHasKey('message', $schema['properties']); | ||
| $this->assertEquals(['type' => 'string', 'description' => 'The message to process'], $schema['properties']['message']); | ||
|
|
||
| // Should NOT include the logger parameter | ||
| $this->assertArrayNotHasKey('logger', $schema['properties']); | ||
|
|
||
| // Required array should only contain client parameters | ||
| $this->assertEquals(['message'], $schema['required']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
those comments are not needed - just make it look like vibe coded
|
@Adebayo120 please wait before continuing here - with #109 there is a competing solution that also covers other client-facing features - doesn't really make sense to work on the same thing. Or do I miss something @CodeWithKyrian that your PR wouldn't cover? also addresses the STDIO vs HTTP question that is rather unsolved here, right? |
|
@CodeWithKyrian could you please help here |
|
There is still something in the PR we could need - mostly the @Adebayo120 are you still up for that? |


This PR implements the Model Context Protocol (MCP) logging specification, providing centralized logging capabilities with auto-injection support for capability handlers. This enables developers to debug across multiple MCP servers from a single client interface, addressing the challenge of distributed logging in MCP ecosystems.
Motivation and Context
Fixes #70
This implementation addresses the missing logging functionality as outlined in the MCP logging specification.
Problem solved:
Key benefits:
How Has This Been Tested?
Comprehensive test coverage:
Test scenarios:
McpLoggerinto tools, resources, and promptsWorking examples:
examples/stdio-logging-showcase/- Complete demonstration of auto-injectionBreaking Changes
None. This implementation maintains full backward compatibility:
->enableMcpLogging()McpLoggerorLoggerInterfaceparameters are declaredTypes of changes
Checklist
Additional context
Implementation highlights:
Core Components:
McpLogger: PSR-3 compliant logger with MCP notification transportNotificationSender: Handles delivery of log messages to clientsSetLogLevelHandler: Processes client log level configuration requestsLoggingLevelenum: RFC-5424 compliant severity levels with indexingAuto-injection mechanism: