Extend modules instead of inheriting classes#48
Extend modules instead of inheriting classes#48sambostock wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
Classes are meant to be instantiated, but we expect consumers to use "macros" and define a singleton `call` method, so we should have them `extend` a `Module` instead.
|
I'm also not happy with the current design, but I'm unsure if this change is the best way forward. I think one good way to design libraries/code is to not surprise/confuse the user... and from my point of view the main surprise of the current design has not been resolved: When I see a class defined, I expect to create instances and use them somehow. But that's not how Tool/Prompt definition works right now. The class objects are singletons that contain tool definition information and handle the conversion to the MCP JSON response format for you. Nothing useful can happen by instantiating them. Btw: That criticism applies only to the If I were to improve the design I would probably introduce a plain Ruby Object And then refactor the current Same for For some reason, |
|
Thanks for the feedback @kfischer-okarin! I'll explore the |
|
@kfischer-okarin I've opened #56 as a draft to get feedback on a more "definition" like approach. |
|
What benefits would this provide to users? There may be debate over whether an inheritance-based approach is preferable, but if an API incompatibility is introduced, users should receive benefits that justify the cost of the change. Additionally, the migration path for an API change should follow this approach:
RuboCop is a supporting tool, and as a product, this kind of migration flow is user-friendly. |
Motivation and Context
Classes are meant to be instantiated, but we expect consumers to use "macros" and define a singleton
callmethod, so we should have themextendaModuleinstead.How Has This Been Tested?
The tests have been updated.
Breaking Changes
Consumers will need to update their tools and prompts to use the module based approach instead of the class based approach. We could facilitate this by providing an autocorrecting RuboCop cop.
Types of changes
Checklist
Additional context