mcp 0.4.0 → 0.5.0

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.
data/lib/mcp/tool.rb CHANGED
@@ -4,9 +4,11 @@ module MCP
4
4
  class Tool
5
5
  class << self
6
6
  NOT_SET = Object.new
7
+ MAX_LENGTH_OF_NAME = 128
7
8
 
8
9
  attr_reader :title_value
9
10
  attr_reader :description_value
11
+ attr_reader :icons_value
10
12
  attr_reader :annotations_value
11
13
  attr_reader :meta_value
12
14
 
@@ -19,6 +21,7 @@ module MCP
19
21
  name: name_value,
20
22
  title: title_value,
21
23
  description: description_value,
24
+ icons: icons&.map(&:to_h),
22
25
  inputSchema: input_schema_value.to_h,
23
26
  outputSchema: @output_schema_value&.to_h,
24
27
  annotations: annotations_value&.to_h,
@@ -31,6 +34,7 @@ module MCP
31
34
  subclass.instance_variable_set(:@name_value, nil)
32
35
  subclass.instance_variable_set(:@title_value, nil)
33
36
  subclass.instance_variable_set(:@description_value, nil)
37
+ subclass.instance_variable_set(:@icons_value, nil)
34
38
  subclass.instance_variable_set(:@input_schema_value, nil)
35
39
  subclass.instance_variable_set(:@output_schema_value, nil)
36
40
  subclass.instance_variable_set(:@annotations_value, nil)
@@ -42,11 +46,13 @@ module MCP
42
46
  name_value
43
47
  else
44
48
  @name_value = value
49
+
50
+ validate!
45
51
  end
46
52
  end
47
53
 
48
54
  def name_value
49
- @name_value || StringUtils.handle_from_class_name(name)
55
+ @name_value || (name.nil? ? nil : StringUtils.handle_from_class_name(name))
50
56
  end
51
57
 
52
58
  def input_schema_value
@@ -71,13 +77,19 @@ module MCP
71
77
  end
72
78
  end
73
79
 
80
+ def icons(value = NOT_SET)
81
+ if value == NOT_SET
82
+ @icons_value
83
+ else
84
+ @icons_value = value
85
+ end
86
+ end
87
+
74
88
  def input_schema(value = NOT_SET)
75
89
  if value == NOT_SET
76
90
  input_schema_value
77
91
  elsif value.is_a?(Hash)
78
- properties = value[:properties] || value["properties"] || {}
79
- required = value[:required] || value["required"] || []
80
- @input_schema_value = InputSchema.new(properties:, required:)
92
+ @input_schema_value = InputSchema.new(value)
81
93
  elsif value.is_a?(InputSchema)
82
94
  @input_schema_value = value
83
95
  end
@@ -109,16 +121,33 @@ module MCP
109
121
  end
110
122
  end
111
123
 
112
- def define(name: nil, title: nil, description: nil, input_schema: nil, output_schema: nil, meta: nil, annotations: nil, &block)
124
+ def define(name: nil, title: nil, description: nil, icons: [], input_schema: nil, output_schema: nil, meta: nil, annotations: nil, &block)
113
125
  Class.new(self) do
114
126
  tool_name name
115
127
  title title
116
128
  description description
129
+ icons icons
117
130
  input_schema input_schema
118
131
  meta meta
119
132
  output_schema output_schema
120
133
  self.annotations(annotations) if annotations
121
134
  define_singleton_method(:call, &block) if block
135
+ end.tap(&:validate!)
136
+ end
137
+
138
+ # It complies with the following tool name specification:
139
+ # https://modelcontextprotocol.io/specification/latest/server/tools#tool-names
140
+ def validate!
141
+ return true unless tool_name
142
+
143
+ if tool_name.empty? || tool_name.length > MAX_LENGTH_OF_NAME
144
+ raise ArgumentError, "Tool names should be between 1 and 128 characters in length (inclusive)."
145
+ end
146
+
147
+ unless tool_name.match?(/\A[A-Za-z\d_\-\.]+\z/)
148
+ raise ArgumentError, <<~MESSAGE
149
+ Tool names only allowed characters: uppercase and lowercase ASCII letters (A-Z, a-z), digits (0-9), underscore (_), hyphen (-), and dot (.).
150
+ MESSAGE
122
151
  end
123
152
  end
124
153
  end
data/lib/mcp/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MCP
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/mcp.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "json_rpc_handler"
3
4
  require_relative "mcp/configuration"
4
5
  require_relative "mcp/content"
6
+ require_relative "mcp/icon"
5
7
  require_relative "mcp/instrumentation"
6
8
  require_relative "mcp/methods"
7
9
  require_relative "mcp/prompt"
data/mcp.gemspec CHANGED
@@ -13,11 +13,15 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/modelcontextprotocol/ruby-sdk"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.required_ruby_version = ">= 3.2.0"
16
+ # Since this library is used by a broad range of users, it does not align its support policy with Ruby's EOL.
17
+ spec.required_ruby_version = ">= 2.7.0"
17
18
 
18
19
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+ spec.metadata["changelog_uri"] = "https://github.com/modelcontextprotocol/ruby-sdk/releases/tag/v#{spec.version}"
19
21
  spec.metadata["homepage_uri"] = spec.homepage
20
22
  spec.metadata["source_code_uri"] = spec.homepage
23
+ spec.metadata["bug_tracker_uri"] = "#{spec.homepage}/issues"
24
+ spec.metadata["documentation_uri"] = "https://rubydoc.info/gems/mcp"
21
25
 
22
26
  spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
23
27
  %x(git ls-files -z).split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -27,6 +31,5 @@ Gem::Specification.new do |spec|
27
31
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
32
  spec.require_paths = ["lib"]
29
33
 
30
- spec.add_dependency("json_rpc_handler", "~> 0.1")
31
34
  spec.add_dependency("json-schema", ">= 4.1")
32
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mcp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Model Context Protocol
@@ -9,20 +9,6 @@ bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
- - !ruby/object:Gem::Dependency
13
- name: json_rpc_handler
14
- requirement: !ruby/object:Gem::Requirement
15
- requirements:
16
- - - "~>"
17
- - !ruby/object:Gem::Version
18
- version: '0.1'
19
- type: :runtime
20
- prerelease: false
21
- version_requirements: !ruby/object:Gem::Requirement
22
- requirements:
23
- - - "~>"
24
- - !ruby/object:Gem::Version
25
- version: '0.1'
26
12
  - !ruby/object:Gem::Dependency
27
13
  name: json-schema
28
14
  requirement: !ruby/object:Gem::Requirement
@@ -56,23 +42,30 @@ files:
56
42
  - Gemfile
57
43
  - LICENSE.txt
58
44
  - README.md
45
+ - RELEASE.md
59
46
  - Rakefile
60
47
  - bin/console
48
+ - bin/generate-gh-pages.sh
61
49
  - bin/rake
62
50
  - bin/setup
63
51
  - dev.yml
52
+ - docs/_config.yml
53
+ - docs/index.md
54
+ - docs/latest/index.html
64
55
  - examples/README.md
65
56
  - examples/http_client.rb
66
57
  - examples/http_server.rb
67
58
  - examples/stdio_server.rb
68
59
  - examples/streamable_http_client.rb
69
60
  - examples/streamable_http_server.rb
61
+ - lib/json_rpc_handler.rb
70
62
  - lib/mcp.rb
71
63
  - lib/mcp/client.rb
72
64
  - lib/mcp/client/http.rb
73
65
  - lib/mcp/client/tool.rb
74
66
  - lib/mcp/configuration.rb
75
67
  - lib/mcp/content.rb
68
+ - lib/mcp/icon.rb
76
69
  - lib/mcp/instrumentation.rb
77
70
  - lib/mcp/methods.rb
78
71
  - lib/mcp/prompt.rb
@@ -93,6 +86,7 @@ files:
93
86
  - lib/mcp/tool/input_schema.rb
94
87
  - lib/mcp/tool/output_schema.rb
95
88
  - lib/mcp/tool/response.rb
89
+ - lib/mcp/tool/schema.rb
96
90
  - lib/mcp/transport.rb
97
91
  - lib/mcp/transports/stdio.rb
98
92
  - lib/mcp/version.rb
@@ -102,8 +96,11 @@ licenses:
102
96
  - MIT
103
97
  metadata:
104
98
  allowed_push_host: https://rubygems.org
99
+ changelog_uri: https://github.com/modelcontextprotocol/ruby-sdk/releases/tag/v0.5.0
105
100
  homepage_uri: https://github.com/modelcontextprotocol/ruby-sdk
106
101
  source_code_uri: https://github.com/modelcontextprotocol/ruby-sdk
102
+ bug_tracker_uri: https://github.com/modelcontextprotocol/ruby-sdk/issues
103
+ documentation_uri: https://rubydoc.info/gems/mcp
107
104
  rdoc_options: []
108
105
  require_paths:
109
106
  - lib
@@ -111,14 +108,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
108
  requirements:
112
109
  - - ">="
113
110
  - !ruby/object:Gem::Version
114
- version: 3.2.0
111
+ version: 2.7.0
115
112
  required_rubygems_version: !ruby/object:Gem::Requirement
116
113
  requirements:
117
114
  - - ">="
118
115
  - !ruby/object:Gem::Version
119
116
  version: '0'
120
117
  requirements: []
121
- rubygems_version: 3.6.9
118
+ rubygems_version: 4.0.3
122
119
  specification_version: 4
123
120
  summary: The official Ruby SDK for Model Context Protocol servers and clients
124
121
  test_files: []