Internal Release 0.7.0
- add support for resource templates - improve capability negotiation on handlers - clean up readme - reduce default protocol version to "2024-11-05" - address spec compliance of resources - add debug gem to development - alias ModelContextProtocol to MCP - move prompt subclasses to subdir - improve tool and prompt definition - improve passing of server context to tools - improve tool input schema validation
This commit is contained in:
parent
62184957e0
commit
baeb99ffbc
3 changed files with 842 additions and 253 deletions
27
lib/model_context_protocol/tool/annotations.rb
Normal file
27
lib/model_context_protocol/tool/annotations.rb
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ModelContextProtocol
|
||||
class Tool
|
||||
class Annotations
|
||||
attr_reader :title, :read_only_hint, :destructive_hint, :idempotent_hint, :open_world_hint
|
||||
|
||||
def initialize(title: nil, read_only_hint: nil, destructive_hint: nil, idempotent_hint: nil, open_world_hint: nil)
|
||||
@title = title
|
||||
@read_only_hint = read_only_hint
|
||||
@destructive_hint = destructive_hint
|
||||
@idempotent_hint = idempotent_hint
|
||||
@open_world_hint = open_world_hint
|
||||
end
|
||||
|
||||
def to_h
|
||||
{
|
||||
title:,
|
||||
readOnlyHint: read_only_hint,
|
||||
destructiveHint: destructive_hint,
|
||||
idempotentHint: idempotent_hint,
|
||||
openWorldHint: open_world_hint,
|
||||
}.compact
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
26
lib/model_context_protocol/tool/input_schema.rb
Normal file
26
lib/model_context_protocol/tool/input_schema.rb
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ModelContextProtocol
|
||||
class Tool
|
||||
class InputSchema
|
||||
attr_reader :properties, :required
|
||||
|
||||
def initialize(properties: {}, required: [])
|
||||
@properties = properties
|
||||
@required = required.map(&:to_sym)
|
||||
end
|
||||
|
||||
def to_h
|
||||
{ type: "object", properties:, required: }
|
||||
end
|
||||
|
||||
def missing_required_arguments?(arguments)
|
||||
missing_required_arguments(arguments).any?
|
||||
end
|
||||
|
||||
def missing_required_arguments(arguments)
|
||||
(required - arguments.keys.map(&:to_sym))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
18
lib/model_context_protocol/tool/response.rb
Normal file
18
lib/model_context_protocol/tool/response.rb
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ModelContextProtocol
|
||||
class Tool
|
||||
class Response
|
||||
attr_reader :content, :is_error
|
||||
|
||||
def initialize(content, is_error = false)
|
||||
@content = content
|
||||
@is_error = is_error
|
||||
end
|
||||
|
||||
def to_h
|
||||
{ content:, isError: is_error }.compact
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue