Skip to content

Conversation

lorenzocesconetto
Copy link
Contributor

Currently if the progress notification callback throws an exception we get a misleading warning message.
This PR aims to fix it.

Motivation and Context

How Has This Been Tested?

Ran a few tests locally.

Breaking Changes

No breaking changes.

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

Copy link
Contributor

@ihrpr ihrpr 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 so much for working on this!

There are some suggestion would be good to address before merging:

  • please can you add tests
  • replace use of try-except-else to make it consistent in the project

@lorenzocesconetto
Copy link
Contributor Author

lorenzocesconetto commented May 23, 2025

Hi @ihrpr thank you for the review. I'll add the tests.

@lorenzocesconetto
Copy link
Contributor Author

Hi @ihrpr, ready for another pass!
I've added the unit test and removed the try-except-else as you've requested.

@Kludex
Copy link
Member

Kludex commented May 26, 2025

Why is it misleading? Do you have a MRE that I can check this locally?

Also, if this makes sense, we should except on ValidationError, not on Exception.

Copy link
Contributor

@ihrpr ihrpr 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 for adding tests! Few things to address - please see comments in PR

  1. As Kludex pointed out, the PR catches Exception which is too broad.
  2. The warning could include more context about which progress token/request triggered the exception.

@lorenzocesconetto
Copy link
Contributor Author

Thank you for your reviews and comments @Kludex and @ihrpr!
Totally agree with you guys and changed to ValidationError in the try-except.
I only kept the generic Exception around the callback execution since we don't know what kind of exception might be raised in there.

@Kludex the "misleading" part is that it prints Failed to validate notification... when the user's callback raises an exception. When I saw that for the first time I thought the server notification message was not following the protocol's standard (or the client validation was broken). That message is very misleading. The root cause was a bad implementation of the callback.

@lorenzocesconetto
Copy link
Contributor Author

@ihrpr can you take another look?

gspencergoog pushed a commit to gspencergoog/mcp-python-sdk that referenced this pull request Jul 29, 2025
…/basil/expand_meta_name_reservation

expand `_meta` name reservation
Copy link
Contributor

@felixweinberger felixweinberger left a comment

Choose a reason for hiding this comment

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

Hi @lorenzocesconetto - thank you for your contribution!

Apologies for the time it took to get back to this - would you be able to update the PR to ensure tests pass and merge conflicts are resolved?

Happy to get back to this quickly if you have the bandwidth to update this PR!

@felixweinberger felixweinberger added the needs sync Needs sync with latest main branch to ensure CI passes label Sep 5, 2025
@lorenzocesconetto
Copy link
Contributor Author

lorenzocesconetto commented Sep 7, 2025

Hi @felixweinberger, thanks for getting back to me, I'll update this PR.
I am actually interested in contributing more to this repo as long as core contributors are willing to provide quick feedback.
Lmk if there's any other issues across the repo that could use an extra pair of hands.

@felixweinberger
Copy link
Contributor

Hi @felixweinberger, thanks for getting back to me, I'll update this PR. I am actually interested in contributing more to this repo as long as core contributors are willing to provide quick feedback. Lmk if there's any other issues across the repo that could use an extra pair of hands.

Thank you for the feedback and yes it's something we're currently working on the team to improve coverage for (so we can get back to people more quickly). I'll be sure to get back to you quickly on this PR.

Thank you for the offer of making more contributions! I'm currently trying to get a handle on clusters of issues on the python SDK worth prioritizing, I'll let you know if I find something suitable that needs some help!

@lorenzocesconetto lorenzocesconetto requested a review from a team as a code owner September 9, 2025 00:19
@lorenzocesconetto
Copy link
Contributor Author

lorenzocesconetto commented Sep 9, 2025

@felixweinberger pulled the latest changes and resolved the conflicts.
But it seems that one of the tests is breaking for python 3.10 but runs successfully for other versions, interesting...

@felixweinberger
Copy link
Contributor

@felixweinberger pulled the latest changes and resolved the conflicts. But it seems that one of the tests is breaking for python 3.10 but runs successfully for other versions, interesting...

Thanks! There is occasional flakiness in the tests, I restarted it let's see if it was one of those.

Comment on lines +401 to +405
except Exception as e:
logging.error(
"Progress callback raised an exception: %s",
e,
)
Copy link
Member

Choose a reason for hiding this comment

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

There's an outer exception block 🤔

Copy link
Contributor

@felixweinberger felixweinberger Sep 16, 2025

Choose a reason for hiding this comment

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

Fair - how would you propose addressing the misleading part here instead? The callback could be anything, so it could throw any kind of exception.

We could potentially replace 410 to just be a generic logging.exception(e) without any additional decoration? In order to be more broad without adding misleading commentary?

@felixweinberger felixweinberger added needs more eyes Needs alignment among maintainers whether this is something we want to add and removed needs sync Needs sync with latest main branch to ensure CI passes labels Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more eyes Needs alignment among maintainers whether this is something we want to add
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants