add titles to tools, prompts and resources
This commit is contained in:
parent
d1c6a46e1a
commit
8b4085468e
5 changed files with 94 additions and 40 deletions
|
|
@ -6,6 +6,7 @@ module MCP
|
|||
class << self
|
||||
NOT_SET = Object.new
|
||||
|
||||
attr_reader :title_value
|
||||
attr_reader :description_value
|
||||
attr_reader :arguments_value
|
||||
|
||||
|
|
@ -14,12 +15,13 @@ module MCP
|
|||
end
|
||||
|
||||
def to_h
|
||||
{ name: name_value, description: description_value, arguments: arguments_value.map(&:to_h) }.compact
|
||||
{ name: name_value, title: title_value, description: description_value, arguments: arguments_value.map(&:to_h) }.compact
|
||||
end
|
||||
|
||||
def inherited(subclass)
|
||||
super
|
||||
subclass.instance_variable_set(:@name_value, nil)
|
||||
subclass.instance_variable_set(:@title_value, nil)
|
||||
subclass.instance_variable_set(:@description_value, nil)
|
||||
subclass.instance_variable_set(:@arguments_value, nil)
|
||||
end
|
||||
|
|
@ -36,6 +38,14 @@ module MCP
|
|||
@name_value || StringUtils.handle_from_class_name(name)
|
||||
end
|
||||
|
||||
def title(value = NOT_SET)
|
||||
if value == NOT_SET
|
||||
@title_value
|
||||
else
|
||||
@title_value = value
|
||||
end
|
||||
end
|
||||
|
||||
def description(value = NOT_SET)
|
||||
if value == NOT_SET
|
||||
@description_value
|
||||
|
|
@ -52,9 +62,10 @@ module MCP
|
|||
end
|
||||
end
|
||||
|
||||
def define(name: nil, description: nil, arguments: [], &block)
|
||||
def define(name: nil, title: nil, description: nil, arguments: [], &block)
|
||||
Class.new(self) do
|
||||
prompt_name name
|
||||
title title
|
||||
description description
|
||||
arguments arguments
|
||||
define_singleton_method(:template) do |args, server_context: nil|
|
||||
|
|
|
|||
|
|
@ -3,21 +3,23 @@
|
|||
|
||||
module MCP
|
||||
class Resource
|
||||
attr_reader :uri, :name, :description, :mime_type
|
||||
attr_reader :uri, :name, :title, :description, :mime_type
|
||||
|
||||
def initialize(uri:, name:, description: nil, mime_type: nil)
|
||||
def initialize(uri:, name:, title: nil, description: nil, mime_type: nil)
|
||||
@uri = uri
|
||||
@name = name
|
||||
@title = title
|
||||
@description = description
|
||||
@mime_type = mime_type
|
||||
end
|
||||
|
||||
def to_h
|
||||
{
|
||||
uri: @uri,
|
||||
name: @name,
|
||||
description: @description,
|
||||
mimeType: @mime_type,
|
||||
uri: uri,
|
||||
name: name,
|
||||
title: title,
|
||||
description: description,
|
||||
mimeType: mime_type,
|
||||
}.compact
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,21 +3,23 @@
|
|||
|
||||
module MCP
|
||||
class ResourceTemplate
|
||||
attr_reader :uri_template, :name, :description, :mime_type
|
||||
attr_reader :uri_template, :name, :title, :description, :mime_type
|
||||
|
||||
def initialize(uri_template:, name:, description: nil, mime_type: nil)
|
||||
def initialize(uri_template:, name:, title: nil, description: nil, mime_type: nil)
|
||||
@uri_template = uri_template
|
||||
@name = name
|
||||
@title = title
|
||||
@description = description
|
||||
@mime_type = mime_type
|
||||
end
|
||||
|
||||
def to_h
|
||||
{
|
||||
uriTemplate: @uri_template,
|
||||
name: @name,
|
||||
description: @description,
|
||||
mimeType: @mime_type,
|
||||
uriTemplate: uri_template,
|
||||
name: name,
|
||||
title: title,
|
||||
description: description,
|
||||
mimeType: mime_type,
|
||||
}.compact
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -96,13 +96,13 @@ module MCP
|
|||
end
|
||||
end
|
||||
|
||||
def define_tool(name: nil, description: nil, input_schema: nil, annotations: nil, &block)
|
||||
tool = Tool.define(name:, description:, input_schema:, annotations:, &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)
|
||||
@tools[tool.name_value] = tool
|
||||
end
|
||||
|
||||
def define_prompt(name: nil, description: nil, arguments: [], &block)
|
||||
prompt = Prompt.define(name:, description:, arguments:, &block)
|
||||
def define_prompt(name: nil, title: nil, description: nil, arguments: [], &block)
|
||||
prompt = Prompt.define(name:, title:, description:, arguments:, &block)
|
||||
@prompts[prompt.name_value] = prompt
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ module MCP
|
|||
class << self
|
||||
NOT_SET = Object.new
|
||||
|
||||
attr_reader :title_value
|
||||
attr_reader :description_value
|
||||
attr_reader :annotations_value
|
||||
|
||||
|
|
@ -15,6 +16,7 @@ module MCP
|
|||
def to_h
|
||||
result = {
|
||||
name: name_value,
|
||||
title: title_value,
|
||||
description: description_value,
|
||||
inputSchema: input_schema_value.to_h,
|
||||
}
|
||||
|
|
@ -25,6 +27,7 @@ module MCP
|
|||
def inherited(subclass)
|
||||
super
|
||||
subclass.instance_variable_set(:@name_value, nil)
|
||||
subclass.instance_variable_set(:@title_value, nil)
|
||||
subclass.instance_variable_set(:@description_value, nil)
|
||||
subclass.instance_variable_set(:@input_schema_value, nil)
|
||||
subclass.instance_variable_set(:@annotations_value, nil)
|
||||
|
|
@ -46,6 +49,14 @@ module MCP
|
|||
@input_schema_value || InputSchema.new
|
||||
end
|
||||
|
||||
def title(value = NOT_SET)
|
||||
if value == NOT_SET
|
||||
@title_value
|
||||
else
|
||||
@title_value = value
|
||||
end
|
||||
end
|
||||
|
||||
def description(value = NOT_SET)
|
||||
if value == NOT_SET
|
||||
@description_value
|
||||
|
|
@ -74,9 +85,10 @@ module MCP
|
|||
end
|
||||
end
|
||||
|
||||
def define(name: nil, description: nil, input_schema: nil, annotations: nil, &block)
|
||||
def define(name: nil, title: nil, description: nil, input_schema: nil, annotations: nil, &block)
|
||||
Class.new(self) do
|
||||
tool_name name
|
||||
title title
|
||||
description description
|
||||
input_schema input_schema
|
||||
self.annotations(annotations) if annotations
|
||||
|
|
|
|||
Loading…
Reference in a new issue