mcp 0.12.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +467 -131
- data/lib/json_rpc_handler.rb +16 -9
- data/lib/mcp/client/http.rb +133 -14
- data/lib/mcp/client/paginated_result.rb +13 -0
- data/lib/mcp/client.rb +195 -22
- data/lib/mcp/configuration.rb +38 -2
- data/lib/mcp/content.rb +16 -12
- data/lib/mcp/instrumentation.rb +23 -2
- data/lib/mcp/methods.rb +4 -5
- data/lib/mcp/prompt/result.rb +4 -3
- data/lib/mcp/resource/contents.rb +8 -7
- data/lib/mcp/resource.rb +4 -2
- data/lib/mcp/resource_template.rb +4 -2
- data/lib/mcp/server/pagination.rb +42 -0
- data/lib/mcp/server/transports/streamable_http_transport.rb +35 -8
- data/lib/mcp/server.rb +82 -60
- data/lib/mcp/server_context.rb +54 -0
- data/lib/mcp/server_session.rb +45 -0
- data/lib/mcp/tool/response.rb +4 -3
- data/lib/mcp/version.rb +1 -1
- metadata +6 -4
data/lib/mcp/server_context.rb
CHANGED
|
@@ -30,6 +30,24 @@ module MCP
|
|
|
30
30
|
@notification_target.notify_log_message(data: data, level: level, logger: logger, related_request_id: @related_request_id)
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
# Sends a resource updated notification scoped to the originating session.
|
|
34
|
+
#
|
|
35
|
+
# @param uri [String] The URI of the updated resource.
|
|
36
|
+
def notify_resources_updated(uri:)
|
|
37
|
+
return unless @notification_target
|
|
38
|
+
|
|
39
|
+
@notification_target.notify_resources_updated(uri: uri)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Delegates to the session so the request is scoped to the originating client.
|
|
43
|
+
def list_roots
|
|
44
|
+
if @notification_target.respond_to?(:list_roots)
|
|
45
|
+
@notification_target.list_roots(related_request_id: @related_request_id)
|
|
46
|
+
else
|
|
47
|
+
raise NoMethodError, "undefined method 'list_roots' for #{self}"
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
33
51
|
# Delegates to the session so the request is scoped to the originating client.
|
|
34
52
|
# Falls back to `@context` (via `method_missing`) when `@notification_target`
|
|
35
53
|
# does not support sampling.
|
|
@@ -43,6 +61,42 @@ module MCP
|
|
|
43
61
|
end
|
|
44
62
|
end
|
|
45
63
|
|
|
64
|
+
# Delegates to the session so the request is scoped to the originating client.
|
|
65
|
+
# Falls back to `@context` (via `method_missing`) when `@notification_target`
|
|
66
|
+
# does not support elicitation.
|
|
67
|
+
def create_form_elicitation(**kwargs)
|
|
68
|
+
if @notification_target.respond_to?(:create_form_elicitation)
|
|
69
|
+
@notification_target.create_form_elicitation(**kwargs, related_request_id: @related_request_id)
|
|
70
|
+
elsif @context.respond_to?(:create_form_elicitation)
|
|
71
|
+
@context.create_form_elicitation(**kwargs, related_request_id: @related_request_id)
|
|
72
|
+
else
|
|
73
|
+
raise NoMethodError, "undefined method 'create_form_elicitation' for #{self}"
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Delegates to the session so the request is scoped to the originating client.
|
|
78
|
+
# Falls back to `@context` when `@notification_target` does not support URL mode elicitation.
|
|
79
|
+
def create_url_elicitation(**kwargs)
|
|
80
|
+
if @notification_target.respond_to?(:create_url_elicitation)
|
|
81
|
+
@notification_target.create_url_elicitation(**kwargs, related_request_id: @related_request_id)
|
|
82
|
+
elsif @context.respond_to?(:create_url_elicitation)
|
|
83
|
+
@context.create_url_elicitation(**kwargs, related_request_id: @related_request_id)
|
|
84
|
+
else
|
|
85
|
+
raise NoMethodError, "undefined method 'create_url_elicitation' for #{self}"
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Delegates to the session so the notification is scoped to the originating client.
|
|
90
|
+
def notify_elicitation_complete(**kwargs)
|
|
91
|
+
if @notification_target.respond_to?(:notify_elicitation_complete)
|
|
92
|
+
@notification_target.notify_elicitation_complete(**kwargs)
|
|
93
|
+
elsif @context.respond_to?(:notify_elicitation_complete)
|
|
94
|
+
@context.notify_elicitation_complete(**kwargs)
|
|
95
|
+
else
|
|
96
|
+
raise NoMethodError, "undefined method 'notify_elicitation_complete' for #{self}"
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
46
100
|
def method_missing(name, ...)
|
|
47
101
|
if @context.respond_to?(name)
|
|
48
102
|
@context.public_send(name, ...)
|
data/lib/mcp/server_session.rb
CHANGED
|
@@ -41,12 +41,57 @@ module MCP
|
|
|
41
41
|
@client_capabilities || @server.client_capabilities
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
+
# Sends a `roots/list` request scoped to this session.
|
|
45
|
+
def list_roots(related_request_id: nil)
|
|
46
|
+
unless client_capabilities&.dig(:roots)
|
|
47
|
+
raise "Client does not support roots."
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
send_to_transport_request(Methods::ROOTS_LIST, nil, related_request_id: related_request_id)
|
|
51
|
+
end
|
|
52
|
+
|
|
44
53
|
# Sends a `sampling/createMessage` request scoped to this session.
|
|
45
54
|
def create_sampling_message(related_request_id: nil, **kwargs)
|
|
46
55
|
params = @server.build_sampling_params(client_capabilities, **kwargs)
|
|
47
56
|
send_to_transport_request(Methods::SAMPLING_CREATE_MESSAGE, params, related_request_id: related_request_id)
|
|
48
57
|
end
|
|
49
58
|
|
|
59
|
+
# Sends an `elicitation/create` request (form mode) scoped to this session.
|
|
60
|
+
def create_form_elicitation(message:, requested_schema:, related_request_id: nil)
|
|
61
|
+
unless client_capabilities&.dig(:elicitation)
|
|
62
|
+
raise "Client does not support elicitation. " \
|
|
63
|
+
"The client must declare the `elicitation` capability during initialization."
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
params = { mode: "form", message: message, requestedSchema: requested_schema }
|
|
67
|
+
send_to_transport_request(Methods::ELICITATION_CREATE, params, related_request_id: related_request_id)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Sends an `elicitation/create` request (URL mode) scoped to this session.
|
|
71
|
+
def create_url_elicitation(message:, url:, elicitation_id:, related_request_id: nil)
|
|
72
|
+
unless client_capabilities&.dig(:elicitation, :url)
|
|
73
|
+
raise "Client does not support URL mode elicitation. " \
|
|
74
|
+
"The client must declare the `elicitation.url` capability during initialization."
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
params = { mode: "url", message: message, url: url, elicitationId: elicitation_id }
|
|
78
|
+
send_to_transport_request(Methods::ELICITATION_CREATE, params, related_request_id: related_request_id)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Sends an elicitation complete notification scoped to this session.
|
|
82
|
+
def notify_elicitation_complete(elicitation_id:)
|
|
83
|
+
send_to_transport(Methods::NOTIFICATIONS_ELICITATION_COMPLETE, { elicitationId: elicitation_id })
|
|
84
|
+
rescue => e
|
|
85
|
+
@server.report_exception(e, notification: "elicitation_complete")
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Sends a resource updated notification to this session only.
|
|
89
|
+
def notify_resources_updated(uri:)
|
|
90
|
+
send_to_transport(Methods::NOTIFICATIONS_RESOURCES_UPDATED, { "uri" => uri })
|
|
91
|
+
rescue => e
|
|
92
|
+
@server.report_exception(e, notification: "resources_updated")
|
|
93
|
+
end
|
|
94
|
+
|
|
50
95
|
# Sends a progress notification to this session only.
|
|
51
96
|
def notify_progress(progress_token:, progress:, total: nil, message: nil, related_request_id: nil)
|
|
52
97
|
params = {
|
data/lib/mcp/tool/response.rb
CHANGED
|
@@ -5,9 +5,9 @@ module MCP
|
|
|
5
5
|
class Response
|
|
6
6
|
NOT_GIVEN = Object.new.freeze
|
|
7
7
|
|
|
8
|
-
attr_reader :content, :structured_content
|
|
8
|
+
attr_reader :content, :structured_content, :meta
|
|
9
9
|
|
|
10
|
-
def initialize(content = nil, deprecated_error = NOT_GIVEN, error: false, structured_content: nil)
|
|
10
|
+
def initialize(content = nil, deprecated_error = NOT_GIVEN, error: false, structured_content: nil, meta: nil)
|
|
11
11
|
if deprecated_error != NOT_GIVEN
|
|
12
12
|
warn("Passing `error` with the 2nd argument of `Response.new` is deprecated. Use keyword argument like `Response.new(content, error: error)` instead.", uplevel: 1)
|
|
13
13
|
error = deprecated_error
|
|
@@ -16,6 +16,7 @@ module MCP
|
|
|
16
16
|
@content = content || []
|
|
17
17
|
@error = error
|
|
18
18
|
@structured_content = structured_content
|
|
19
|
+
@meta = meta
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
def error?
|
|
@@ -23,7 +24,7 @@ module MCP
|
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
def to_h
|
|
26
|
-
{ content: content, isError: error?, structuredContent: @structured_content }.compact
|
|
27
|
+
{ content: content, isError: error?, structuredContent: @structured_content, _meta: meta }.compact
|
|
27
28
|
end
|
|
28
29
|
end
|
|
29
30
|
end
|
data/lib/mcp/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mcp
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.14.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Model Context Protocol
|
|
@@ -39,6 +39,7 @@ files:
|
|
|
39
39
|
- lib/mcp/annotations.rb
|
|
40
40
|
- lib/mcp/client.rb
|
|
41
41
|
- lib/mcp/client/http.rb
|
|
42
|
+
- lib/mcp/client/paginated_result.rb
|
|
42
43
|
- lib/mcp/client/stdio.rb
|
|
43
44
|
- lib/mcp/client/tool.rb
|
|
44
45
|
- lib/mcp/configuration.rb
|
|
@@ -58,6 +59,7 @@ files:
|
|
|
58
59
|
- lib/mcp/resource_template.rb
|
|
59
60
|
- lib/mcp/server.rb
|
|
60
61
|
- lib/mcp/server/capabilities.rb
|
|
62
|
+
- lib/mcp/server/pagination.rb
|
|
61
63
|
- lib/mcp/server/transports.rb
|
|
62
64
|
- lib/mcp/server/transports/stdio_transport.rb
|
|
63
65
|
- lib/mcp/server/transports/streamable_http_transport.rb
|
|
@@ -73,13 +75,13 @@ files:
|
|
|
73
75
|
- lib/mcp/transport.rb
|
|
74
76
|
- lib/mcp/transports/stdio.rb
|
|
75
77
|
- lib/mcp/version.rb
|
|
76
|
-
homepage: https://
|
|
78
|
+
homepage: https://ruby.sdk.modelcontextprotocol.io
|
|
77
79
|
licenses:
|
|
78
80
|
- Apache-2.0
|
|
79
81
|
metadata:
|
|
80
82
|
allowed_push_host: https://rubygems.org
|
|
81
|
-
changelog_uri: https://github.com/modelcontextprotocol/ruby-sdk/releases/tag/v0.
|
|
82
|
-
homepage_uri: https://
|
|
83
|
+
changelog_uri: https://github.com/modelcontextprotocol/ruby-sdk/releases/tag/v0.14.0
|
|
84
|
+
homepage_uri: https://ruby.sdk.modelcontextprotocol.io
|
|
83
85
|
source_code_uri: https://github.com/modelcontextprotocol/ruby-sdk
|
|
84
86
|
bug_tracker_uri: https://github.com/modelcontextprotocol/ruby-sdk/issues
|
|
85
87
|
documentation_uri: https://rubydoc.info/gems/mcp
|