context_drop 0.1.3 → 0.2.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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +218 -49
  3. data/SPEC.md +74 -26
  4. data/app/assets/javascripts/context_drop/context_drop.js +5227 -652
  5. data/app/controllers/context_drop/agent_controller.rb +170 -0
  6. data/app/controllers/context_drop/configs_controller.rb +2 -1
  7. data/app/controllers/context_drop/dashboard/feedbacks_controller.rb +62 -2
  8. data/app/controllers/context_drop/feedbacks_controller.rb +13 -3
  9. data/app/controllers/context_drop/mcp_controller.rb +2 -1
  10. data/app/helpers/context_drop/dashboard_helper.rb +52 -0
  11. data/app/helpers/context_drop/widget_helper.rb +11 -1
  12. data/app/javascript/context_drop/__tests__/widget.test.ts +731 -92
  13. data/app/javascript/context_drop/api-client.ts +130 -11
  14. data/app/javascript/context_drop/element-picker.ts +247 -30
  15. data/app/javascript/context_drop/icons.ts +24 -0
  16. data/app/javascript/context_drop/markdown.ts +146 -0
  17. data/app/javascript/context_drop/sanitizer.ts +413 -2
  18. data/app/javascript/context_drop/screenshot.ts +102 -8
  19. data/app/javascript/context_drop/styles.ts +1528 -252
  20. data/app/javascript/context_drop/types.ts +147 -0
  21. data/app/javascript/context_drop/widget.ts +2629 -288
  22. data/app/models/context_drop/feedback.rb +34 -5
  23. data/app/views/context_drop/dashboard/feedbacks/index.html.erb +166 -60
  24. data/app/views/context_drop/dashboard/feedbacks/show.html.erb +178 -47
  25. data/app/views/layouts/context_drop/application.html.erb +416 -70
  26. data/config/routes.rb +11 -0
  27. data/db/migrate/20261112000004_add_environment_to_context_drop_feedbacks.rb +10 -0
  28. data/lib/context_drop/agent/key_store.rb +290 -0
  29. data/lib/context_drop/agent/llm_client.rb +413 -0
  30. data/lib/context_drop/agent/orchestrator.rb +314 -0
  31. data/lib/context_drop/agent/workspace_sandbox.rb +499 -0
  32. data/lib/context_drop/configuration.rb +216 -3
  33. data/lib/context_drop/mcp/dispatcher.rb +71 -29
  34. data/lib/context_drop/mcp/environment_router.rb +115 -0
  35. data/lib/context_drop/mcp/prompts/investigate_feedback.rb +87 -8
  36. data/lib/context_drop/mcp/remote_client.rb +120 -0
  37. data/lib/context_drop/mcp/server.rb +9 -2
  38. data/lib/context_drop/mcp/tools/get_feedback.rb +50 -4
  39. data/lib/context_drop/mcp/tools/get_feedback_attachment.rb +26 -4
  40. data/lib/context_drop/mcp/tools/list_environments.rb +60 -0
  41. data/lib/context_drop/mcp/tools/list_feedbacks.rb +174 -22
  42. data/lib/context_drop/mcp/tools/update_feedback_status.rb +45 -4
  43. data/lib/context_drop/version.rb +1 -1
  44. data/lib/context_drop.rb +8 -2
  45. data/lib/generators/context_drop/install/templates/initializer.rb.tt +29 -2
  46. metadata +13 -2
@@ -6,26 +6,43 @@ module ContextDrop
6
6
  class InvestigateFeedback
7
7
  DEFINITION = {
8
8
  name: "investigate_feedback",
9
- description: "Generate a structured investigation brief for a ContextDrop feedback record, including its originating URL, DOM element selectors/paths, and visual screenshots.",
9
+ description: "Generate a structured investigation brief for a ContextDrop feedback record (local or remote), including its originating environment, URL, DOM element selectors/paths, and visual screenshots.",
10
10
  arguments: [
11
11
  {
12
12
  name: "feedback_id",
13
- description: "ID of the ContextDrop::Feedback record to investigate.",
13
+ description: "ID of the ContextDrop::Feedback record to investigate, or '<environment>:<id>' (e.g. 'staging:42').",
14
14
  required: true
15
+ },
16
+ {
17
+ name: "environment",
18
+ description: "Optional environment name ('local', 'staging', 'production', etc.).",
19
+ required: false
15
20
  }
16
21
  ]
17
22
  }.freeze
18
23
 
19
24
  def self.call(args = {})
20
25
  params = args.is_a?(Hash) ? args.transform_keys(&:to_s) : {}
21
- feedback_id = params["feedback_id"] || params["id"]
22
- raise ContextDrop::Error, "Missing required argument: feedback_id" if feedback_id.nil? || feedback_id.to_s.strip.empty?
26
+ raw_id = params["feedback_id"] || params["id"]
27
+ raise ContextDrop::Error, "Missing required argument: feedback_id" if raw_id.nil? || raw_id.to_s.strip.empty?
28
+
29
+ target_env, feedback_id = ContextDrop::MCP::EnvironmentRouter.parse_target(raw_id, params["environment"])
30
+
31
+ unless ContextDrop::MCP::EnvironmentRouter.local_target?(target_env)
32
+ remote_cfg = ContextDrop::MCP::EnvironmentRouter.remote_config_for(target_env)
33
+ raise ContextDrop::Error, "Unknown remote environment '#{target_env}'" unless remote_cfg
34
+
35
+ return build_remote_prompt(target_env, remote_cfg, feedback_id)
36
+ end
23
37
 
24
38
  feedback = ContextDrop::Feedback
25
39
  .includes(:submitter, :element_references, :attachments)
26
40
  .find_by(id: feedback_id)
27
41
  raise ContextDrop::Error, "Feedback ##{feedback_id} not found" unless feedback
28
42
 
43
+ env_name = ContextDrop::MCP::EnvironmentRouter.record_environment(feedback)
44
+ qualified = ContextDrop::MCP::EnvironmentRouter.qualify_id(env_name, feedback.id)
45
+
29
46
  element_lines = if feedback.element_references.any?
30
47
  feedback.element_references.map.with_index(1) do |el, idx|
31
48
  <<~EL.strip
@@ -41,9 +58,10 @@ module ContextDrop
41
58
  end
42
59
 
43
60
  instructions = <<~PROMPT
44
- Investigate and resolve ContextDrop Feedback ##{feedback.id} (status: #{feedback.status}).
61
+ Investigate and resolve ContextDrop Feedback ##{feedback.id} (`#{qualified}`, environment: `#{env_name}`, status: #{feedback.status}).
45
62
 
46
63
  ## Reported Feedback
64
+ - **Environment:** `#{env_name}`
47
65
  - **Message:** #{feedback.message.presence || '(No text message provided)'}
48
66
  - **Originating Page URL:** `#{feedback.page_url}`
49
67
  - **Submitter:** #{feedback.submitter_label}
@@ -56,8 +74,8 @@ module ContextDrop
56
74
  ## Recommended Investigation Steps
57
75
  1. Locate the Rails route and controller action corresponding to `#{feedback.page_url}` in `config/routes.rb` and `app/controllers/`.
58
76
  2. Search the view templates (`app/views/`, ViewComponents, or frontend components) for the attached DOM selectors (`#{feedback.element_references.map(&:selector).join(', ')}`) and structural DOM paths (`#{feedback.element_references.map(&:dom_path).compact.join(', ')}`).
59
- 3. Inspect any attached screenshots (`get_feedback` with `id: #{feedback.id}`) to verify the visual layout issue.
60
- 4. Propose and verify a fix, then call `update_feedback_status` (`id: #{feedback.id}`, `status: "resolved"`) once complete.
77
+ 3. Inspect any attached screenshots (`get_feedback` with `id: "#{qualified}"`) to verify the visual layout issue.
78
+ 4. Propose and verify a fix, then call `update_feedback_status` (`id: "#{qualified}"`, `status: "resolved"`) once complete.
61
79
  PROMPT
62
80
 
63
81
  message_content = [{ type: "text", text: instructions }]
@@ -68,7 +86,68 @@ module ContextDrop
68
86
  end
69
87
 
70
88
  {
71
- description: "Investigation brief for ContextDrop Feedback ##{feedback.id} on #{feedback.page_url}",
89
+ description: "Investigation brief for ContextDrop Feedback #{qualified} on #{feedback.page_url}",
90
+ messages: [
91
+ {
92
+ role: "user",
93
+ content: message_content.size == 1 ? message_content.first : message_content
94
+ }
95
+ ]
96
+ }
97
+ end
98
+
99
+ def self.build_remote_prompt(env_name, remote_cfg, feedback_id)
100
+ tool_res = ContextDrop::MCP::Tools::GetFeedback.fetch_remote_feedback(env_name, remote_cfg, feedback_id, include_images: true)
101
+ if tool_res[:isError]
102
+ err_text = Array(tool_res[:content]).first&.dig(:text).to_s
103
+ raise ContextDrop::Error, err_text
104
+ end
105
+
106
+ text_block = Array(tool_res[:content]).find { |b| b.is_a?(Hash) && b[:type].to_s == "text" }
107
+ fb = text_block ? JSON.parse(text_block[:text].to_s) : {}
108
+ qualified = ContextDrop::MCP::EnvironmentRouter.qualify_id(env_name, fb["id"] || feedback_id)
109
+
110
+ els = Array(fb["element_references"])
111
+ element_lines = if els.any?
112
+ els.map.with_index(1) do |el, idx|
113
+ <<~EL.strip
114
+ #{idx}. `<#{el['tag_name']}>` — Selector: `#{el['selector']}`
115
+ - DOM Path: `#{el['dom_path'] || 'N/A'}`
116
+ - Visible Text: #{el['text_content'].inspect}
117
+ - Bounding Box: `#{JSON.generate(el['bounding_rect'] || {})}`
118
+ - Attributes: `#{JSON.generate(el['attributes_snapshot'] || {})}`
119
+ EL
120
+ end.join("\n")
121
+ else
122
+ "None selected."
123
+ end
124
+
125
+ instructions = <<~PROMPT
126
+ Investigate and resolve ContextDrop Feedback ##{fb['id'] || feedback_id} (`#{qualified}`, environment: `#{env_name}`, status: #{fb['status']}).
127
+
128
+ ## Reported Feedback
129
+ - **Environment:** `#{env_name}`
130
+ - **Message:** #{fb['message'].presence || '(No text message provided)'}
131
+ - **Originating Page URL:** `#{fb['page_url']}`
132
+ - **Submitter:** #{fb.dig('submitter', 'label') || 'Anonymous'}
133
+ - **Submitted At:** #{fb['created_at']}
134
+ - **Viewport / Metadata:** `#{JSON.generate(fb['metadata'] || {})}`
135
+
136
+ ## Attached DOM Element References
137
+ #{element_lines}
138
+
139
+ ## Recommended Investigation Steps
140
+ 1. Locate the Rails route and controller action corresponding to `#{fb['page_url']}` in `config/routes.rb` and `app/controllers/`.
141
+ 2. Search the view templates (`app/views/`, ViewComponents, or frontend components) for the attached DOM selectors (`#{els.map { |e| e['selector'] }.join(', ')}`).
142
+ 3. Inspect any attached screenshots (`get_feedback` with `id: "#{qualified}"`) to verify the visual layout issue.
143
+ 4. Propose and verify a fix locally, then call `update_feedback_status` (`id: "#{qualified}"`, `status: "resolved"`) once complete.
144
+ PROMPT
145
+
146
+ image_blocks = Array(tool_res[:content]).select { |b| b.is_a?(Hash) && b[:type].to_s == "image" }
147
+ message_content = [{ type: "text", text: instructions }] + image_blocks
148
+
149
+ {
150
+ description: "Investigation brief for ContextDrop Feedback #{qualified} on #{fb['page_url']}",
72
151
  messages: [
73
152
  {
74
153
  role: "user",
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "net/http"
5
+ require "uri"
6
+
7
+ module ContextDrop
8
+ module MCP
9
+ class RemoteClient
10
+ DEFAULT_OPEN_TIMEOUT = 4
11
+ DEFAULT_READ_TIMEOUT = 12
12
+ LOOPBACK_HOSTS = %w[localhost 127.0.0.1 ::1 [::1]].freeze
13
+
14
+ class RemoteError < ContextDrop::Error; end
15
+
16
+ class << self
17
+ # Optional test seam for stubbing remote JSON-RPC calls in unit specs without network sockets
18
+ attr_accessor :transport
19
+
20
+ def call_rpc(env_name, env_config, method, params = {})
21
+ if transport.respond_to?(:call)
22
+ return transport.call(env_name.to_s, env_config, method.to_s, params)
23
+ end
24
+
25
+ url_str = env_config[:url].to_s.strip
26
+ uri = validate_endpoint_uri!(env_name, url_str, allow_insecure_http: !!env_config[:allow_insecure_http])
27
+
28
+ payload = {
29
+ jsonrpc: "2.0",
30
+ id: "fed_#{env_name}_#{Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)}",
31
+ method: method.to_s,
32
+ params: params
33
+ }
34
+
35
+ http = Net::HTTP.new(uri.host, uri.port)
36
+ http.use_ssl = (uri.scheme == "https")
37
+ http.open_timeout = DEFAULT_OPEN_TIMEOUT
38
+ http.read_timeout = DEFAULT_READ_TIMEOUT
39
+
40
+ req = Net::HTTP::Post.new(uri.request_uri)
41
+ req["Content-Type"] = "application/json"
42
+ req["Accept"] = "application/json"
43
+ req["X-Context-Drop-Federated"] = "1"
44
+
45
+ if env_config[:headers].is_a?(Hash)
46
+ env_config[:headers].each do |k, v|
47
+ req[k.to_s] = v.to_s unless k.to_s.strip.empty?
48
+ end
49
+ end
50
+
51
+ api_key = env_config[:api_key].to_s.strip
52
+ req["Authorization"] = "Bearer #{api_key}" unless api_key.empty?
53
+ req.body = JSON.generate(payload)
54
+
55
+ response = http.request(req)
56
+ unless response.code.to_i.between?(200, 299)
57
+ raise RemoteError, "Remote environment '#{env_name}' returned HTTP #{response.code}"
58
+ end
59
+
60
+ parsed = JSON.parse(response.body.to_s)
61
+ if parsed.is_a?(Hash) && parsed["error"].is_a?(Hash)
62
+ raise RemoteError, "Remote environment '#{env_name}' error: #{parsed['error']['message']}"
63
+ end
64
+
65
+ parsed.is_a?(Hash) ? (parsed["result"] || parsed[:result]) : nil
66
+ rescue JSON::ParserError => e
67
+ raise RemoteError, "Invalid JSON from remote environment '#{env_name}': #{e.message}"
68
+ rescue Timeout::Error, SocketError, SystemCallError, IOError, OpenSSL::SSL::SSLError => e
69
+ raise RemoteError, "Failed to reach remote environment '#{env_name}': #{e.class}: #{e.message}"
70
+ end
71
+
72
+ def call_tool(env_name, env_config, tool_name, arguments = {})
73
+ clean_args = arguments.is_a?(Hash) ? arguments.dup : {}
74
+ clean_args.delete("environment")
75
+ clean_args.delete(:environment)
76
+
77
+ result = call_rpc(env_name, env_config, "tools/call", {
78
+ name: tool_name.to_s,
79
+ arguments: clean_args
80
+ })
81
+
82
+ unless result.is_a?(Hash)
83
+ raise RemoteError, "Unexpected tool response from '#{env_name}'"
84
+ end
85
+
86
+ normalize_tool_result(result)
87
+ end
88
+
89
+ def validate_endpoint_uri!(env_name, url_str, allow_insecure_http: false)
90
+ uri = URI.parse(url_str)
91
+ unless %w[http https].include?(uri.scheme) && uri.host && !uri.host.empty?
92
+ raise RemoteError, "Invalid MCP URL for environment '#{env_name}': #{url_str.inspect}"
93
+ end
94
+
95
+ is_loopback = LOOPBACK_HOSTS.include?(uri.host.downcase)
96
+ if uri.scheme == "http" && !is_loopback && !allow_insecure_http
97
+ raise RemoteError, "Insecure HTTP MCP URL refused for remote environment '#{env_name}' (use https:// or set allow_insecure_http: true)"
98
+ end
99
+
100
+ uri
101
+ rescue URI::InvalidURIError => e
102
+ raise RemoteError, "Malformed MCP URL for environment '#{env_name}': #{e.message}"
103
+ end
104
+
105
+ private
106
+
107
+ def normalize_tool_result(raw)
108
+ str_hash = raw.transform_keys(&:to_s)
109
+ raw_content = Array(str_hash["content"]).map do |block|
110
+ block.is_a?(Hash) ? block.transform_keys(&:to_sym) : block
111
+ end
112
+ {
113
+ content: raw_content,
114
+ isError: !!str_hash["isError"]
115
+ }
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "remote_client"
4
+ require_relative "environment_router"
5
+ require_relative "tools/list_environments"
3
6
  require_relative "tools/list_feedbacks"
4
7
  require_relative "tools/get_feedback"
5
8
  require_relative "tools/get_feedback_attachment"
@@ -12,8 +15,12 @@ module ContextDrop
12
15
  module MCP
13
16
  class Server
14
17
  class << self
15
- def handle_http_payload(payload)
16
- Dispatcher.call(payload)
18
+ def handle_http_payload(payload, local_only: true)
19
+ if local_only
20
+ EnvironmentRouter.with_local_only { Dispatcher.call(payload) }
21
+ else
22
+ Dispatcher.call(payload)
23
+ end
17
24
  end
18
25
 
19
26
  def run_stdio(input: $stdin, output: $stdout, error: $stderr)
@@ -8,14 +8,18 @@ module ContextDrop
8
8
 
9
9
  DEFINITION = {
10
10
  name: "get_feedback",
11
- description: "Retrieve a complete ContextDrop feedback record, all DOM ElementReference snapshots, and screenshots/images as multimodal MCP image blocks.",
11
+ description: "Retrieve a complete ContextDrop feedback record, all DOM ElementReference snapshots, and screenshots/images as multimodal MCP image blocks across local or remote environments.",
12
12
  inputSchema: {
13
13
  type: "object",
14
14
  required: ["id"],
15
15
  properties: {
16
16
  id: {
17
17
  type: %w[integer string],
18
- description: "The ID of the ContextDrop::Feedback record."
18
+ description: "The ID of the ContextDrop::Feedback record, or a qualified '<environment>:<id>' string (e.g. 'staging:42')."
19
+ },
20
+ environment: {
21
+ type: "string",
22
+ description: "Optional environment name ('local', 'development', 'staging', 'production', etc.). Defaults to the local host environment unless specified or prefixed on `id`."
19
23
  },
20
24
  include_images: {
21
25
  type: "boolean",
@@ -27,10 +31,20 @@ module ContextDrop
27
31
 
28
32
  def self.call(args = {})
29
33
  params = args.is_a?(Hash) ? args.transform_keys(&:to_s) : {}
30
- feedback_id = params["id"] || params["feedback_id"]
31
- return error_result("Missing required parameter: id") if feedback_id.nil? || feedback_id.to_s.strip.empty?
34
+ raw_id = params["id"] || params["feedback_id"]
35
+ return error_result("Missing required parameter: id") if raw_id.nil? || raw_id.to_s.strip.empty?
32
36
 
33
37
  include_images = params.key?("include_images") ? !!params["include_images"] : true
38
+ target_env, feedback_id = ContextDrop::MCP::EnvironmentRouter.parse_target(raw_id, params["environment"])
39
+
40
+ unless ContextDrop::MCP::EnvironmentRouter.local_target?(target_env)
41
+ remote_cfg = ContextDrop::MCP::EnvironmentRouter.remote_config_for(target_env)
42
+ unless remote_cfg
43
+ return error_result("Unknown remote environment '#{target_env}'")
44
+ end
45
+
46
+ return fetch_remote_feedback(target_env, remote_cfg, feedback_id, include_images: include_images)
47
+ end
34
48
 
35
49
  feedback = ContextDrop::Feedback
36
50
  .includes(:submitter, :element_references, :attachments)
@@ -59,9 +73,40 @@ module ContextDrop
59
73
  }
60
74
  end
61
75
 
76
+ def self.fetch_remote_feedback(env_name, remote_cfg, feedback_id, include_images: true)
77
+ res = ContextDrop::MCP::RemoteClient.call_tool(env_name, remote_cfg, "get_feedback", {
78
+ "id" => feedback_id,
79
+ "include_images" => include_images
80
+ })
81
+ return res if res[:isError]
82
+
83
+ updated_blocks = Array(res[:content]).map do |block|
84
+ if block.is_a?(Hash) && block[:type].to_s == "text"
85
+ begin
86
+ parsed = JSON.parse(block[:text].to_s)
87
+ if parsed.is_a?(Hash)
88
+ parsed["environment"] = env_name
89
+ parsed["qualified_id"] = ContextDrop::MCP::EnvironmentRouter.qualify_id(env_name, parsed["id"] || feedback_id)
90
+ next block.merge(text: JSON.pretty_generate(parsed))
91
+ end
92
+ rescue JSON::ParserError
93
+ # Keep original text block if non-JSON
94
+ end
95
+ end
96
+ block
97
+ end
98
+
99
+ { content: updated_blocks, isError: false }
100
+ rescue ContextDrop::MCP::RemoteClient::RemoteError => e
101
+ error_result(e.message)
102
+ end
103
+
62
104
  def self.serialize_feedback(feedback)
105
+ env_name = ContextDrop::MCP::EnvironmentRouter.record_environment(feedback)
63
106
  {
64
107
  id: feedback.id,
108
+ qualified_id: ContextDrop::MCP::EnvironmentRouter.qualify_id(env_name, feedback.id),
109
+ environment: env_name,
65
110
  status: feedback.status,
66
111
  message: feedback.message,
67
112
  page_url: feedback.page_url,
@@ -93,6 +138,7 @@ module ContextDrop
93
138
  attached = att.respond_to?(:file) && att.file.attached?
94
139
  {
95
140
  id: att.id,
141
+ qualified_id: ContextDrop::MCP::EnvironmentRouter.qualify_id(env_name, att.id),
96
142
  attachment_type: att.attachment_type,
97
143
  element_reference_id: att.element_reference_id,
98
144
  metadata: att.metadata || {},
@@ -6,14 +6,18 @@ module ContextDrop
6
6
  class GetFeedbackAttachment
7
7
  DEFINITION = {
8
8
  name: "get_feedback_attachment",
9
- description: "Retrieve a specific ContextDrop::Attachment record and its binary image/screenshot as an MCP image content block.",
9
+ description: "Retrieve a specific ContextDrop::Attachment record and its binary image/screenshot as an MCP image content block from local or remote environments.",
10
10
  inputSchema: {
11
11
  type: "object",
12
12
  required: ["attachment_id"],
13
13
  properties: {
14
14
  attachment_id: {
15
15
  type: %w[integer string],
16
- description: "The ID of the ContextDrop::Attachment record."
16
+ description: "The ID of the ContextDrop::Attachment record, or a qualified '<environment>:<attachment_id>' string (e.g. 'staging:201')."
17
+ },
18
+ environment: {
19
+ type: "string",
20
+ description: "Optional environment name ('local', 'staging', 'production', etc.)."
17
21
  }
18
22
  }
19
23
  }
@@ -21,15 +25,33 @@ module ContextDrop
21
25
 
22
26
  def self.call(args = {})
23
27
  params = args.is_a?(Hash) ? args.transform_keys(&:to_s) : {}
24
- att_id = params["attachment_id"] || params["id"]
25
- return error_result("Missing required parameter: attachment_id") if att_id.nil? || att_id.to_s.strip.empty?
28
+ raw_att_id = params["attachment_id"] || params["id"]
29
+ return error_result("Missing required parameter: attachment_id") if raw_att_id.nil? || raw_att_id.to_s.strip.empty?
30
+
31
+ target_env, att_id = ContextDrop::MCP::EnvironmentRouter.parse_target(raw_att_id, params["environment"])
32
+
33
+ unless ContextDrop::MCP::EnvironmentRouter.local_target?(target_env)
34
+ remote_cfg = ContextDrop::MCP::EnvironmentRouter.remote_config_for(target_env)
35
+ return error_result("Unknown remote environment '#{target_env}'") unless remote_cfg
36
+
37
+ begin
38
+ return ContextDrop::MCP::RemoteClient.call_tool(target_env, remote_cfg, "get_feedback_attachment", {
39
+ "attachment_id" => att_id
40
+ })
41
+ rescue ContextDrop::MCP::RemoteClient::RemoteError => e
42
+ return error_result(e.message)
43
+ end
44
+ end
26
45
 
27
46
  attachment = ContextDrop::Attachment.includes(:element_reference).find_by(id: att_id)
28
47
  return error_result("Attachment ##{att_id} not found") unless attachment
29
48
 
49
+ env_name = ContextDrop::MCP::EnvironmentRouter.host_environment
30
50
  attached = attachment.respond_to?(:file) && attachment.file.attached?
31
51
  meta_payload = {
32
52
  id: attachment.id,
53
+ qualified_id: ContextDrop::MCP::EnvironmentRouter.qualify_id(env_name, attachment.id),
54
+ environment: env_name,
33
55
  feedback_id: attachment.feedback_id,
34
56
  element_reference_id: attachment.element_reference_id,
35
57
  element_selector: attachment.element_reference&.selector,
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ContextDrop
4
+ module MCP
5
+ module Tools
6
+ class ListEnvironments
7
+ DEFINITION = {
8
+ name: "list_environments",
9
+ description: "List the active host Rails environment and all federated remote ContextDrop environments connected through this unified MCP server.",
10
+ inputSchema: {
11
+ type: "object",
12
+ properties: {
13
+ ping_remotes: {
14
+ type: "boolean",
15
+ description: "When true, performs a lightweight JSON-RPC ping against each configured remote environment to verify connectivity."
16
+ }
17
+ }
18
+ }
19
+ }.freeze
20
+
21
+ def self.call(args = {})
22
+ params = args.is_a?(Hash) ? args.transform_keys(&:to_s) : {}
23
+ ping_remotes = !!params["ping_remotes"]
24
+
25
+ environments = ContextDrop::MCP::EnvironmentRouter.available_environments.map(&:dup)
26
+
27
+ if ping_remotes
28
+ remotes = ContextDrop::MCP::EnvironmentRouter.remote_environments
29
+ environments.each do |entry|
30
+ next unless entry[:mode] == "remote_http"
31
+
32
+ cfg = remotes[entry[:name]]
33
+ begin
34
+ ContextDrop::MCP::RemoteClient.call_rpc(entry[:name], cfg, "ping", {})
35
+ entry[:reachable] = true
36
+ rescue ContextDrop::MCP::RemoteClient::RemoteError => e
37
+ entry[:reachable] = false
38
+ entry[:error] = e.message
39
+ end
40
+ end
41
+ end
42
+
43
+ {
44
+ content: [
45
+ {
46
+ type: "text",
47
+ text: JSON.pretty_generate(
48
+ host_environment: ContextDrop::MCP::EnvironmentRouter.host_environment,
49
+ federation_enabled: !ContextDrop::MCP::EnvironmentRouter.local_only?,
50
+ environments: environments
51
+ )
52
+ }
53
+ ],
54
+ isError: false
55
+ }
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end