Class: Mistri::Generators::McpGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
ActiveRecord::Generators::Migration
Defined in:
lib/generators/mistri/mcp/mcp_generator.rb

Overview

bin/rails generate mistri:mcp McpConnection

Creates a host-named MCP connection model and migration: each row is one server connection and carries its own OAuth flow state, so the connect/callback pair works from a controller, a GraphQL mutation, or anywhere else the host prefers.

Instance Method Summary collapse

Instance Method Details

#create_migration_fileObject



26
27
28
29
# File 'lib/generators/mistri/mcp/mcp_generator.rb', line 26

def create_migration_file
  migration_template "migration.rb.tt",
                     File.join(db_migrate_path, "create_#{table_name}.rb")
end

#create_modelObject



22
23
24
# File 'lib/generators/mistri/mcp/mcp_generator.rb', line 22

def create_model
  template "model.rb.tt", File.join("app/models", class_path, "#{file_name}.rb")
end

#show_wiringObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/generators/mistri/mcp/mcp_generator.rb', line 31

def show_wiring
  say <<~NOTE

    Connect (from a controller, GraphQL mutation, wherever):

      connection, authorize_url = #{class_name}.connect(
        name: "Linear", url: params[:url],
        client_name: "YourApp", redirect_uri: mcp_callback_url,
      )
      redirect_to authorize_url, allow_other_host: true

    Callback:

      connection = #{class_name}.complete(state: params[:state], code: params[:code])

    Then hand its tools to an agent:

      agent = Mistri.agent("claude-opus-4-8", tools: connection.tools(prefix: "linear"))

    Tokens are encrypted; run bin/rails db:encryption:init if you have
    not set up Active Record encryption.

  NOTE
end