Merge pull request #310 from koic/add_meta_field_support
Add `_meta` field to resource, content, and result classes
This commit is contained in:
commit
88248fc4c7
6 changed files with 269 additions and 29 deletions
|
|
@ -3,56 +3,60 @@
|
|||
module MCP
|
||||
module Content
|
||||
class Text
|
||||
attr_reader :text, :annotations
|
||||
attr_reader :text, :annotations, :meta
|
||||
|
||||
def initialize(text, annotations: nil)
|
||||
def initialize(text, annotations: nil, meta: nil)
|
||||
@text = text
|
||||
@annotations = annotations
|
||||
@meta = meta
|
||||
end
|
||||
|
||||
def to_h
|
||||
{ text: text, annotations: annotations, type: "text" }.compact
|
||||
{ text: text, annotations: annotations, _meta: meta, type: "text" }.compact
|
||||
end
|
||||
end
|
||||
|
||||
class Image
|
||||
attr_reader :data, :mime_type, :annotations
|
||||
attr_reader :data, :mime_type, :annotations, :meta
|
||||
|
||||
def initialize(data, mime_type, annotations: nil)
|
||||
def initialize(data, mime_type, annotations: nil, meta: nil)
|
||||
@data = data
|
||||
@mime_type = mime_type
|
||||
@annotations = annotations
|
||||
@meta = meta
|
||||
end
|
||||
|
||||
def to_h
|
||||
{ data: data, mimeType: mime_type, annotations: annotations, type: "image" }.compact
|
||||
{ data: data, mimeType: mime_type, annotations: annotations, _meta: meta, type: "image" }.compact
|
||||
end
|
||||
end
|
||||
|
||||
class Audio
|
||||
attr_reader :data, :mime_type, :annotations
|
||||
attr_reader :data, :mime_type, :annotations, :meta
|
||||
|
||||
def initialize(data, mime_type, annotations: nil)
|
||||
def initialize(data, mime_type, annotations: nil, meta: nil)
|
||||
@data = data
|
||||
@mime_type = mime_type
|
||||
@annotations = annotations
|
||||
@meta = meta
|
||||
end
|
||||
|
||||
def to_h
|
||||
{ data: data, mimeType: mime_type, annotations: annotations, type: "audio" }.compact
|
||||
{ data: data, mimeType: mime_type, annotations: annotations, _meta: meta, type: "audio" }.compact
|
||||
end
|
||||
end
|
||||
|
||||
class EmbeddedResource
|
||||
attr_reader :resource, :annotations
|
||||
attr_reader :resource, :annotations, :meta
|
||||
|
||||
def initialize(resource, annotations: nil)
|
||||
def initialize(resource, annotations: nil, meta: nil)
|
||||
@resource = resource
|
||||
@annotations = annotations
|
||||
@meta = meta
|
||||
end
|
||||
|
||||
def to_h
|
||||
{ resource: resource.to_h, annotations: annotations, type: "resource" }.compact
|
||||
{ resource: resource.to_h, annotations: annotations, _meta: meta, type: "resource" }.compact
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,15 +3,16 @@
|
|||
module MCP
|
||||
class Prompt
|
||||
class Result
|
||||
attr_reader :description, :messages
|
||||
attr_reader :description, :messages, :meta
|
||||
|
||||
def initialize(description: nil, messages: [])
|
||||
def initialize(description: nil, messages: [], meta: nil)
|
||||
@description = description
|
||||
@messages = messages
|
||||
@meta = meta
|
||||
end
|
||||
|
||||
def to_h
|
||||
{ description: description, messages: messages.map(&:to_h) }.compact
|
||||
{ description: description, messages: messages.map(&:to_h), _meta: meta }.compact
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,15 +5,16 @@ require_relative "resource/embedded"
|
|||
|
||||
module MCP
|
||||
class Resource
|
||||
attr_reader :uri, :name, :title, :description, :icons, :mime_type
|
||||
attr_reader :uri, :name, :title, :description, :icons, :mime_type, :meta
|
||||
|
||||
def initialize(uri:, name:, title: nil, description: nil, icons: [], mime_type: nil)
|
||||
def initialize(uri:, name:, title: nil, description: nil, icons: [], mime_type: nil, meta: nil)
|
||||
@uri = uri
|
||||
@name = name
|
||||
@title = title
|
||||
@description = description
|
||||
@icons = icons
|
||||
@mime_type = mime_type
|
||||
@meta = meta
|
||||
end
|
||||
|
||||
def to_h
|
||||
|
|
@ -24,6 +25,7 @@ module MCP
|
|||
description: description,
|
||||
icons: icons&.then { |icons| icons.empty? ? nil : icons.map(&:to_h) },
|
||||
mimeType: mime_type,
|
||||
_meta: meta,
|
||||
}.compact
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,23 +3,24 @@
|
|||
module MCP
|
||||
class Resource
|
||||
class Contents
|
||||
attr_reader :uri, :mime_type
|
||||
attr_reader :uri, :mime_type, :meta
|
||||
|
||||
def initialize(uri:, mime_type: nil)
|
||||
def initialize(uri:, mime_type: nil, meta: nil)
|
||||
@uri = uri
|
||||
@mime_type = mime_type
|
||||
@meta = meta
|
||||
end
|
||||
|
||||
def to_h
|
||||
{ uri: uri, mimeType: mime_type }.compact
|
||||
{ uri: uri, mimeType: mime_type, _meta: meta }.compact
|
||||
end
|
||||
end
|
||||
|
||||
class TextContents < Contents
|
||||
attr_reader :text
|
||||
|
||||
def initialize(text:, uri:, mime_type:)
|
||||
super(uri: uri, mime_type: mime_type)
|
||||
def initialize(text:, uri:, mime_type:, meta: nil)
|
||||
super(uri: uri, mime_type: mime_type, meta: meta)
|
||||
@text = text
|
||||
end
|
||||
|
||||
|
|
@ -31,8 +32,8 @@ module MCP
|
|||
class BlobContents < Contents
|
||||
attr_reader :data
|
||||
|
||||
def initialize(data:, uri:, mime_type:)
|
||||
super(uri: uri, mime_type: mime_type)
|
||||
def initialize(data:, uri:, mime_type:, meta: nil)
|
||||
super(uri: uri, mime_type: mime_type, meta: meta)
|
||||
@data = data
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -2,15 +2,16 @@
|
|||
|
||||
module MCP
|
||||
class ResourceTemplate
|
||||
attr_reader :uri_template, :name, :title, :description, :icons, :mime_type
|
||||
attr_reader :uri_template, :name, :title, :description, :icons, :mime_type, :meta
|
||||
|
||||
def initialize(uri_template:, name:, title: nil, description: nil, icons: [], mime_type: nil)
|
||||
def initialize(uri_template:, name:, title: nil, description: nil, icons: [], mime_type: nil, meta: nil)
|
||||
@uri_template = uri_template
|
||||
@name = name
|
||||
@title = title
|
||||
@description = description
|
||||
@icons = icons
|
||||
@mime_type = mime_type
|
||||
@meta = meta
|
||||
end
|
||||
|
||||
def to_h
|
||||
|
|
@ -21,6 +22,7 @@ module MCP
|
|||
description: description,
|
||||
icons: icons&.then { |icons| icons.empty? ? nil : icons.map(&:to_h) },
|
||||
mimeType: mime_type,
|
||||
_meta: meta,
|
||||
}.compact
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ module MCP
|
|||
class Response
|
||||
NOT_GIVEN = Object.new.freeze
|
||||
|
||||
attr_reader :content, :structured_content
|
||||
attr_reader :content, :structured_content, :meta
|
||||
|
||||
def initialize(content = nil, deprecated_error = NOT_GIVEN, error: false, structured_content: nil)
|
||||
def initialize(content = nil, deprecated_error = NOT_GIVEN, error: false, structured_content: nil, meta: nil)
|
||||
if deprecated_error != NOT_GIVEN
|
||||
warn("Passing `error` with the 2nd argument of `Response.new` is deprecated. Use keyword argument like `Response.new(content, error: error)` instead.", uplevel: 1)
|
||||
error = deprecated_error
|
||||
|
|
@ -16,6 +16,7 @@ module MCP
|
|||
@content = content || []
|
||||
@error = error
|
||||
@structured_content = structured_content
|
||||
@meta = meta
|
||||
end
|
||||
|
||||
def error?
|
||||
|
|
@ -23,7 +24,7 @@ module MCP
|
|||
end
|
||||
|
||||
def to_h
|
||||
{ content: content, isError: error?, structuredContent: @structured_content }.compact
|
||||
{ content: content, isError: error?, structuredContent: @structured_content, _meta: meta }.compact
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue