mcp 0.5.0 → 0.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa42259e96ff9b07eb17a7e65ec9ca1324a1cce6f969295a4cb452872302aee9
4
- data.tar.gz: f353de6d9331617ae6bf14f559b6de94e45885ce16feabbb23f65996dc8a850f
3
+ metadata.gz: de660064625f4c983293603731aad08da2dc60fe6efdc92a79c11501182610e4
4
+ data.tar.gz: 663b210aee91776875b90c06457651ff33fe2c125826ee188a8143bf5569e5e9
5
5
  SHA512:
6
- metadata.gz: 7b19b451b27926590498eb8320088cf8737c8b20e1897088f7a033e33fa8fec976c88c89e80d9e78d96202ae142e02c1698cc6ece52e9240085ad25b7fd5d4ac
7
- data.tar.gz: 88f67864aecba8e4b475a53ba49a8651a10f8909c3c7e07138603ce4ea2c489580856494519a7cc6e7e6803e47bb99c38ae32a7802cb11fa268b5c18f9c40cb3
6
+ metadata.gz: 77e28efcff07e26bf49e1509b988f137008ae19391dd86e4ebb31be7d63fdfdcb740a4d49840b4b28b319f3ccd757e8034207eedfed72e2b33b3b464ebd4ff2a
7
+ data.tar.gz: 3d83677fe719a766f73b2e91fe6e8c5109bbbb7143ef5c674a154226d0f517fb28ed3b8cce6bbac37136770892258bde3267963000f8aa43d77faaa2a83a1083
@@ -4,6 +4,8 @@ on: [push, pull_request]
4
4
  jobs:
5
5
  test:
6
6
  runs-on: ubuntu-latest
7
+ permissions:
8
+ contents: read
7
9
  strategy:
8
10
  matrix:
9
11
  entry:
@@ -27,6 +29,8 @@ jobs:
27
29
 
28
30
  rubocop:
29
31
  runs-on: ubuntu-latest
32
+ permissions:
33
+ contents: read
30
34
  name: RuboCop
31
35
  steps:
32
36
  - uses: actions/checkout@v6
@@ -38,6 +42,8 @@ jobs:
38
42
 
39
43
  yard:
40
44
  runs-on: ubuntu-latest
45
+ permissions:
46
+ contents: read
41
47
  name: YARD Documentation
42
48
  steps:
43
49
  - uses: actions/checkout@v6
data/CHANGELOG.md CHANGED
@@ -7,6 +7,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.7.0] - 2026-02-14
11
+
12
+ ### Added
13
+
14
+ - `logging` support (#103)
15
+ - Protocol version negotiation to server initialization (#223)
16
+ - Tool arguments to instrumentation data (#218)
17
+ - Client info to instrumentation callback (#221)
18
+ - `resource_templates` to `MCP::Client` (#225)
19
+
20
+ ### Changed
21
+
22
+ - Extract `MCP::Annotations` into a dedicated file (#224)
23
+
24
+ ### Fixed
25
+
26
+ - `Resource::Embedded` not setting `@resource` in `initialize` (#220)
27
+
28
+ ## [0.6.0] - 2026-01-16
29
+
30
+ ### Changed
31
+
32
+ - Update licensing to Apache 2.0 for new contributions (#213)
33
+
34
+ ### Fixed
35
+
36
+ - Omit `icons` from responses when empty or nil to reduce context window usage (#212)
37
+
10
38
  ## [0.5.0] - 2026-01-11
11
39
 
12
40
  ### Added
data/LICENSE ADDED
@@ -0,0 +1,216 @@
1
+ The MCP project is undergoing a licensing transition from the MIT License to the Apache License, Version 2.0 ("Apache-2.0"). All new code and specification contributions to the project are licensed under Apache-2.0. Documentation contributions (excluding specifications) are licensed under CC-BY-4.0.
2
+
3
+ Contributions for which relicensing consent has been obtained are licensed under Apache-2.0. Contributions made by authors who originally licensed their work under the MIT License and who have not yet granted explicit permission to relicense remain licensed under the MIT License.
4
+
5
+ No rights beyond those granted by the applicable original license are conveyed for such contributions.
6
+
7
+ ---
8
+
9
+ Apache License
10
+ Version 2.0, January 2004
11
+ http://www.apache.org/licenses/
12
+
13
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
14
+
15
+ 1. Definitions.
16
+
17
+ "License" shall mean the terms and conditions for use, reproduction,
18
+ and distribution as defined by Sections 1 through 9 of this document.
19
+
20
+ "Licensor" shall mean the copyright owner or entity authorized by
21
+ the copyright owner that is granting the License.
22
+
23
+ "Legal Entity" shall mean the union of the acting entity and all
24
+ other entities that control, are controlled by, or are under common
25
+ control with that entity. For the purposes of this definition,
26
+ "control" means (i) the power, direct or indirect, to cause the
27
+ direction or management of such entity, whether by contract or
28
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
29
+ outstanding shares, or (iii) beneficial ownership of such entity.
30
+
31
+ "You" (or "Your") shall mean an individual or Legal Entity
32
+ exercising permissions granted by this License.
33
+
34
+ "Source" form shall mean the preferred form for making modifications,
35
+ including but not limited to software source code, documentation
36
+ source, and configuration files.
37
+
38
+ "Object" form shall mean any form resulting from mechanical
39
+ transformation or translation of a Source form, including but
40
+ not limited to compiled object code, generated documentation,
41
+ and conversions to other media types.
42
+
43
+ "Work" shall mean the work of authorship, whether in Source or
44
+ Object form, made available under the License, as indicated by a
45
+ copyright notice that is included in or attached to the work
46
+ (an example is provided in the Appendix below).
47
+
48
+ "Derivative Works" shall mean any work, whether in Source or Object
49
+ form, that is based on (or derived from) the Work and for which the
50
+ editorial revisions, annotations, elaborations, or other modifications
51
+ represent, as a whole, an original work of authorship. For the purposes
52
+ of this License, Derivative Works shall not include works that remain
53
+ separable from, or merely link (or bind by name) to the interfaces of,
54
+ the Work and Derivative Works thereof.
55
+
56
+ "Contribution" shall mean any work of authorship, including
57
+ the original version of the Work and any modifications or additions
58
+ to that Work or Derivative Works thereof, that is intentionally
59
+ submitted to the Licensor for inclusion in the Work by the copyright
60
+ owner or by an individual or Legal Entity authorized to submit on behalf
61
+ of the copyright owner. For the purposes of this definition, "submitted"
62
+ means any form of electronic, verbal, or written communication sent
63
+ to the Licensor or its representatives, including but not limited to
64
+ communication on electronic mailing lists, source code control systems,
65
+ and issue tracking systems that are managed by, or on behalf of, the
66
+ Licensor for the purpose of discussing and improving the Work, but
67
+ excluding communication that is conspicuously marked or otherwise
68
+ designated in writing by the copyright owner as "Not a Contribution."
69
+
70
+ "Contributor" shall mean Licensor and any individual or Legal Entity
71
+ on behalf of whom a Contribution has been received by Licensor and
72
+ subsequently incorporated within the Work.
73
+
74
+ 2. Grant of Copyright License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ copyright license to reproduce, prepare Derivative Works of,
78
+ publicly display, publicly perform, sublicense, and distribute the
79
+ Work and such Derivative Works in Source or Object form.
80
+
81
+ 3. Grant of Patent License. Subject to the terms and conditions of
82
+ this License, each Contributor hereby grants to You a perpetual,
83
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
84
+ (except as stated in this section) patent license to make, have made,
85
+ use, offer to sell, sell, import, and otherwise transfer the Work,
86
+ where such license applies only to those patent claims licensable
87
+ by such Contributor that are necessarily infringed by their
88
+ Contribution(s) alone or by combination of their Contribution(s)
89
+ with the Work to which such Contribution(s) was submitted. If You
90
+ institute patent litigation against any entity (including a
91
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
92
+ or a Contribution incorporated within the Work constitutes direct
93
+ or contributory patent infringement, then any patent licenses
94
+ granted to You under this License for that Work shall terminate
95
+ as of the date such litigation is filed.
96
+
97
+ 4. Redistribution. You may reproduce and distribute copies of the
98
+ Work or Derivative Works thereof in any medium, with or without
99
+ modifications, and in Source or Object form, provided that You
100
+ meet the following conditions:
101
+
102
+ (a) You must give any other recipients of the Work or
103
+ Derivative Works a copy of this License; and
104
+
105
+ (b) You must cause any modified files to carry prominent notices
106
+ stating that You changed the files; and
107
+
108
+ (c) You must retain, in the Source form of any Derivative Works
109
+ that You distribute, all copyright, patent, trademark, and
110
+ attribution notices from the Source form of the Work,
111
+ excluding those notices that do not pertain to any part of
112
+ the Derivative Works; and
113
+
114
+ (d) If the Work includes a "NOTICE" text file as part of its
115
+ distribution, then any Derivative Works that You distribute must
116
+ include a readable copy of the attribution notices contained
117
+ within such NOTICE file, excluding those notices that do not
118
+ pertain to any part of the Derivative Works, in at least one
119
+ of the following places: within a NOTICE text file distributed
120
+ as part of the Derivative Works; within the Source form or
121
+ documentation, if provided along with the Derivative Works; or,
122
+ within a display generated by the Derivative Works, if and
123
+ wherever such third-party notices normally appear. The contents
124
+ of the NOTICE file are for informational purposes only and
125
+ do not modify the License. You may add Your own attribution
126
+ notices within Derivative Works that You distribute, alongside
127
+ or as an addendum to the NOTICE text from the Work, provided
128
+ that such additional attribution notices cannot be construed
129
+ as modifying the License.
130
+
131
+ You may add Your own copyright statement to Your modifications and
132
+ may provide additional or different license terms and conditions
133
+ for use, reproduction, or distribution of Your modifications, or
134
+ for any such Derivative Works as a whole, provided Your use,
135
+ reproduction, and distribution of the Work otherwise complies with
136
+ the conditions stated in this License.
137
+
138
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
139
+ any Contribution intentionally submitted for inclusion in the Work
140
+ by You to the Licensor shall be under the terms and conditions of
141
+ this License, without any additional terms or conditions.
142
+ Notwithstanding the above, nothing herein shall supersede or modify
143
+ the terms of any separate license agreement you may have executed
144
+ with Licensor regarding such Contributions.
145
+
146
+ 6. Trademarks. This License does not grant permission to use the trade
147
+ names, trademarks, service marks, or product names of the Licensor,
148
+ except as required for reasonable and customary use in describing the
149
+ origin of the Work and reproducing the content of the NOTICE file.
150
+
151
+ 7. Disclaimer of Warranty. Unless required by applicable law or
152
+ agreed to in writing, Licensor provides the Work (and each
153
+ Contributor provides its Contributions) on an "AS IS" BASIS,
154
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
155
+ implied, including, without limitation, any warranties or conditions
156
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
157
+ PARTICULAR PURPOSE. You are solely responsible for determining the
158
+ appropriateness of using or redistributing the Work and assume any
159
+ risks associated with Your exercise of permissions under this License.
160
+
161
+ 8. Limitation of Liability. In no event and under no legal theory,
162
+ whether in tort (including negligence), contract, or otherwise,
163
+ unless required by applicable law (such as deliberate and grossly
164
+ negligent acts) or agreed to in writing, shall any Contributor be
165
+ liable to You for damages, including any direct, indirect, special,
166
+ incidental, or consequential damages of any character arising as a
167
+ result of this License or out of the use or inability to use the
168
+ Work (including but not limited to damages for loss of goodwill,
169
+ work stoppage, computer failure or malfunction, or any and all
170
+ other commercial damages or losses), even if such Contributor
171
+ has been advised of the possibility of such damages.
172
+
173
+ 9. Accepting Warranty or Additional Liability. While redistributing
174
+ the Work or Derivative Works thereof, You may choose to offer,
175
+ and charge a fee for, acceptance of support, warranty, indemnity,
176
+ or other liability obligations and/or rights consistent with this
177
+ License. However, in accepting such obligations, You may act only
178
+ on Your own behalf and on Your sole responsibility, not on behalf
179
+ of any other Contributor, and only if You agree to indemnify,
180
+ defend, and hold each Contributor harmless for any liability
181
+ incurred by, or claims asserted against, such Contributor by reason
182
+ of your accepting any such warranty or additional liability.
183
+
184
+ END OF TERMS AND CONDITIONS
185
+
186
+ ---
187
+
188
+ MIT License
189
+
190
+ Copyright (c) 2024-2025 Model Context Protocol a Series of LF Projects, LLC.
191
+
192
+ Permission is hereby granted, free of charge, to any person obtaining a copy
193
+ of this software and associated documentation files (the "Software"), to deal
194
+ in the Software without restriction, including without limitation the rights
195
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
196
+ copies of the Software, and to permit persons to whom the Software is
197
+ furnished to do so, subject to the following conditions:
198
+
199
+ The above copyright notice and this permission notice shall be included in all
200
+ copies or substantial portions of the Software.
201
+
202
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
203
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
204
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
205
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
206
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
207
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
208
+ SOFTWARE.
209
+
210
+ ---
211
+
212
+ Creative Commons Attribution 4.0 International (CC-BY-4.0)
213
+
214
+ Documentation in this project (excluding specifications) is licensed under
215
+ CC-BY-4.0. See https://creativecommons.org/licenses/by/4.0/legalcode for
216
+ the full license text.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # MCP Ruby SDK [![Gem Version](https://img.shields.io/gem/v/mcp)](https://rubygems.org/gems/mcp) [![MIT licensed](https://img.shields.io/badge/license-MIT-green)](https://github.com/modelcontextprotocol/ruby-sdk/blob/main/LICENSE.txt) [![CI](https://github.com/modelcontextprotocol/ruby-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/modelcontextprotocol/ruby-sdk/actions/workflows/ci.yml)
1
+ # MCP Ruby SDK [![Gem Version](https://img.shields.io/gem/v/mcp)](https://rubygems.org/gems/mcp) [![Apache 2.0 licensed](https://img.shields.io/badge/license-Apache%202.0-blue)](https://github.com/modelcontextprotocol/ruby-sdk/blob/main/LICENSE) [![CI](https://github.com/modelcontextprotocol/ruby-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/modelcontextprotocol/ruby-sdk/actions/workflows/ci.yml)
2
2
 
3
3
  The official Ruby SDK for Model Context Protocol servers and clients.
4
4
 
@@ -113,6 +113,7 @@ The server provides three notification methods:
113
113
  - `notify_tools_list_changed` - Send a notification when the tools list changes
114
114
  - `notify_prompts_list_changed` - Send a notification when the prompts list changes
115
115
  - `notify_resources_list_changed` - Send a notification when the resources list changes
116
+ - `notify_log_message` - Send a structured logging notification message
116
117
 
117
118
  #### Notification Format
118
119
 
@@ -121,6 +122,82 @@ Notifications follow the JSON-RPC 2.0 specification and use these method names:
121
122
  - `notifications/tools/list_changed`
122
123
  - `notifications/prompts/list_changed`
123
124
  - `notifications/resources/list_changed`
125
+ - `notifications/message`
126
+
127
+ ### Logging
128
+
129
+ The MCP Ruby SDK supports structured logging through the `notify_log_message` method, following the [MCP Logging specification](https://modelcontextprotocol.io/specification/latest/server/utilities/logging).
130
+
131
+ The `notifications/message` notification is used for structured logging between client and server.
132
+
133
+ #### Log Levels
134
+
135
+ The SDK supports 8 log levels with increasing severity:
136
+
137
+ - `debug` - Detailed debugging information
138
+ - `info` - General informational messages
139
+ - `notice` - Normal but significant events
140
+ - `warning` - Warning conditions
141
+ - `error` - Error conditions
142
+ - `critical` - Critical conditions
143
+ - `alert` - Action must be taken immediately
144
+ - `emergency` - System is unusable
145
+
146
+ #### How Logging Works
147
+
148
+ 1. **Client Configuration**: The client sends a `logging/setLevel` request to configure the minimum log level
149
+ 2. **Server Filtering**: The server only sends log messages at the configured level or higher severity
150
+ 3. **Notification Delivery**: Log messages are sent as `notifications/message` to the client
151
+
152
+ For example, if the client sets the level to `"error"` (severity 4), the server will send messages with levels: `error`, `critical`, `alert`, and `emergency`.
153
+
154
+ For more details, see the [MCP Logging specification](https://modelcontextprotocol.io/specification/latest/server/utilities/logging).
155
+
156
+ **Usage Example:**
157
+
158
+ ```ruby
159
+ server = MCP::Server.new(name: "my_server")
160
+ transport = MCP::Server::Transports::StdioTransport.new(server)
161
+ server.transport = transport
162
+
163
+ # The client first configures the logging level (on the client side):
164
+ transport.send_request(
165
+ request: {
166
+ jsonrpc: "2.0",
167
+ method: "logging/setLevel",
168
+ params: { level: "info" },
169
+ id: session_id # Unique request ID within the session
170
+ }
171
+ )
172
+
173
+ # Send log messages at different severity levels
174
+ server.notify_log_message(
175
+ data: { message: "Application started successfully" },
176
+ level: "info"
177
+ )
178
+
179
+ server.notify_log_message(
180
+ data: { message: "Configuration file not found, using defaults" },
181
+ level: "warning"
182
+ )
183
+
184
+ server.notify_log_message(
185
+ data: {
186
+ error: "Database connection failed",
187
+ details: { host: "localhost", port: 5432 }
188
+ },
189
+ level: "error",
190
+ logger: "DatabaseLogger" # Optional logger name
191
+ )
192
+ ```
193
+
194
+ **Key Features:**
195
+
196
+ - Supports 8 log levels (debug, info, notice, warning, error, critical, alert, emergency) based on https://modelcontextprotocol.io/specification/2025-06-18/server/utilities/logging#log-levels
197
+ - Server has capability `logging` to send log messages
198
+ - Messages are only sent if a transport is configured
199
+ - Messages are filtered based on the client's configured log level
200
+ - If the log level hasn't been set by the client, no messages will be sent
124
201
 
125
202
  #### Transport Support
126
203
 
@@ -153,7 +230,6 @@ transport = MCP::Server::Transports::StreamableHTTPTransport.new(server, statele
153
230
 
154
231
  ### Unsupported Features (to be implemented in future versions)
155
232
 
156
- - Log Level
157
233
  - Resource subscriptions
158
234
  - Completions
159
235
  - Elicitation
@@ -320,10 +396,16 @@ The instrumentation callback receives a hash with the following possible keys:
320
396
 
321
397
  - `method`: (String) The protocol method called (e.g., "ping", "tools/list")
322
398
  - `tool_name`: (String, optional) The name of the tool called
399
+ - `tool_arguments`: (Hash, optional) The arguments passed to the tool
323
400
  - `prompt_name`: (String, optional) The name of the prompt called
324
401
  - `resource_uri`: (String, optional) The URI of the resource called
325
402
  - `error`: (String, optional) Error code if a lookup failed
326
403
  - `duration`: (Float) Duration of the call in seconds
404
+ - `client`: (Hash, optional) Client information with `name` and `version` keys, from the initialize request
405
+
406
+ > [!NOTE]
407
+ > `tool_name`, `prompt_name` and `resource_uri` are only populated if a matching handler is registered.
408
+ > This is to avoid potential issues with metric cardinality.
327
409
 
328
410
  **Type:**
329
411
 
@@ -335,9 +417,11 @@ instrumentation_callback = ->(data) { ... }
335
417
  **Example:**
336
418
 
337
419
  ```ruby
338
- config.instrumentation_callback = ->(data) {
339
- puts "Instrumentation: #{data.inspect}"
340
- }
420
+ MCP.configure do |config|
421
+ config.instrumentation_callback = ->(data) {
422
+ puts "Instrumentation: #{data.inspect}"
423
+ }
424
+ end
341
425
  ```
342
426
 
343
427
  ### Server Protocol Version
@@ -787,31 +871,6 @@ The server will handle prompt listing and execution through the MCP protocol met
787
871
  - `prompts/list` - Lists all registered prompts and their schemas
788
872
  - `prompts/get` - Retrieves and executes a specific prompt with arguments
789
873
 
790
- ### Instrumentation
791
-
792
- The server allows registering a callback to receive information about instrumentation.
793
- To register a handler pass a proc/lambda to as `instrumentation_callback` into the server constructor.
794
-
795
- ```ruby
796
- MCP.configure do |config|
797
- config.instrumentation_callback = ->(data) {
798
- puts "Got instrumentation data #{data.inspect}"
799
- }
800
- end
801
- ```
802
-
803
- The data contains the following keys:
804
-
805
- - `method`: the method called, e.g. `ping`, `tools/list`, `tools/call` etc
806
- - `tool_name`: the name of the tool called
807
- - `prompt_name`: the name of the prompt called
808
- - `resource_uri`: the uri of the resource called
809
- - `error`: if looking up tools/prompts etc failed, e.g. `tool_not_found`
810
- - `duration`: the duration of the call in seconds
811
-
812
- `tool_name`, `prompt_name` and `resource_uri` are only populated if a matching handler is registered.
813
- This is to avoid potential issues with metric cardinality
814
-
815
874
  ### Resources
816
875
 
817
876
  MCP spec includes [Resources](https://modelcontextprotocol.io/specification/latest/server/resources).
@@ -877,6 +936,7 @@ This class supports:
877
936
  - Tool listing via the `tools/list` method (`MCP::Client#tools`)
878
937
  - Tool invocation via the `tools/call` method (`MCP::Client#call_tools`)
879
938
  - Resource listing via the `resources/list` method (`MCP::Client#resources`)
939
+ - Resource template listing via the `resources/templates/list` method (`MCP::Client#resource_templates`)
880
940
  - Resource reading via the `resources/read` method (`MCP::Client#read_resources`)
881
941
  - Prompt listing via the `prompts/list` method (`MCP::Client#prompts`)
882
942
  - Prompt retrieval via the `prompts/get` method (`MCP::Client#get_prompt`)
@@ -122,6 +122,10 @@ def main
122
122
  exit(1)
123
123
  end
124
124
 
125
+ if init_response[:body].dig("result", "capabilities", "logging")
126
+ make_request(session_id, "logging/setLevel", { level: "info" })
127
+ end
128
+
125
129
  logger.info("Session initialized: #{session_id}")
126
130
  logger.info("Server info: #{init_response[:body]["result"]["serverInfo"]}")
127
131
 
@@ -107,6 +107,7 @@ app = proc do |env|
107
107
  mcp_logger.error("Response error: #{parsed_response["error"]["message"]}")
108
108
  elsif parsed_response["accepted"]
109
109
  # Response was sent via SSE
110
+ server.notify_log_message(data: { details: "Response accepted and sent via SSE" }, level: "info")
110
111
  sse_logger.info("Response sent via SSE stream")
111
112
  else
112
113
  mcp_logger.info("Response: success (id: #{parsed_response["id"]})")
@@ -105,6 +105,8 @@ module JsonRpcHandler
105
105
  result = method.call(params)
106
106
 
107
107
  success_response(id: id, result: result)
108
+ rescue MCP::Server::RequestHandlerError => e
109
+ handle_request_error(e, id, id_validation_pattern)
108
110
  rescue StandardError => e
109
111
  error_response(id: id, id_validation_pattern: id_validation_pattern, error: {
110
112
  code: ErrorCode::INTERNAL_ERROR,
@@ -114,6 +116,24 @@ module JsonRpcHandler
114
116
  end
115
117
  end
116
118
 
119
+ def handle_request_error(error, id, id_validation_pattern)
120
+ error_type = error.respond_to?(:error_type) ? error.error_type : nil
121
+
122
+ code, message = case error_type
123
+ when :invalid_request then [ErrorCode::INVALID_REQUEST, "Invalid Request"]
124
+ when :invalid_params then [ErrorCode::INVALID_PARAMS, "Invalid params"]
125
+ when :parse_error then [ErrorCode::PARSE_ERROR, "Parse error"]
126
+ when :internal_error then [ErrorCode::INTERNAL_ERROR, "Internal error"]
127
+ else [ErrorCode::INTERNAL_ERROR, "Internal error"]
128
+ end
129
+
130
+ error_response(id: id, id_validation_pattern: id_validation_pattern, error: {
131
+ code: code,
132
+ message: message,
133
+ data: error.message,
134
+ })
135
+ end
136
+
117
137
  def valid_version?(version)
118
138
  version == Version::V2_0
119
139
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MCP
4
+ class Annotations
5
+ attr_reader :audience, :priority, :last_modified
6
+
7
+ def initialize(audience: nil, priority: nil, last_modified: nil)
8
+ @audience = audience
9
+ @priority = priority
10
+ @last_modified = last_modified
11
+ end
12
+
13
+ def to_h
14
+ {
15
+ audience: audience,
16
+ priority: priority,
17
+ lastModified: last_modified,
18
+ }.compact
19
+ end
20
+ end
21
+ end
data/lib/mcp/client.rb CHANGED
@@ -58,6 +58,20 @@ module MCP
58
58
  response.dig("result", "resources") || []
59
59
  end
60
60
 
61
+ # Returns the list of resource templates available from the server.
62
+ # Each call will make a new request – the result is not cached.
63
+ #
64
+ # @return [Array<Hash>] An array of available resource templates.
65
+ def resource_templates
66
+ response = transport.send_request(request: {
67
+ jsonrpc: JsonRpcHandler::Version::V2_0,
68
+ id: request_id,
69
+ method: "resources/templates/list",
70
+ })
71
+
72
+ response.dig("result", "resourceTemplates") || []
73
+ end
74
+
61
75
  # Returns the list of prompts available from the server.
62
76
  # Each call will make a new request – the result is not cached.
63
77
  #
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MCP
4
+ class LoggingMessageNotification
5
+ LOG_LEVEL_SEVERITY = {
6
+ "debug" => 0,
7
+ "info" => 1,
8
+ "notice" => 2,
9
+ "warning" => 3,
10
+ "error" => 4,
11
+ "critical" => 5,
12
+ "alert" => 6,
13
+ "emergency" => 7,
14
+ }.freeze
15
+
16
+ def initialize(level:)
17
+ @level = level
18
+ end
19
+
20
+ def valid_level?
21
+ LOG_LEVEL_SEVERITY.keys.include?(@level)
22
+ end
23
+
24
+ def should_notify?(log_level)
25
+ return false unless LOG_LEVEL_SEVERITY.key?(log_level)
26
+
27
+ LOG_LEVEL_SEVERITY[log_level] >= LOG_LEVEL_SEVERITY[@level]
28
+ end
29
+ end
30
+ end
data/lib/mcp/prompt.rb CHANGED
@@ -20,7 +20,7 @@ module MCP
20
20
  name: name_value,
21
21
  title: title_value,
22
22
  description: description_value,
23
- icons: icons&.map(&:to_h),
23
+ icons: icons_value&.then { |icons| icons.empty? ? nil : icons.map(&:to_h) },
24
24
  arguments: arguments_value&.map(&:to_h),
25
25
  _meta: meta_value,
26
26
  }.compact
@@ -6,6 +6,7 @@ module MCP
6
6
  attr_reader :resource, :annotations
7
7
 
8
8
  def initialize(resource:, annotations: nil)
9
+ @resource = resource
9
10
  @annotations = annotations
10
11
  end
11
12
 
data/lib/mcp/resource.rb CHANGED
@@ -19,7 +19,7 @@ module MCP
19
19
  name: name,
20
20
  title: title,
21
21
  description: description,
22
- icons: icons.map(&:to_h),
22
+ icons: icons&.then { |icons| icons.empty? ? nil : icons.map(&:to_h) },
23
23
  mimeType: mime_type,
24
24
  }.compact
25
25
  end
@@ -19,7 +19,7 @@ module MCP
19
19
  name: name,
20
20
  title: title,
21
21
  description: description,
22
- icons: icons.map(&:to_h),
22
+ icons: icons&.then { |icons| icons.empty? ? nil : icons.map(&:to_h) },
23
23
  mimeType: mime_type,
24
24
  }.compact
25
25
  end
data/lib/mcp/server.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative "../json_rpc_handler"
4
4
  require_relative "instrumentation"
5
5
  require_relative "methods"
6
+ require_relative "logging_message_notification"
6
7
 
7
8
  module MCP
8
9
  class ToolNotUnique < StandardError
@@ -17,6 +18,9 @@ module MCP
17
18
  class Server
18
19
  DEFAULT_VERSION = "0.1.0"
19
20
 
21
+ UNSUPPORTED_PROPERTIES_UNTIL_2025_06_18 = [:description, :icons].freeze
22
+ UNSUPPORTED_PROPERTIES_UNTIL_2025_03_26 = [:title, :websiteUrl].freeze
23
+
20
24
  class RequestHandlerError < StandardError
21
25
  attr_reader :error_type
22
26
  attr_reader :original_error
@@ -40,7 +44,7 @@ module MCP
40
44
 
41
45
  include Instrumentation
42
46
 
43
- attr_accessor :description, :icons, :name, :title, :version, :website_url, :instructions, :tools, :prompts, :resources, :server_context, :configuration, :capabilities, :transport
47
+ attr_accessor :description, :icons, :name, :title, :version, :website_url, :instructions, :tools, :prompts, :resources, :server_context, :configuration, :capabilities, :transport, :logging_message_notification
44
48
 
45
49
  def initialize(
46
50
  description: nil,
@@ -74,10 +78,12 @@ module MCP
74
78
  @resource_index = index_resources_by_uri(resources)
75
79
  @server_context = server_context
76
80
  @configuration = MCP.configuration.merge(configuration)
81
+ @client = nil
77
82
 
78
83
  validate!
79
84
 
80
85
  @capabilities = capabilities || default_capabilities
86
+ @logging_message_notification = nil
81
87
 
82
88
  @handlers = {
83
89
  Methods::RESOURCES_LIST => method(:list_resources),
@@ -90,12 +96,12 @@ module MCP
90
96
  Methods::INITIALIZE => method(:init),
91
97
  Methods::PING => ->(_) { {} },
92
98
  Methods::NOTIFICATIONS_INITIALIZED => ->(_) {},
99
+ Methods::LOGGING_SET_LEVEL => method(:configure_logging_level),
93
100
 
94
101
  # No op handlers for currently unsupported methods
95
102
  Methods::RESOURCES_SUBSCRIBE => ->(_) {},
96
103
  Methods::RESOURCES_UNSUBSCRIBE => ->(_) {},
97
104
  Methods::COMPLETION_COMPLETE => ->(_) {},
98
- Methods::LOGGING_SET_LEVEL => ->(_) {},
99
105
  Methods::ELICITATION_CREATE => ->(_) {},
100
106
  }
101
107
  @transport = transport
@@ -162,6 +168,18 @@ module MCP
162
168
  report_exception(e, { notification: "resources_list_changed" })
163
169
  end
164
170
 
171
+ def notify_log_message(data:, level:, logger: nil)
172
+ return unless @transport
173
+ return unless logging_message_notification&.should_notify?(level)
174
+
175
+ params = { "data" => data, "level" => level }
176
+ params["logger"] = logger if logger
177
+
178
+ @transport.send_notification(Methods::NOTIFICATIONS_MESSAGE, params)
179
+ rescue => e
180
+ report_exception(e, { notification: "log_message" })
181
+ end
182
+
165
183
  def resources_list_handler(&block)
166
184
  @handlers[Methods::RESOURCES_LIST] = block
167
185
  end
@@ -244,7 +262,9 @@ module MCP
244
262
  def handle_request(request, method)
245
263
  handler = @handlers[method]
246
264
  unless handler
247
- instrument_call("unsupported_method") {}
265
+ instrument_call("unsupported_method") do
266
+ add_instrumentation_data(client: @client) if @client
267
+ end
248
268
  return
249
269
  end
250
270
 
@@ -252,7 +272,7 @@ module MCP
252
272
 
253
273
  ->(params) {
254
274
  instrument_call(method) do
255
- case method
275
+ result = case method
256
276
  when Methods::TOOLS_LIST
257
277
  { tools: @handlers[Methods::TOOLS_LIST].call(params) }
258
278
  when Methods::PROMPTS_LIST
@@ -266,6 +286,9 @@ module MCP
266
286
  else
267
287
  @handlers[method].call(params)
268
288
  end
289
+ add_instrumentation_data(client: @client) if @client
290
+
291
+ result
269
292
  rescue => e
270
293
  report_exception(e, { request: request })
271
294
  if e.is_a?(RequestHandlerError)
@@ -284,13 +307,14 @@ module MCP
284
307
  tools: { listChanged: true },
285
308
  prompts: { listChanged: true },
286
309
  resources: { listChanged: true },
310
+ logging: {},
287
311
  }
288
312
  end
289
313
 
290
314
  def server_info
291
315
  @server_info ||= {
292
316
  description: description,
293
- icons: icons,
317
+ icons: icons&.then { |icons| icons.empty? ? nil : icons.map(&:to_h) },
294
318
  name: name,
295
319
  title: title,
296
320
  version: version,
@@ -298,15 +322,48 @@ module MCP
298
322
  }.compact
299
323
  end
300
324
 
301
- def init(request)
325
+ def init(params)
326
+ @client = params[:clientInfo] if params
327
+
328
+ protocol_version = params[:protocolVersion] if params
329
+ negotiated_version = if Configuration::SUPPORTED_STABLE_PROTOCOL_VERSIONS.include?(protocol_version)
330
+ protocol_version
331
+ else
332
+ configuration.protocol_version
333
+ end
334
+
335
+ info = server_info.reject do |property|
336
+ negotiated_version <= "2025-06-18" && UNSUPPORTED_PROPERTIES_UNTIL_2025_06_18.include?(property) ||
337
+ negotiated_version <= "2025-03-26" && UNSUPPORTED_PROPERTIES_UNTIL_2025_03_26.include?(property)
338
+ end
339
+
340
+ response_instructions = instructions
341
+
342
+ if negotiated_version == "2024-11-05"
343
+ response_instructions = nil
344
+ end
345
+
302
346
  {
303
- protocolVersion: configuration.protocol_version,
347
+ protocolVersion: negotiated_version,
304
348
  capabilities: capabilities,
305
- serverInfo: server_info,
306
- instructions: instructions,
349
+ serverInfo: info,
350
+ instructions: response_instructions,
307
351
  }.compact
308
352
  end
309
353
 
354
+ def configure_logging_level(request)
355
+ if capabilities[:logging].nil?
356
+ raise RequestHandlerError.new("Server does not support logging", request, error_type: :internal_error)
357
+ end
358
+
359
+ logging_message_notification = LoggingMessageNotification.new(level: request[:level])
360
+ unless logging_message_notification.valid_level?
361
+ raise RequestHandlerError.new("Invalid log level #{request[:level]}", request, error_type: :invalid_params)
362
+ end
363
+
364
+ @logging_message_notification = logging_message_notification
365
+ end
366
+
310
367
  def list_tools(request)
311
368
  @tools.values.map(&:to_h)
312
369
  end
@@ -322,7 +379,7 @@ module MCP
322
379
  end
323
380
 
324
381
  arguments = request[:arguments] || {}
325
- add_instrumentation_data(tool_name: tool_name)
382
+ add_instrumentation_data(tool_name: tool_name, tool_arguments: arguments)
326
383
 
327
384
  if tool.input_schema&.missing_required_arguments?(arguments)
328
385
  add_instrumentation_data(error: :missing_required_arguments)
data/lib/mcp/tool.rb CHANGED
@@ -21,7 +21,7 @@ module MCP
21
21
  name: name_value,
22
22
  title: title_value,
23
23
  description: description_value,
24
- icons: icons&.map(&:to_h),
24
+ icons: icons_value&.then { |icons| icons.empty? ? nil : icons.map(&:to_h) },
25
25
  inputSchema: input_schema_value.to_h,
26
26
  outputSchema: @output_schema_value&.to_h,
27
27
  annotations: annotations_value&.to_h,
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.5.0"
4
+ VERSION = "0.7.0"
5
5
  end
data/lib/mcp.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "json_rpc_handler"
4
+ require_relative "mcp/annotations"
4
5
  require_relative "mcp/configuration"
5
6
  require_relative "mcp/content"
6
7
  require_relative "mcp/icon"
@@ -39,13 +40,4 @@ module MCP
39
40
  @configuration ||= Configuration.new
40
41
  end
41
42
  end
42
-
43
- class Annotations
44
- attr_reader :audience, :priority
45
-
46
- def initialize(audience: nil, priority: nil)
47
- @audience = audience
48
- @priority = priority
49
- end
50
- end
51
43
  end
data/mcp.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = "The official Ruby SDK for Model Context Protocol servers and clients"
12
12
  spec.description = spec.summary
13
13
  spec.homepage = "https://github.com/modelcontextprotocol/ruby-sdk"
14
- spec.license = "MIT"
14
+ spec.license = "Apache-2.0"
15
15
 
16
16
  # Since this library is used by a broad range of users, it does not align its support policy with Ruby's EOL.
17
17
  spec.required_ruby_version = ">= 2.7.0"
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.5.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Model Context Protocol
@@ -40,7 +40,7 @@ files:
40
40
  - CHANGELOG.md
41
41
  - CODE_OF_CONDUCT.md
42
42
  - Gemfile
43
- - LICENSE.txt
43
+ - LICENSE
44
44
  - README.md
45
45
  - RELEASE.md
46
46
  - Rakefile
@@ -60,6 +60,7 @@ files:
60
60
  - examples/streamable_http_server.rb
61
61
  - lib/json_rpc_handler.rb
62
62
  - lib/mcp.rb
63
+ - lib/mcp/annotations.rb
63
64
  - lib/mcp/client.rb
64
65
  - lib/mcp/client/http.rb
65
66
  - lib/mcp/client/tool.rb
@@ -67,6 +68,7 @@ files:
67
68
  - lib/mcp/content.rb
68
69
  - lib/mcp/icon.rb
69
70
  - lib/mcp/instrumentation.rb
71
+ - lib/mcp/logging_message_notification.rb
70
72
  - lib/mcp/methods.rb
71
73
  - lib/mcp/prompt.rb
72
74
  - lib/mcp/prompt/argument.rb
@@ -93,10 +95,10 @@ files:
93
95
  - mcp.gemspec
94
96
  homepage: https://github.com/modelcontextprotocol/ruby-sdk
95
97
  licenses:
96
- - MIT
98
+ - Apache-2.0
97
99
  metadata:
98
100
  allowed_push_host: https://rubygems.org
99
- changelog_uri: https://github.com/modelcontextprotocol/ruby-sdk/releases/tag/v0.5.0
101
+ changelog_uri: https://github.com/modelcontextprotocol/ruby-sdk/releases/tag/v0.7.0
100
102
  homepage_uri: https://github.com/modelcontextprotocol/ruby-sdk
101
103
  source_code_uri: https://github.com/modelcontextprotocol/ruby-sdk
102
104
  bug_tracker_uri: https://github.com/modelcontextprotocol/ruby-sdk/issues
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2025 TODO: Write your name
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.