context_drop 0.1.4 → 0.3.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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +330 -116
  3. data/Rakefile +110 -1
  4. data/SPEC.md +74 -26
  5. data/app/assets/javascripts/context_drop/context_drop.js +6329 -682
  6. data/app/controllers/context_drop/agent_controller.rb +170 -0
  7. data/app/controllers/context_drop/application_controller.rb +52 -3
  8. data/app/controllers/context_drop/configs_controller.rb +12 -2
  9. data/app/controllers/context_drop/dashboard/feedbacks_controller.rb +15 -11
  10. data/app/controllers/context_drop/feedbacks_controller.rb +396 -20
  11. data/app/controllers/context_drop/mcp_controller.rb +2 -1
  12. data/app/helpers/context_drop/widget_helper.rb +11 -1
  13. data/app/javascript/context_drop/__tests__/api-client.test.ts +255 -0
  14. data/app/javascript/context_drop/__tests__/widget.test.ts +1015 -89
  15. data/app/javascript/context_drop/api-client.ts +422 -19
  16. data/app/javascript/context_drop/element-picker.ts +186 -34
  17. data/app/javascript/context_drop/icons.ts +28 -0
  18. data/app/javascript/context_drop/markdown.ts +146 -0
  19. data/app/javascript/context_drop/sanitizer.ts +413 -2
  20. data/app/javascript/context_drop/screenshot.ts +103 -9
  21. data/app/javascript/context_drop/styles.ts +1705 -248
  22. data/app/javascript/context_drop/types.ts +243 -6
  23. data/app/javascript/context_drop/widget.ts +3318 -294
  24. data/app/models/context_drop/feedback.rb +88 -8
  25. data/app/services/context_drop/ownership_token.rb +114 -0
  26. data/app/views/context_drop/dashboard/feedbacks/index.html.erb +13 -0
  27. data/app/views/context_drop/dashboard/feedbacks/show.html.erb +19 -0
  28. data/app/views/layouts/context_drop/application.html.erb +6 -0
  29. data/config/routes.rb +22 -0
  30. data/db/migrate/20261112000004_add_environment_to_context_drop_feedbacks.rb +10 -0
  31. data/db/migrate/20261113000005_add_deleted_at_to_context_drop_feedbacks.rb +11 -0
  32. data/lib/context_drop/agent/key_store.rb +290 -0
  33. data/lib/context_drop/agent/llm_client.rb +413 -0
  34. data/lib/context_drop/agent/orchestrator.rb +314 -0
  35. data/lib/context_drop/agent/workspace_sandbox.rb +499 -0
  36. data/lib/context_drop/configuration.rb +242 -3
  37. data/lib/context_drop/mcp/dispatcher.rb +71 -29
  38. data/lib/context_drop/mcp/environment_router.rb +115 -0
  39. data/lib/context_drop/mcp/prompts/investigate_feedback.rb +90 -9
  40. data/lib/context_drop/mcp/remote_client.rb +120 -0
  41. data/lib/context_drop/mcp/server.rb +9 -2
  42. data/lib/context_drop/mcp/tools/get_feedback.rb +62 -5
  43. data/lib/context_drop/mcp/tools/get_feedback_attachment.rb +29 -4
  44. data/lib/context_drop/mcp/tools/list_environments.rb +60 -0
  45. data/lib/context_drop/mcp/tools/list_feedbacks.rb +195 -23
  46. data/lib/context_drop/mcp/tools/update_feedback_status.rb +48 -5
  47. data/lib/context_drop/version.rb +1 -1
  48. data/lib/context_drop.rb +8 -2
  49. data/lib/generators/context_drop/install/templates/initializer.rb.tt +29 -2
  50. metadata +14 -2
@@ -6,25 +6,44 @@ 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
- raise ContextDrop::Error, "Feedback ##{feedback_id} not found" unless feedback
41
+ if !feedback || (feedback.respond_to?(:deleted?) && feedback.deleted?)
42
+ raise ContextDrop::Error, "Feedback ##{feedback_id} not found"
43
+ end
44
+
45
+ env_name = ContextDrop::MCP::EnvironmentRouter.record_environment(feedback)
46
+ qualified = ContextDrop::MCP::EnvironmentRouter.qualify_id(env_name, feedback.id)
28
47
 
29
48
  element_lines = if feedback.element_references.any?
30
49
  feedback.element_references.map.with_index(1) do |el, idx|
@@ -41,9 +60,10 @@ module ContextDrop
41
60
  end
42
61
 
43
62
  instructions = <<~PROMPT
44
- Investigate and resolve ContextDrop Feedback ##{feedback.id} (status: #{feedback.status}).
63
+ Investigate and resolve ContextDrop Feedback ##{feedback.id} (`#{qualified}`, environment: `#{env_name}`, status: #{feedback.status}).
45
64
 
46
65
  ## Reported Feedback
66
+ - **Environment:** `#{env_name}`
47
67
  - **Message:** #{feedback.message.presence || '(No text message provided)'}
48
68
  - **Originating Page URL:** `#{feedback.page_url}`
49
69
  - **Submitter:** #{feedback.submitter_label}
@@ -56,8 +76,8 @@ module ContextDrop
56
76
  ## Recommended Investigation Steps
57
77
  1. Locate the Rails route and controller action corresponding to `#{feedback.page_url}` in `config/routes.rb` and `app/controllers/`.
58
78
  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.
79
+ 3. Inspect any attached screenshots (`get_feedback` with `id: "#{qualified}"`) to verify the visual layout issue.
80
+ 4. Propose and verify a fix, then call `update_feedback_status` (`id: "#{qualified}"`, `status: "resolved"`) once complete.
61
81
  PROMPT
62
82
 
63
83
  message_content = [{ type: "text", text: instructions }]
@@ -68,7 +88,68 @@ module ContextDrop
68
88
  end
69
89
 
70
90
  {
71
- description: "Investigation brief for ContextDrop Feedback ##{feedback.id} on #{feedback.page_url}",
91
+ description: "Investigation brief for ContextDrop Feedback #{qualified} on #{feedback.page_url}",
92
+ messages: [
93
+ {
94
+ role: "user",
95
+ content: message_content.size == 1 ? message_content.first : message_content
96
+ }
97
+ ]
98
+ }
99
+ end
100
+
101
+ def self.build_remote_prompt(env_name, remote_cfg, feedback_id)
102
+ tool_res = ContextDrop::MCP::Tools::GetFeedback.fetch_remote_feedback(env_name, remote_cfg, feedback_id, include_images: true)
103
+ if tool_res[:isError]
104
+ err_text = Array(tool_res[:content]).first&.dig(:text).to_s
105
+ raise ContextDrop::Error, err_text
106
+ end
107
+
108
+ text_block = Array(tool_res[:content]).find { |b| b.is_a?(Hash) && b[:type].to_s == "text" }
109
+ fb = text_block ? JSON.parse(text_block[:text].to_s) : {}
110
+ qualified = ContextDrop::MCP::EnvironmentRouter.qualify_id(env_name, fb["id"] || feedback_id)
111
+
112
+ els = Array(fb["element_references"])
113
+ element_lines = if els.any?
114
+ els.map.with_index(1) do |el, idx|
115
+ <<~EL.strip
116
+ #{idx}. `<#{el['tag_name']}>` — Selector: `#{el['selector']}`
117
+ - DOM Path: `#{el['dom_path'] || 'N/A'}`
118
+ - Visible Text: #{el['text_content'].inspect}
119
+ - Bounding Box: `#{JSON.generate(el['bounding_rect'] || {})}`
120
+ - Attributes: `#{JSON.generate(el['attributes_snapshot'] || {})}`
121
+ EL
122
+ end.join("\n")
123
+ else
124
+ "None selected."
125
+ end
126
+
127
+ instructions = <<~PROMPT
128
+ Investigate and resolve ContextDrop Feedback ##{fb['id'] || feedback_id} (`#{qualified}`, environment: `#{env_name}`, status: #{fb['status']}).
129
+
130
+ ## Reported Feedback
131
+ - **Environment:** `#{env_name}`
132
+ - **Message:** #{fb['message'].presence || '(No text message provided)'}
133
+ - **Originating Page URL:** `#{fb['page_url']}`
134
+ - **Submitter:** #{fb.dig('submitter', 'label') || 'Anonymous'}
135
+ - **Submitted At:** #{fb['created_at']}
136
+ - **Viewport / Metadata:** `#{JSON.generate(fb['metadata'] || {})}`
137
+
138
+ ## Attached DOM Element References
139
+ #{element_lines}
140
+
141
+ ## Recommended Investigation Steps
142
+ 1. Locate the Rails route and controller action corresponding to `#{fb['page_url']}` in `config/routes.rb` and `app/controllers/`.
143
+ 2. Search the view templates (`app/views/`, ViewComponents, or frontend components) for the attached DOM selectors (`#{els.map { |e| e['selector'] }.join(', ')}`).
144
+ 3. Inspect any attached screenshots (`get_feedback` with `id: "#{qualified}"`) to verify the visual layout issue.
145
+ 4. Propose and verify a fix locally, then call `update_feedback_status` (`id: "#{qualified}"`, `status: "resolved"`) once complete.
146
+ PROMPT
147
+
148
+ image_blocks = Array(tool_res[:content]).select { |b| b.is_a?(Hash) && b[:type].to_s == "image" }
149
+ message_content = [{ type: "text", text: instructions }] + image_blocks
150
+
151
+ {
152
+ description: "Investigation brief for ContextDrop Feedback #{qualified} on #{fb['page_url']}",
72
153
  messages: [
73
154
  {
74
155
  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,18 +8,26 @@ 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",
22
26
  description: "When true (default), includes attached screenshots and images as base64 MCP image content blocks."
27
+ },
28
+ include_deleted: {
29
+ type: "boolean",
30
+ description: "When true, allows retrieving a soft-deleted feedback record. Defaults to false."
23
31
  }
24
32
  }
25
33
  }
@@ -27,16 +35,29 @@ module ContextDrop
27
35
 
28
36
  def self.call(args = {})
29
37
  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?
38
+ raw_id = params["id"] || params["feedback_id"]
39
+ return error_result("Missing required parameter: id") if raw_id.nil? || raw_id.to_s.strip.empty?
32
40
 
33
41
  include_images = params.key?("include_images") ? !!params["include_images"] : true
42
+ include_deleted = params["include_deleted"] == true || %w[true 1 yes].include?(params["include_deleted"].to_s.strip.downcase)
43
+ target_env, feedback_id = ContextDrop::MCP::EnvironmentRouter.parse_target(raw_id, params["environment"])
44
+
45
+ unless ContextDrop::MCP::EnvironmentRouter.local_target?(target_env)
46
+ remote_cfg = ContextDrop::MCP::EnvironmentRouter.remote_config_for(target_env)
47
+ unless remote_cfg
48
+ return error_result("Unknown remote environment '#{target_env}'")
49
+ end
50
+
51
+ return fetch_remote_feedback(target_env, remote_cfg, feedback_id, include_images: include_images, include_deleted: include_deleted)
52
+ end
34
53
 
35
54
  feedback = ContextDrop::Feedback
36
55
  .includes(:submitter, :element_references, :attachments)
37
56
  .find_by(id: feedback_id)
38
57
 
39
- return error_result("Feedback ##{feedback_id} not found") unless feedback
58
+ if !feedback || (!include_deleted && feedback.respond_to?(:deleted?) && feedback.deleted?)
59
+ return error_result("Feedback ##{feedback_id} not found")
60
+ end
40
61
 
41
62
  payload = serialize_feedback(feedback)
42
63
  content_blocks = [
@@ -59,9 +80,42 @@ module ContextDrop
59
80
  }
60
81
  end
61
82
 
83
+ def self.fetch_remote_feedback(env_name, remote_cfg, feedback_id, include_images: true, include_deleted: false)
84
+ remote_args = {
85
+ "id" => feedback_id,
86
+ "include_images" => include_images
87
+ }
88
+ remote_args["include_deleted"] = true if include_deleted
89
+ res = ContextDrop::MCP::RemoteClient.call_tool(env_name, remote_cfg, "get_feedback", remote_args)
90
+ return res if res[:isError]
91
+
92
+ updated_blocks = Array(res[:content]).map do |block|
93
+ if block.is_a?(Hash) && block[:type].to_s == "text"
94
+ begin
95
+ parsed = JSON.parse(block[:text].to_s)
96
+ if parsed.is_a?(Hash)
97
+ parsed["environment"] = env_name
98
+ parsed["qualified_id"] = ContextDrop::MCP::EnvironmentRouter.qualify_id(env_name, parsed["id"] || feedback_id)
99
+ next block.merge(text: JSON.pretty_generate(parsed))
100
+ end
101
+ rescue JSON::ParserError
102
+ # Keep original text block if non-JSON
103
+ end
104
+ end
105
+ block
106
+ end
107
+
108
+ { content: updated_blocks, isError: false }
109
+ rescue ContextDrop::MCP::RemoteClient::RemoteError => e
110
+ error_result(e.message)
111
+ end
112
+
62
113
  def self.serialize_feedback(feedback)
114
+ env_name = ContextDrop::MCP::EnvironmentRouter.record_environment(feedback)
63
115
  {
64
116
  id: feedback.id,
117
+ qualified_id: ContextDrop::MCP::EnvironmentRouter.qualify_id(env_name, feedback.id),
118
+ environment: env_name,
65
119
  status: feedback.status,
66
120
  message: feedback.message,
67
121
  page_url: feedback.page_url,
@@ -74,6 +128,8 @@ module ContextDrop
74
128
  metadata: feedback.metadata || {},
75
129
  created_at: feedback.created_at&.iso8601,
76
130
  updated_at: feedback.updated_at&.iso8601,
131
+ deleted: (feedback.respond_to?(:deleted?) ? feedback.deleted? : false),
132
+ deleted_at: (feedback.respond_to?(:deleted_at_value) ? feedback.deleted_at_value&.iso8601 : nil),
77
133
  element_references: feedback.element_references.map do |el|
78
134
  {
79
135
  id: el.id,
@@ -93,6 +149,7 @@ module ContextDrop
93
149
  attached = att.respond_to?(:file) && att.file.attached?
94
150
  {
95
151
  id: att.id,
152
+ qualified_id: ContextDrop::MCP::EnvironmentRouter.qualify_id(env_name, att.id),
96
153
  attachment_type: att.attachment_type,
97
154
  element_reference_id: att.element_reference_id,
98
155
  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,36 @@ 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
48
+ if attachment.respond_to?(:feedback) && attachment.feedback.respond_to?(:deleted?) && attachment.feedback.deleted?
49
+ return error_result("Attachment ##{att_id} not found")
50
+ end
29
51
 
52
+ env_name = ContextDrop::MCP::EnvironmentRouter.host_environment
30
53
  attached = attachment.respond_to?(:file) && attachment.file.attached?
31
54
  meta_payload = {
32
55
  id: attachment.id,
56
+ qualified_id: ContextDrop::MCP::EnvironmentRouter.qualify_id(env_name, attachment.id),
57
+ environment: env_name,
33
58
  feedback_id: attachment.feedback_id,
34
59
  element_reference_id: attachment.element_reference_id,
35
60
  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