I've refactored the Tool class for improved ergonomics and consistency. #38
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.
This commit introduces several improvements to the
Toolclass:Flexible Return Types for
doExecute(): TheTool::doExecute()method can now return either a singleContentItemInterfaceobject or an array ofContentItemInterfaceobjects. If a single item is returned, theTool::execute()method automatically wraps it in an array. This simplifies tool implementation when only one content item needs to be returned, e.g.,return $this->text("response");. The final JSON output still adheres to the Model Context Protocol, with thecontentfield always being an array.Shorter Helper Method Names: The content creation helper methods within the
Toolclass have been renamed for brevity and consistency with similar methods in theResourceclass:createTextContent()is nowtext()createImageContent()is nowimage()createAudioContent()is nowaudio()createEmbeddedResource()is nowembeddedResource()Codebase Updates: All existing tool implementations and tests throughout the codebase have been updated to use the new helper method names.
Enhanced Testing:
ToolTest.phphas been significantly updated with new test cases to cover:doExecute().PHPStan and PHPUnit Fixes: Addressed various PHPStan typing errors by adding appropriate
usestatements and refining PHPDoc annotations. Corrected PHPUnit test logic, including data passed to media helper methods and expected exception types.I ran the
jules_setup.shscript to ensure a consistent development environment, and therun_tests.shscript confirms that all tests and linters pass.