Class: Relay::Forms::MCP

Inherits:
Object
  • Object
show all
Defined in:
app/forms/mcp.rb,
app/forms/mcp/github.rb,
app/forms/mcp/forgejo.rb

Overview

The MCP class represents preset-backed MCP form state. It holds the shared persisted fields for Relay’s MCP UI and dispatches to preset-specific subclasses for GitHub and Forgejo.

Direct Known Subclasses

Forgejo, GitHub

Defined Under Namespace

Classes: Forgejo, GitHub

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, persisted: false) ⇒ MCP

Returns a new instance of MCP.

Parameters:

  • id (Integer, String, nil) (defaults to: nil)

    The MCP row id

  • persisted (Boolean) (defaults to: false)

    Whether the form is backed by a persisted MCP row



77
78
79
80
# File 'app/forms/mcp.rb', line 77

def initialize(id: nil, persisted: false)
  @id = id
  @persisted = persisted
end

Instance Attribute Details

#idInteger, ... (readonly)

Returns the MCP row id when editing an existing server

Returns:

  • (Integer, String, nil)

    Returns the MCP row id when editing an existing server



12
13
14
# File 'app/forms/mcp.rb', line 12

def id
  @id
end

Class Method Details

.build(preset:, attributes: {}) ⇒ Relay::Forms::MCP

Returns A preset-specific form instance.

Parameters:

  • preset (String)

    The MCP preset id

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

    Shared form attributes

Returns:



64
65
66
67
68
69
70
# File 'app/forms/mcp.rb', line 64

def self.build(preset:, attributes: {})
  case preset
  when "forgejo" then Forgejo.new(**attributes)
  when "github" then GitHub.new(**attributes)
  else raise ArgumentError, "Unknown MCP preset: #{preset.inspect}"
  end
end

.from_model(mcp) ⇒ Relay::Forms::MCP

Returns A preset-specific form instance.

Parameters:

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/forms/mcp.rb', line 19

def self.from_model(mcp)
  common = {
    id: mcp.id,
    persisted: true
  }
  case preset = mcp.data["preset"]
  when "forgejo"
    attributes = common.merge(url: mcp.env["FORGEJO_URL"], token: mcp.env["FORGEJO_TOKEN"])
    build(preset:, attributes:)
  when "github"
    attributes = common.merge(token: mcp.headers["Authorization"].to_s.delete_prefix("Bearer ").strip)
    build(preset:, attributes:)
  else
    raise ArgumentError, "Unknown MCP preset: #{mcp.data["preset"].inspect}"
  end
end

.from_params(params) ⇒ Relay::Forms::MCP

Returns A preset-specific form instance.

Parameters:

  • params (Hash)

    The submitted MCP form params

Returns:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/forms/mcp.rb', line 41

def self.from_params(params)
  common = {
    id: params["id"],
    persisted: false
  }
  case preset = params["preset"]
  when "forgejo"
    attributes = common.merge(url: params["url"], token: params["token"])
    build(preset:, attributes:)
  when "github"
    build(preset:, attributes: common.merge(token: params["token"]))
  else
    raise ArgumentError, "Unknown MCP preset: #{params["preset"].inspect}"
  end
end

Instance Method Details

#persisted?Boolean

Returns true when this form was built from a persisted MCP row

Returns:

  • (Boolean)

    Returns true when this form was built from a persisted MCP row



85
86
87
# File 'app/forms/mcp.rb', line 85

def persisted?
  @persisted
end