Skip to content

Commit cd46813

Browse files
authored
Merge branch 'main' into main
2 parents aad8e94 + 5c5f420 commit cd46813

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ Notifications follow the JSON-RPC 2.0 specification and use these method names:
124124

125125
#### Transport Support
126126

127-
- **HTTP Transport**: Notifications are sent as Server-Sent Events (SSE) to all connected sessions
128-
- **Stdio Transport**: Notifications are sent as JSON-RPC 2.0 messages to stdout
127+
- **stdio**: Notifications are sent as JSON-RPC 2.0 messages to stdout
128+
- **Streamable HTTP**: Notifications are sent as JSON-RPC 2.0 messages over HTTP with streaming (chunked transfer or SSE)
129129

130130
#### Usage Example
131131

@@ -456,6 +456,9 @@ Tools can include annotations that provide additional metadata about their behav
456456

457457
Annotations can be set either through the class definition using the `annotations` class method or when defining a tool using the `define` method.
458458

459+
> [!NOTE]
460+
> This **Tool Annotations** feature is supported starting from `protocol_version: '2025-03-26'`.
461+
459462
### Tool Output Schemas
460463

461464
Tools can optionally define an `output_schema` to specify the expected structure of their results. This works similarly to how `input_schema` is defined and can be used in three ways:

lib/mcp/server.rb

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ def initialize(
5959
@server_context = server_context
6060
@configuration = MCP.configuration.merge(configuration)
6161

62-
if @configuration.protocol_version == "2024-11-05" && @instructions
63-
message = "`instructions` supported by protocol version 2025-03-26 or higher"
64-
raise ArgumentError, message
65-
end
62+
validate!
6663

6764
@capabilities = capabilities || default_capabilities
6865

@@ -102,6 +99,8 @@ def handle_json(request)
10299
def define_tool(name: nil, title: nil, description: nil, input_schema: nil, annotations: nil, &block)
103100
tool = Tool.define(name:, title:, description:, input_schema:, annotations:, &block)
104101
@tools[tool.name_value] = tool
102+
103+
validate!
105104
end
106105

107106
def define_prompt(name: nil, title: nil, description: nil, arguments: [], &block)
@@ -171,6 +170,25 @@ def prompts_get_handler(&block)
171170

172171
private
173172

173+
def validate!
174+
if @configuration.protocol_version == "2024-11-05"
175+
if @instructions
176+
message = "`instructions` supported by protocol version 2025-03-26 or higher"
177+
raise ArgumentError, message
178+
end
179+
180+
error_tool_names = @tools.each_with_object([]) do |(tool_name, tool), error_tool_names|
181+
if tool.annotations
182+
error_tool_names << tool_name
183+
end
184+
end
185+
unless error_tool_names.empty?
186+
message = "Error occurred in #{error_tool_names.join(", ")}. `annotations` are supported by protocol version 2025-03-26 or higher"
187+
raise ArgumentError, message
188+
end
189+
end
190+
end
191+
174192
def handle_request(request, method)
175193
handler = @handlers[method]
176194
unless handler

test/mcp/server_test.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,28 @@ def call(message:, server_context: nil)
822822
assert_equal("`instructions` supported by protocol version 2025-03-26 or higher", exception.message)
823823
end
824824

825+
test "server uses annotations when configured with protocol version 2025-03-26" do
826+
configuration = Configuration.new(protocol_version: "2025-03-26")
827+
server = Server.new(name: "test_server", configuration: configuration)
828+
server.define_tool(
829+
name: "defined_tool",
830+
annotations: { title: "test server" },
831+
)
832+
assert_equal({ destructiveHint: true, idempotentHint: false, openWorldHint: true, readOnlyHint: false, title: "test server" }, server.tools.first[1].annotations.to_h)
833+
end
834+
835+
test "raises error if annotations are used with protocol version 2024-11-05" do
836+
configuration = Configuration.new(protocol_version: "2024-11-05")
837+
exception = assert_raises(ArgumentError) do
838+
server = Server.new(name: "test_server", configuration: configuration)
839+
server.define_tool(
840+
name: "defined_tool",
841+
annotations: { title: "test server" },
842+
)
843+
end
844+
assert_equal("Error occurred in defined_tool. `annotations` are supported by protocol version 2025-03-26 or higher", exception.message)
845+
end
846+
825847
test "#define_tool adds a tool to the server" do
826848
@server.define_tool(
827849
name: "defined_tool",

0 commit comments

Comments
 (0)