Module: ActionMCP::Client::Resources

Included in:
Base
Defined in:
lib/action_mcp/client/resources.rb

Instance Method Summary collapse

Instance Method Details

#list_resource_templates(params = {}) ⇒ String

List resource templates from the server

Parameters:

  • params (Hash) (defaults to: {})

    Optional parameters for pagination

Options Hash (params):

  • :cursor (String)

    Pagination cursor for fetching next page

  • :limit (Integer)

    Maximum number of items to return

Returns:

  • (String)

    Request ID for tracking the request



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/action_mcp/client/resources.rb', line 32

def list_resource_templates(params = {})
  request_id = SecureRandom.uuid_v7

  # Send request with pagination parameters if provided
  request_params = {}
  request_params[:cursor] = params[:cursor] if params[:cursor]
  request_params[:limit] = params[:limit] if params[:limit]

  send_jsonrpc_request("resources/templates/list",
                       params: request_params.empty? ? nil : request_params,
                       id: request_id)

  # Return request ID for tracking the request
  request_id
end

#list_resources(params = {}) ⇒ String

List all available resources from the server

Parameters:

  • params (Hash) (defaults to: {})

    Optional parameters for pagination

Options Hash (params):

  • :cursor (String)

    Pagination cursor for fetching next page

  • :limit (Integer)

    Maximum number of items to return

Returns:

  • (String)

    Request ID for tracking the request



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/action_mcp/client/resources.rb', line 11

def list_resources(params = {})
  request_id = SecureRandom.uuid_v7

  # Send request with pagination parameters if provided
  request_params = {}
  request_params[:cursor] = params[:cursor] if params[:cursor]
  request_params[:limit] = params[:limit] if params[:limit]

  send_jsonrpc_request("resources/list",
                       params: request_params.empty? ? nil : request_params,
                       id: request_id)

  # Return request ID for tracking the request
  request_id
end

#read_resource(uri) ⇒ String

Read a specific resource

Parameters:

  • uri (String)

    URI of the resource to read

Returns:

  • (String)

    Request ID for tracking the request



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/action_mcp/client/resources.rb', line 51

def read_resource(uri)
  request_id = SecureRandom.uuid_v7

  # Send request
  send_jsonrpc_request("resources/read",
                       params: { uri: uri },
                       id: request_id)

  # Return request ID for tracking the request
  request_id
end

#subscribe_resource(uri, update_callback) ⇒ String

Subscribe to updates for a specific resource

Parameters:

  • uri (String)

    URI of the resource to subscribe to

  • update_callback (Proc)

    Callback for resource updates

Returns:

  • (String)

    Request ID for tracking the request



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/action_mcp/client/resources.rb', line 67

def subscribe_resource(uri, update_callback)
  @resource_subscriptions ||= {}
  @resource_subscriptions[uri] = update_callback

  request_id = SecureRandom.uuid_v7

  # Send request
  send_jsonrpc_request("resources/subscribe",
                       params: { uri: uri },
                       id: request_id)

  # Return request ID for tracking the request
  request_id
end

#unsubscribe_resource(uri) ⇒ String

Unsubscribe from updates for a specific resource

Parameters:

  • uri (String)

    URI of the resource to unsubscribe from

Returns:

  • (String)

    Request ID for tracking the request



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/action_mcp/client/resources.rb', line 85

def unsubscribe_resource(uri)
  @resource_subscriptions&.delete(uri)

  request_id = SecureRandom.uuid_v7

  # Send request
  send_jsonrpc_request("resources/unsubscribe",
                       params: { uri: uri },
                       id: request_id)

  # Return request ID for tracking the request
  request_id
end