model-context-protocol-rb 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e004a2e471748b63aa9f5742300fd2b648aabb84d02e75949f9741f1c78aa963
|
4
|
+
data.tar.gz: ecf369882f10f2cb19099d47d991ba70e6d33e0841ebda48e6917fb98780f2fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fa10a6fe78390f0d8c6303efcc6135751b50a2c4dd3cc2b0ed0d07e0647e9555a3317a7b68b2794d52f9d6ac3e8e38a569bda96e20bc2e0193dadefab346dd6
|
7
|
+
data.tar.gz: fda6f707e7814911a4e9175cd40fbab41f45dc775db644185e4bc2008fe71bddd83c89ed321cfeee67f93cbf7c29bc6e69b46596893e3ae2242fa757fd9f4f75
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.3.4] - 2025-09-02
|
4
|
+
|
5
|
+
- (Fix) Fixes broken arguments usage in prompts and tools.
|
6
|
+
|
3
7
|
## [0.3.3] - 2025-09-02
|
4
8
|
|
5
9
|
- (Breaking) Added logging support.
|
@@ -47,7 +51,8 @@
|
|
47
51
|
|
48
52
|
- Initial release
|
49
53
|
|
50
|
-
[Unreleased]: https://github.com/dickdavis/model-context-protocol-rb/compare/v0.3.
|
54
|
+
[Unreleased]: https://github.com/dickdavis/model-context-protocol-rb/compare/v0.3.4...HEAD
|
55
|
+
[0.3.4]: https://github.com/dickdavis/model-context-protocol-rb/compare/v0.3.3...v0.3.4
|
51
56
|
[0.3.3]: https://github.com/dickdavis/model-context-protocol-rb/compare/v0.3.2...v0.3.3
|
52
57
|
[0.3.2]: https://github.com/dickdavis/model-context-protocol-rb/compare/v0.3.1...v0.3.2
|
53
58
|
[0.3.1]: https://github.com/dickdavis/model-context-protocol-rb/compare/v0.3.0...v0.3.1
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module ModelContextProtocol
|
2
2
|
class Server::Prompt
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :arguments, :context, :logger
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
validate!(
|
7
|
-
@
|
5
|
+
def initialize(arguments, logger, context = {})
|
6
|
+
validate!(arguments)
|
7
|
+
@arguments = arguments
|
8
8
|
@context = context
|
9
9
|
@logger = logger
|
10
10
|
end
|
@@ -24,18 +24,18 @@ module ModelContextProtocol
|
|
24
24
|
Response[messages:, description: self.class.description]
|
25
25
|
end
|
26
26
|
|
27
|
-
private def validate!(
|
28
|
-
|
29
|
-
required_args =
|
30
|
-
valid_arg_names =
|
27
|
+
private def validate!(arguments = {})
|
28
|
+
defined_arguments = self.class.defined_arguments || []
|
29
|
+
required_args = defined_arguments.select { |arg| arg[:required] }.map { |arg| arg[:name].to_sym }
|
30
|
+
valid_arg_names = defined_arguments.map { |arg| arg[:name].to_sym }
|
31
31
|
|
32
|
-
missing_args = required_args -
|
32
|
+
missing_args = required_args - arguments.keys
|
33
33
|
unless missing_args.empty?
|
34
34
|
missing_args_list = missing_args.join(", ")
|
35
35
|
raise ArgumentError, "Missing required arguments: #{missing_args_list}"
|
36
36
|
end
|
37
37
|
|
38
|
-
extra_args =
|
38
|
+
extra_args = arguments.keys - valid_arg_names
|
39
39
|
unless extra_args.empty?
|
40
40
|
extra_args_list = extra_args.join(", ")
|
41
41
|
raise ArgumentError, "Unexpected arguments: #{extra_args_list}"
|
@@ -43,10 +43,10 @@ module ModelContextProtocol
|
|
43
43
|
end
|
44
44
|
|
45
45
|
class << self
|
46
|
-
attr_reader :name, :description, :
|
46
|
+
attr_reader :name, :description, :defined_arguments
|
47
47
|
|
48
48
|
def with_metadata(&block)
|
49
|
-
@
|
49
|
+
@defined_arguments ||= []
|
50
50
|
|
51
51
|
metadata_dsl = MetadataDSL.new
|
52
52
|
metadata_dsl.instance_eval(&block)
|
@@ -56,12 +56,12 @@ module ModelContextProtocol
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def with_argument(&block)
|
59
|
-
@
|
59
|
+
@defined_arguments ||= []
|
60
60
|
|
61
61
|
argument_dsl = ArgumentDSL.new
|
62
62
|
argument_dsl.instance_eval(&block)
|
63
63
|
|
64
|
-
@
|
64
|
+
@defined_arguments << {
|
65
65
|
name: argument_dsl.name,
|
66
66
|
description: argument_dsl.description,
|
67
67
|
required: argument_dsl.required,
|
@@ -72,21 +72,21 @@ module ModelContextProtocol
|
|
72
72
|
def inherited(subclass)
|
73
73
|
subclass.instance_variable_set(:@name, @name)
|
74
74
|
subclass.instance_variable_set(:@description, @description)
|
75
|
-
subclass.instance_variable_set(:@
|
75
|
+
subclass.instance_variable_set(:@defined_arguments, @defined_arguments&.dup)
|
76
76
|
end
|
77
77
|
|
78
|
-
def call(
|
79
|
-
new(
|
78
|
+
def call(arguments, logger, context = {})
|
79
|
+
new(arguments, logger, context).call
|
80
80
|
rescue ArgumentError => error
|
81
81
|
raise ModelContextProtocol::Server::ParameterValidationError, error.message
|
82
82
|
end
|
83
83
|
|
84
84
|
def metadata
|
85
|
-
{name: @name, description: @description, arguments: @
|
85
|
+
{name: @name, description: @description, arguments: @defined_arguments}
|
86
86
|
end
|
87
87
|
|
88
88
|
def complete_for(arg_name, value)
|
89
|
-
arg = @
|
89
|
+
arg = @defined_arguments&.find { |a| a[:name] == arg_name.to_s }
|
90
90
|
completion = (arg && arg[:completion]) ? arg[:completion] : ModelContextProtocol::Server::NullCompletion
|
91
91
|
completion.call(arg_name.to_s, value)
|
92
92
|
end
|
@@ -2,11 +2,11 @@ require "json-schema"
|
|
2
2
|
|
3
3
|
module ModelContextProtocol
|
4
4
|
class Server::Tool
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :arguments, :context, :logger
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
validate!(
|
9
|
-
@
|
7
|
+
def initialize(arguments, logger, context = {})
|
8
|
+
validate!(arguments)
|
9
|
+
@arguments = arguments
|
10
10
|
@context = context
|
11
11
|
@logger = logger
|
12
12
|
end
|
@@ -70,8 +70,8 @@ module ModelContextProtocol
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
private def validate!(
|
74
|
-
JSON::Validator.validate!(self.class.input_schema,
|
73
|
+
private def validate!(arguments)
|
74
|
+
JSON::Validator.validate!(self.class.input_schema, arguments)
|
75
75
|
end
|
76
76
|
|
77
77
|
class << self
|
@@ -92,8 +92,8 @@ module ModelContextProtocol
|
|
92
92
|
subclass.instance_variable_set(:@input_schema, @input_schema)
|
93
93
|
end
|
94
94
|
|
95
|
-
def call(
|
96
|
-
new(
|
95
|
+
def call(arguments, logger, context = {})
|
96
|
+
new(arguments, logger, context).call
|
97
97
|
rescue JSON::Schema::ValidationError => validation_error
|
98
98
|
raise ModelContextProtocol::Server::ParameterValidationError, validation_error.message
|
99
99
|
rescue ModelContextProtocol::Server::ResponseArgumentsError => response_arguments_error
|