Skip to content

Add PSR-3 compliant exception context when logging exceptions#300

Open
svenmuennich wants to merge 2 commits into
modelcontextprotocol:mainfrom
pickware:fix/psr3-exception-logging
Open

Add PSR-3 compliant exception context when logging exceptions#300
svenmuennich wants to merge 2 commits into
modelcontextprotocol:mainfrom
pickware:fix/psr3-exception-logging

Conversation

@svenmuennich
Copy link
Copy Markdown

This PR consistently adds caught exceptions to the logging context as exception, following the standard defined by PSR-3.

Motivation and Context

Previously almost no caught exceptions where included in the context passed to respective PSR logging calls, making it very hard for downstream tooling to e.g. filter certain errors from reporting.

How Has This Been Tested?

Added unit test coverage for inclusion of exceptions in logging.

Breaking Changes

n/a

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

I decided to include objects of type Throwable in the logging, even though PSR-3 only covers objects of types Exception. My reasoning was based on the following statement in the spec:

Implementors MUST still verify that the 'exception' key is actually an Exception before using it as such, as it MAY contain anything.

@chr-hertel chr-hertel added enhancement Request for a new feature that's not currently supported labels May 8, 2026
Copy link
Copy Markdown
Member

@chr-hertel chr-hertel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that impulse @svenmuennich - nice house-keeping. I'd say we could go one step further, WDYT?

Comment thread src/Capability/Discovery/DocBlockParser.php Outdated
Comment thread src/Capability/Discovery/SchemaValidator.php Outdated
Comment thread src/Client/Transport/HttpTransport.php Outdated
@chr-hertel chr-hertel added this to the 0.6.0 milestone May 8, 2026
@chr-hertel chr-hertel added needs more work Not ready to be merged yet, needs additional follow-up from the author(s). labels May 8, 2026
@svenmuennich
Copy link
Copy Markdown
Author

I'd say we could go one step further, WDYT?

Sure! I just did another sweep and made sure that only complete exceptions are logged 👍

@svenmuennich svenmuennich requested a review from chr-hertel May 11, 2026 10:40
Copy link
Copy Markdown
Member

@chr-hertel chr-hertel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @svenmuennich!

@chr-hertel chr-hertel removed the needs more work Not ready to be merged yet, needs additional follow-up from the author(s). label May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Request for a new feature that's not currently supported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants