Merge branch 'main' into main
This commit is contained in:
commit
cd4681351d
3 changed files with 49 additions and 6 deletions
|
|
@ -124,8 +124,8 @@ Notifications follow the JSON-RPC 2.0 specification and use these method names:
|
||||||
|
|
||||||
#### Transport Support
|
#### Transport Support
|
||||||
|
|
||||||
- **HTTP Transport**: Notifications are sent as Server-Sent Events (SSE) to all connected sessions
|
- **stdio**: Notifications are sent as JSON-RPC 2.0 messages to stdout
|
||||||
- **Stdio Transport**: Notifications are sent as JSON-RPC 2.0 messages to stdout
|
- **Streamable HTTP**: Notifications are sent as JSON-RPC 2.0 messages over HTTP with streaming (chunked transfer or SSE)
|
||||||
|
|
||||||
#### Usage Example
|
#### Usage Example
|
||||||
|
|
||||||
|
|
@ -456,6 +456,9 @@ Tools can include annotations that provide additional metadata about their behav
|
||||||
|
|
||||||
Annotations can be set either through the class definition using the `annotations` class method or when defining a tool using the `define` method.
|
Annotations can be set either through the class definition using the `annotations` class method or when defining a tool using the `define` method.
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> This **Tool Annotations** feature is supported starting from `protocol_version: '2025-03-26'`.
|
||||||
|
|
||||||
### Tool Output Schemas
|
### Tool Output Schemas
|
||||||
|
|
||||||
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:
|
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:
|
||||||
|
|
|
||||||
|
|
@ -59,10 +59,7 @@ module MCP
|
||||||
@server_context = server_context
|
@server_context = server_context
|
||||||
@configuration = MCP.configuration.merge(configuration)
|
@configuration = MCP.configuration.merge(configuration)
|
||||||
|
|
||||||
if @configuration.protocol_version == "2024-11-05" && @instructions
|
validate!
|
||||||
message = "`instructions` supported by protocol version 2025-03-26 or higher"
|
|
||||||
raise ArgumentError, message
|
|
||||||
end
|
|
||||||
|
|
||||||
@capabilities = capabilities || default_capabilities
|
@capabilities = capabilities || default_capabilities
|
||||||
|
|
||||||
|
|
@ -102,6 +99,8 @@ module MCP
|
||||||
def define_tool(name: nil, title: nil, description: nil, input_schema: nil, annotations: nil, &block)
|
def define_tool(name: nil, title: nil, description: nil, input_schema: nil, annotations: nil, &block)
|
||||||
tool = Tool.define(name:, title:, description:, input_schema:, annotations:, &block)
|
tool = Tool.define(name:, title:, description:, input_schema:, annotations:, &block)
|
||||||
@tools[tool.name_value] = tool
|
@tools[tool.name_value] = tool
|
||||||
|
|
||||||
|
validate!
|
||||||
end
|
end
|
||||||
|
|
||||||
def define_prompt(name: nil, title: nil, description: nil, arguments: [], &block)
|
def define_prompt(name: nil, title: nil, description: nil, arguments: [], &block)
|
||||||
|
|
@ -171,6 +170,25 @@ module MCP
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def validate!
|
||||||
|
if @configuration.protocol_version == "2024-11-05"
|
||||||
|
if @instructions
|
||||||
|
message = "`instructions` supported by protocol version 2025-03-26 or higher"
|
||||||
|
raise ArgumentError, message
|
||||||
|
end
|
||||||
|
|
||||||
|
error_tool_names = @tools.each_with_object([]) do |(tool_name, tool), error_tool_names|
|
||||||
|
if tool.annotations
|
||||||
|
error_tool_names << tool_name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
unless error_tool_names.empty?
|
||||||
|
message = "Error occurred in #{error_tool_names.join(", ")}. `annotations` are supported by protocol version 2025-03-26 or higher"
|
||||||
|
raise ArgumentError, message
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def handle_request(request, method)
|
def handle_request(request, method)
|
||||||
handler = @handlers[method]
|
handler = @handlers[method]
|
||||||
unless handler
|
unless handler
|
||||||
|
|
|
||||||
|
|
@ -822,6 +822,28 @@ module MCP
|
||||||
assert_equal("`instructions` supported by protocol version 2025-03-26 or higher", exception.message)
|
assert_equal("`instructions` supported by protocol version 2025-03-26 or higher", exception.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "server uses annotations when configured with protocol version 2025-03-26" do
|
||||||
|
configuration = Configuration.new(protocol_version: "2025-03-26")
|
||||||
|
server = Server.new(name: "test_server", configuration: configuration)
|
||||||
|
server.define_tool(
|
||||||
|
name: "defined_tool",
|
||||||
|
annotations: { title: "test server" },
|
||||||
|
)
|
||||||
|
assert_equal({ destructiveHint: true, idempotentHint: false, openWorldHint: true, readOnlyHint: false, title: "test server" }, server.tools.first[1].annotations.to_h)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "raises error if annotations are used with protocol version 2024-11-05" do
|
||||||
|
configuration = Configuration.new(protocol_version: "2024-11-05")
|
||||||
|
exception = assert_raises(ArgumentError) do
|
||||||
|
server = Server.new(name: "test_server", configuration: configuration)
|
||||||
|
server.define_tool(
|
||||||
|
name: "defined_tool",
|
||||||
|
annotations: { title: "test server" },
|
||||||
|
)
|
||||||
|
end
|
||||||
|
assert_equal("Error occurred in defined_tool. `annotations` are supported by protocol version 2025-03-26 or higher", exception.message)
|
||||||
|
end
|
||||||
|
|
||||||
test "#define_tool adds a tool to the server" do
|
test "#define_tool adds a tool to the server" do
|
||||||
@server.define_tool(
|
@server.define_tool(
|
||||||
name: "defined_tool",
|
name: "defined_tool",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue