Code Improvements and allow managers without ´args´ - #3
Merged
Conversation
Baraujo25
reviewed
Nov 7, 2025
Comment on lines
-80
to
+84
| args: Dict[str, Any] = Field(description="Dictionary with parameters"), | ||
| args: Dict[str, Any] = Field(description="Dictionary with parameters", default=None), | ||
| ctx: Context = Field(description="Context object providing access to MCP capabilities") | ||
| ) -> BaseResult: | ||
|
|
||
| if args is None: | ||
| args = {} |
Collaborator
There was a problem hiding this comment.
What about
args: Dict[str, Any] = Field(description="Dictionary with parameters", default={}), does it work? It could avoid us setting None, conditional (if args is None) and then setting {}
Collaborator
There was a problem hiding this comment.
If it does work, maybe we could impact the change in all tools, what do you think?
Collaborator
Author
There was a problem hiding this comment.
I mentioned this when I share the PR link.
"There's an issue there which is the comparison of whether arg is None and is initialized as dict; the default of pydantic has other mechanisms but they are convoluted, this method at least is visually clear."
There are some problems in pydantic to be able to do it as you mention, there are also other ways to do it in pydantic but it requires unnecessary over-engineering.
Baraujo25
approved these changes
Nov 7, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In models with non-reasoning capabilities or that don't adhere to pydantic's specification rules, allowing the
argsparameter to be null and initializing it is a better option for managers that don't have arguments.This improves the potential for retries in pydantic due to errors that occur when the tool is incorrectly called by the AI because it follows the text specification but not the formal schema specification.
This would be a good idea to replicate as a pattern for other or future MCPs.
I proceeded to create utility files for each type of manager that needed them. This way, managers retain only the minimum logic, and the rest is delegated to their specific utility files.
This allows for smaller managers and avoids having a single utility file for all managers when specific logic is required.