Omit icons from responses when empty or nil
Previously, the `icons` parameter was always included in responses (as an empty array) even when not configured. This differs from the response representation in MCP Ruby SDK 0.4.0. Since `icons` is optional, it should be omitted from responses when unused to reduce unnecessary context window usage. https://modelcontextprotocol.io/specification/2025-11-25/schema#implementation This fix applies to `Tool#to_h`, `Prompt#to_h`, `Resource#to_h`, `ResourceTemplate#to_h`, and `Server#server_info`. It doesn't seem critical, but if there are no other issues, it would be good to cut 0.5.1 bugfix release soon.
This commit is contained in:
parent
fd1d7a61ec
commit
bd416c7a5f
5 changed files with 163 additions and 5 deletions
|
|
@ -20,7 +20,7 @@ module MCP
|
|||
name: name_value,
|
||||
title: title_value,
|
||||
description: description_value,
|
||||
icons: icons&.map(&:to_h),
|
||||
icons: icons_value&.then { |icons| icons.empty? ? nil : icons.map(&:to_h) },
|
||||
arguments: arguments_value&.map(&:to_h),
|
||||
_meta: meta_value,
|
||||
}.compact
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ module MCP
|
|||
name: name,
|
||||
title: title,
|
||||
description: description,
|
||||
icons: icons.map(&:to_h),
|
||||
icons: icons&.then { |icons| icons.empty? ? nil : icons.map(&:to_h) },
|
||||
mimeType: mime_type,
|
||||
}.compact
|
||||
end
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ module MCP
|
|||
name: name,
|
||||
title: title,
|
||||
description: description,
|
||||
icons: icons.map(&:to_h),
|
||||
icons: icons&.then { |icons| icons.empty? ? nil : icons.map(&:to_h) },
|
||||
mimeType: mime_type,
|
||||
}.compact
|
||||
end
|
||||
|
|
|
|||
|
|
@ -290,7 +290,7 @@ module MCP
|
|||
def server_info
|
||||
@server_info ||= {
|
||||
description: description,
|
||||
icons: icons,
|
||||
icons: icons&.then { |icons| icons.empty? ? nil : icons.map(&:to_h) },
|
||||
name: name,
|
||||
title: title,
|
||||
version: version,
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ module MCP
|
|||
name: name_value,
|
||||
title: title_value,
|
||||
description: description_value,
|
||||
icons: icons&.map(&:to_h),
|
||||
icons: icons_value&.then { |icons| icons.empty? ? nil : icons.map(&:to_h) },
|
||||
inputSchema: input_schema_value.to_h,
|
||||
outputSchema: @output_schema_value&.to_h,
|
||||
annotations: annotations_value&.to_h,
|
||||
|
|
|
|||
Loading…
Reference in a new issue