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
1 changed files with 842 additions and 253 deletions
|
|
@ -2,13 +2,85 @@
|
|||
|
||||
module ModelContextProtocol
|
||||
module Methods
|
||||
RESOURCES_LIST = "resources/list"
|
||||
RESOURCES_READ = "resources/read"
|
||||
TOOLS_LIST = "tools/list"
|
||||
TOOLS_CALL = "tools/call"
|
||||
PROMPTS_LIST = "prompts/list"
|
||||
PROMPTS_GET = "prompts/get"
|
||||
INITIALIZE = "initialize"
|
||||
PING = "ping"
|
||||
LOGGING_SET_LEVEL = "logging/setLevel"
|
||||
|
||||
PROMPTS_GET = "prompts/get"
|
||||
PROMPTS_LIST = "prompts/list"
|
||||
COMPLETION_COMPLETE = "completion/complete"
|
||||
|
||||
RESOURCES_LIST = "resources/list"
|
||||
RESOURCES_READ = "resources/read"
|
||||
RESOURCES_TEMPLATES_LIST = "resources/templates/list"
|
||||
RESOURCES_SUBSCRIBE = "resources/subscribe"
|
||||
RESOURCES_UNSUBSCRIBE = "resources/unsubscribe"
|
||||
|
||||
TOOLS_CALL = "tools/call"
|
||||
TOOLS_LIST = "tools/list"
|
||||
|
||||
SAMPLING_CREATE_MESSAGE = "sampling/createMessage"
|
||||
|
||||
class MissingRequiredCapabilityError < StandardError
|
||||
attr_reader :method
|
||||
attr_reader :capability
|
||||
|
||||
def initialize(method, capability)
|
||||
super("Server does not support #{capability} (required for #{method})")
|
||||
@method = method
|
||||
@capability = capability
|
||||
end
|
||||
end
|
||||
|
||||
extend self
|
||||
|
||||
ALL_METHODS = [
|
||||
SAMPLING_CREATE_MESSAGE,
|
||||
INITIALIZE,
|
||||
LOGGING_SET_LEVEL,
|
||||
PING,
|
||||
PROMPTS_GET,
|
||||
PROMPTS_LIST,
|
||||
COMPLETION_COMPLETE,
|
||||
RESOURCES_LIST,
|
||||
RESOURCES_READ,
|
||||
RESOURCES_TEMPLATES_LIST,
|
||||
RESOURCES_SUBSCRIBE,
|
||||
RESOURCES_UNSUBSCRIBE,
|
||||
TOOLS_CALL,
|
||||
TOOLS_LIST,
|
||||
]
|
||||
|
||||
def ensure_capability!(method, capabilities)
|
||||
case method
|
||||
when PROMPTS_GET, PROMPTS_LIST, COMPLETION_COMPLETE
|
||||
unless capabilities[:prompts]
|
||||
raise MissingRequiredCapabilityError.new(method, :prompts)
|
||||
end
|
||||
when RESOURCES_LIST, RESOURCES_TEMPLATES_LIST, RESOURCES_READ, RESOURCES_SUBSCRIBE, RESOURCES_UNSUBSCRIBE
|
||||
unless capabilities[:resources]
|
||||
raise MissingRequiredCapabilityError.new(method, :resources)
|
||||
end
|
||||
|
||||
if method == RESOURCES_SUBSCRIBE && !capabilities[:resources][:subscribe]
|
||||
raise MissingRequiredCapabilityError.new(method, :resources_subscribe)
|
||||
end
|
||||
when TOOLS_CALL, TOOLS_LIST
|
||||
unless capabilities[:tools]
|
||||
raise MissingRequiredCapabilityError.new(method, :tools)
|
||||
end
|
||||
when SAMPLING_CREATE_MESSAGE
|
||||
unless capabilities[:sampling]
|
||||
raise MissingRequiredCapabilityError.new(method, :sampling)
|
||||
end
|
||||
when LOGGING_SET_LEVEL
|
||||
# Logging is unsupported by the Server
|
||||
unless capabilities[:logging]
|
||||
raise MissingRequiredCapabilityError.new(method, :logging)
|
||||
end
|
||||
when INITIALIZE, PING
|
||||
# No specific capability required for initialize or ping
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue