Uh oh!
There was an error while loading. Please reload this page.
Refactor towards simple data/config classes - #56
Conversation
Also, implement `Annotations#to_h`
sambostock
commented
Jun 10, 2025
@koicasked the following on #48, which is also relevant here, so I'm transcribing it:
|
sambostock
commented
Jun 10, 2025
My original motivation for this was that as a consumer I found the API confusing: why define a class that will never be instantiated and only have singleton methods? In addition, the existing approach has (IMO) a higher implementation complexity because of the various "macros" for setting/getting the configured values, as well as the unusual In this new approach, we maintain a clear separation between the "schema" and the behaviour (isolated in the handler block):
Technically, this gem's README says it follows Semantic Versioning, and since we're still on a 0.x version, we're "free to make breaking changes at any time", and perhaps we should consider if it makes more sense to rapidly iterate towards a feature complete 1.0 release. That said, if we want to go the deprecation warning route, I think we would do something like the following:
Footnotes
|
kfischer-okarin
left a comment
There was a problem hiding this comment.
One comment I had seeing this PR in general... I think it might be more idiomatic and simpler to just use actual Data classes offered by Ruby
@kfischer-okarin I flip-flopped on using I gave it a shot based on your feedback (sambostock/mcp-ruby-sdk@data...sambostock:mcp-ruby-sdk:data-define), and based on what I found, I think it's still preferable to stick to POROs:
To expand on the last point # frozen_string_literal: truerequire"minitest/autorun"classUsingPOROattr_reader:required_positional,:optional_keyworddefinitialize(required_positional,optional_keyword: nil)@required_positional=required_positional@optional_keyword=optional_keywordendendUsingData=Data.define(:required_positional,:optional_keyword)dodefinitialize(required_positional:,optional_keyword: nil)=super(required_positional:,optional_keyword:)endclassMixedPositionalAndKeywordTest < Minitest::Test[UsingPORO,UsingData].eachdo |klass|
define_method"test_#{klass.name}.new('positional') works"doklass.new("positional")enddefine_method"test_#{klass.name}.new('positional', 'optional') raises ArgumentError"doassert_raises(ArgumentError){klass.new("positional","optional")}enddefine_method"test_#{klass.name}.new('positional', optional_keyword: 'optional') works"doklass.new("positional",optional_keyword: "optional")endendend$ ruby data.rbRun options: --seed 26182
# Running:F.E...Finished in 0.000440s, 13636.3644 runs/s, 4545.4548 assertions/s. 1) Failure:MixedPositionalAndKeywordTest#test_UsingData.new('positional', 'optional') raises ArgumentError [data.rb:25]:ArgumentError expected but nothing was raised. 2) Error:MixedPositionalAndKeywordTest#test_UsingData.new('positional', optional_keyword: 'optional') works:ArgumentError: wrong number of arguments (given 2, expected 0) data.rb:29:in 'UsingData.new' data.rb:29:in 'block (2 levels) in <class:MixedPositionalAndKeywordTest>'6 runs, 2 assertions, 1 failures, 1 errors, 0 skipsIMO given the simplicity of the API we're trying to offer, I think it's simplest to stick to POROs. |
kfischer-okarin
commented
Jun 12, 2025
@sambostock Ok, good reasonable points about not choosing the Data class approach - I can get behind that 👍🏻 It would be nice if the examples/docs were also updated to reflect the new API I was wondering if it would also be a good idea to make resources and resource templates also take blocks as I also think it's okay to be not sooo careful about breaking changes since we're before v1.0.0 - the error message and the necessary rewrite are both straightforward enough. If you wanted to be a bit nicer, you could offer a little mini code rewrite example right inside the error message. Or give those examples in longer form in a Changelog entry and refer to that in the error message. |
sambostock
commented
Jun 12, 2025
I agree with all of the above. Incidentally, if merged, #55 would enforce the examples are updated. I'll explore the resource changes you mentioned next week. 👍 |
koic
commented
Apr 11, 2026
Because there have been significant changes to the Ruby SDK implementation, this PR will be closed. Thank you for the contribution. |
This PR is an alternative to #48, with the same underlying motivations. It explores the idea of having tools and prompts be defined as simple data/config/value objects, and drops support for the current inheritance based approach.
It is a work in progress, but I have opted to open a draft now to get feedback, especially as it relates to other PRs, such as #54.
Motivation and Context
How Has This Been Tested?
Breaking Changes
Types of changes
Checklist
Additional context