maquina-generators 0.9.0 → 0.11.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.
- checksums.yaml +4 -4
- data/README.md +201 -12
- data/lib/generators/maquina/app/USAGE +4 -0
- data/lib/generators/maquina/app/app_generator.rb +38 -7
- data/lib/generators/maquina/app/templates/README.md.erb +21 -0
- data/lib/generators/maquina/app/templates/app/views/home/index.html.erb +1 -1
- data/lib/generators/maquina/auth_flavor.rb +59 -0
- data/lib/generators/maquina/backstage_signin/backstage_signin.rb +320 -0
- data/lib/generators/maquina/backstage_signin/templates/test/integration/backstage_access_test.rb.tt +104 -0
- data/lib/generators/maquina/csp_reports/csp_reports_generator.rb +13 -1
- data/lib/generators/maquina/csp_reports/templates/app/models/mcp/tools/csp_reports.rb +71 -0
- data/lib/generators/maquina/csp_reports/templates/test/models/mcp/tools/csp_reports_test.rb +35 -0
- data/lib/generators/maquina/error_context/USAGE +22 -0
- data/lib/generators/maquina/error_context/error_context_generator.rb +51 -0
- data/lib/generators/maquina/mcp/USAGE +38 -0
- data/lib/generators/maquina/mcp/mcp_generator.rb +194 -0
- data/lib/generators/maquina/mcp/mcp_sibling_tools.rb +122 -0
- data/lib/generators/maquina/mcp/templates/app/controllers/concerns/mcp_authenticatable.rb +63 -0
- data/lib/generators/maquina/mcp/templates/app/controllers/mcp_controller.rb +205 -0
- data/lib/generators/maquina/mcp/templates/app/models/mcp/tool_definitions.rb +38 -0
- data/lib/generators/maquina/mcp/templates/app/models/mcp/tool_error.rb +17 -0
- data/lib/generators/maquina/mcp/templates/app/models/mcp/tools/app.rb +51 -0
- data/lib/generators/maquina/mcp/templates/app/models/mcp/tools.rb +83 -0
- data/lib/generators/maquina/mcp/templates/app/models/mcp/user_scope.rb +50 -0
- data/lib/generators/maquina/mcp/templates/config/initializers/mcp_cors.rb +38 -0
- data/lib/generators/maquina/mcp/templates/test/integration/mcp_conformance_test.rb +223 -0
- data/lib/generators/maquina/mcp/templates/test/integration/mcp_flow_test.rb.tt +65 -0
- data/lib/generators/maquina/mcp/templates/test/models/mcp/tools_test.rb.tt +145 -0
- data/lib/generators/maquina/mcp/templates/test/test_helpers/mcp_test_helper.rb.tt +103 -0
- data/lib/generators/maquina/mcp_tool/USAGE +26 -0
- data/lib/generators/maquina/mcp_tool/mcp_tool_generator.rb +239 -0
- data/lib/generators/maquina/mcp_tool/templates/test/models/mcp/tools/tool_test.rb.tt +49 -0
- data/lib/generators/maquina/mission_control_jobs/USAGE +5 -0
- data/lib/generators/maquina/mission_control_jobs/mission_control_jobs_generator.rb +21 -5
- data/lib/generators/maquina/mission_control_jobs/templates/app/views/backstage_dashboard/index.html.erb.tt +1 -1
- data/lib/generators/maquina/mission_control_jobs/templates/app/views/layouts/_admin_navigation.html.erb.tt +12 -11
- data/lib/generators/maquina/mission_control_jobs/templates/app/views/mission_control/jobs/jobs/_filters.html.erb +1 -1
- data/lib/generators/maquina/mission_control_jobs/templates/app/views/mission_control/jobs/jobs/_general_information.html.erb +1 -1
- data/lib/generators/maquina/mission_control_jobs/templates/app/views/mission_control/jobs/jobs/_job.html.erb +1 -1
- data/lib/generators/maquina/mission_control_jobs/templates/app/views/mission_control/jobs/jobs/failed/_job.html.erb +1 -1
- data/lib/generators/maquina/mission_control_jobs/templates/app/views/mission_control/jobs/queues/_job.html.erb +1 -1
- data/lib/generators/maquina/mission_control_jobs/templates/app/views/mission_control/jobs/shared/_job.html.erb +1 -1
- data/lib/generators/maquina/mission_control_jobs/templates/app/views/mission_control/jobs/workers/_worker.html.erb +1 -1
- data/lib/generators/maquina/oauth/USAGE +35 -0
- data/lib/generators/maquina/oauth/oauth_generator.rb +359 -0
- data/lib/generators/maquina/oauth/templates/app/controllers/connected_applications_controller.rb +26 -0
- data/lib/generators/maquina/oauth/templates/app/controllers/oauth/authorization_servers_controller.rb +24 -0
- data/lib/generators/maquina/oauth/templates/app/controllers/oauth/authorizations_controller.rb +92 -0
- data/lib/generators/maquina/oauth/templates/app/controllers/oauth/protected_resources_controller.rb +14 -0
- data/lib/generators/maquina/oauth/templates/app/controllers/oauth/revocations_controller.rb +20 -0
- data/lib/generators/maquina/oauth/templates/app/controllers/oauth/tokens_controller.rb +67 -0
- data/lib/generators/maquina/oauth/templates/app/models/access_token.rb +83 -0
- data/lib/generators/maquina/oauth/templates/app/models/connected_application.rb +49 -0
- data/lib/generators/maquina/oauth/templates/app/models/mcp.rb.tt +33 -0
- data/lib/generators/maquina/oauth/templates/app/models/oauth_authorization_code.rb +52 -0
- data/lib/generators/maquina/oauth/templates/app/models/oauth_client/metadata_fetcher.rb +195 -0
- data/lib/generators/maquina/oauth/templates/app/models/oauth_client.rb +50 -0
- data/lib/generators/maquina/oauth/templates/app/views/connected_applications/index.html.erb +43 -0
- data/lib/generators/maquina/oauth/templates/app/views/oauth/authorizations/error.html.erb +8 -0
- data/lib/generators/maquina/oauth/templates/app/views/oauth/authorizations/new.html.erb +36 -0
- data/lib/generators/maquina/oauth/templates/config/locales/oauth.en.yml +34 -0
- data/lib/generators/maquina/oauth/templates/config/locales/oauth.es.yml +34 -0
- data/lib/generators/maquina/oauth/templates/migration_create_access_tokens.rb.tt +20 -0
- data/lib/generators/maquina/oauth/templates/migration_create_oauth_authorization_codes.rb.tt +19 -0
- data/lib/generators/maquina/oauth/templates/migration_create_oauth_clients.rb.tt +14 -0
- data/lib/generators/maquina/oauth/templates/test/fixtures/access_tokens.yml +48 -0
- data/lib/generators/maquina/oauth/templates/test/fixtures/oauth_authorization_codes.yml +11 -0
- data/lib/generators/maquina/oauth/templates/test/fixtures/oauth_clients.yml +7 -0
- data/lib/generators/maquina/oauth/templates/test/integration/connected_applications_test.rb.tt +70 -0
- data/lib/generators/maquina/oauth/templates/test/integration/oauth_authorization_test.rb.tt +150 -0
- data/lib/generators/maquina/oauth/templates/test/integration/oauth_discovery_test.rb +44 -0
- data/lib/generators/maquina/oauth/templates/test/integration/oauth_tokens_test.rb +147 -0
- data/lib/generators/maquina/oauth/templates/test/models/access_token_test.rb.tt +80 -0
- data/lib/generators/maquina/oauth/templates/test/models/connected_application_test.rb +41 -0
- data/lib/generators/maquina/oauth/templates/test/models/oauth_authorization_code_test.rb +58 -0
- data/lib/generators/maquina/oauth/templates/test/test_helpers/oauth_test_helper.rb.tt +82 -0
- data/lib/generators/maquina/passkeys/USAGE +4 -2
- data/lib/generators/maquina/passkeys/passkeys_generator.rb +16 -11
- data/lib/generators/maquina/passkeys/templates/app/controllers/session/{passkeys_controller.rb → passkeys_controller.rb.tt} +6 -2
- data/lib/generators/maquina/passkeys/templates/config/locales/{passkeys.en.yml → passkeys.en.yml.tt} +15 -0
- data/lib/generators/maquina/passkeys/templates/config/locales/{passkeys.es.yml → passkeys.es.yml.tt} +15 -0
- data/lib/generators/maquina/passkeys/templates/test/integration/{passkeys_test.rb → passkeys_test.rb.tt} +6 -0
- data/lib/generators/maquina/rack_attack/rack_attack_generator.rb +4 -1
- data/lib/generators/maquina/rack_attack/templates/config/initializers/rack_attack.rb.tt +317 -4
- data/lib/generators/maquina/registration/registration_generator.rb +32 -0
- data/lib/generators/maquina/registration/templates/app/views/registrations/new.html.erb.tt +4 -0
- data/lib/generators/maquina/registration/templates/app/views/sessions/new.html.erb.tt +5 -0
- data/lib/generators/maquina/security/USAGE +12 -0
- data/lib/generators/maquina/security/security_generator.rb +79 -7
- data/lib/generators/maquina/security/templates/app/models/mcp/tools/security.rb.tt +114 -0
- data/lib/generators/maquina/security/templates/app/views/backstage_dashboard/index.html.erb.tt +1 -1
- data/lib/generators/maquina/security/templates/app/views/layouts/_admin_navigation.html.erb.tt +12 -11
- data/lib/generators/maquina/security/templates/test/models/mcp/tools/security_test.rb +99 -0
- data/lib/generators/maquina/solid_errors/USAGE +21 -10
- data/lib/generators/maquina/solid_errors/error_context_files.rb +82 -0
- data/lib/generators/maquina/solid_errors/solid_errors_generator.rb +52 -31
- data/lib/generators/maquina/solid_errors/templates/app/agents/errors_query.rb +86 -29
- data/lib/generators/maquina/solid_errors/templates/app/agents/failure_triage.rb +4 -2
- data/lib/generators/maquina/solid_errors/templates/app/agents/list_failures_tool.rb +9 -4
- data/lib/generators/maquina/solid_errors/templates/app/models/mcp/tools/solid_errors.rb.tt +132 -0
- data/lib/generators/maquina/solid_errors/templates/app/views/backstage_dashboard/index.html.erb.tt +1 -1
- data/lib/generators/maquina/solid_errors/templates/app/views/layouts/_admin_navigation.html.erb.tt +12 -11
- data/lib/generators/maquina/solid_errors/templates/app/views/solid_errors/errors/show/_actions.html.erb +0 -15
- data/lib/generators/maquina/solid_errors/templates/app/views/solid_errors/errors/show/_error_details.html.erb +5 -5
- data/lib/generators/maquina/solid_errors/templates/app/views/solid_errors/occurrences/_collection.html.erb +1 -1
- data/lib/generators/maquina/solid_errors/templates/config/initializers/error_context.rb +33 -0
- data/lib/generators/maquina/solid_errors/templates/test/models/mcp/tools/solid_errors_filters_test.rb +68 -0
- data/lib/generators/maquina/solid_errors/templates/test/models/mcp/tools/solid_errors_test.rb +109 -0
- data/lib/generators/maquina/solid_queue/USAGE +11 -0
- data/lib/generators/maquina/solid_queue/solid_queue_generator.rb +25 -1
- data/lib/generators/maquina/solid_queue/templates/app/models/mcp/tools/solid_queue.rb.tt +163 -0
- data/lib/generators/maquina/solid_queue/templates/test/models/mcp/tools/solid_queue_test.rb +99 -0
- data/lib/maquina_generators/version.rb +1 -1
- data/test/fixtures/error_context/0.10.0/app/agents/errors_query.rb +105 -0
- data/test/fixtures/error_context/0.10.0/app/agents/failure_triage.rb +21 -0
- data/test/fixtures/error_context/0.10.0/app/agents/list_failures_tool.rb +20 -0
- data/test/fixtures/error_context/0.10.0/app/models/mcp/tools/solid_errors.rb +81 -0
- data/test/fixtures/error_context/0.10.0/app/models/mcp/tools/solid_errors_write.rb +101 -0
- data/test/generators/maquina/app_generator_test.rb +67 -5
- data/test/generators/maquina/backstage_signin_test.rb +296 -0
- data/test/generators/maquina/csp_reports_generator_test.rb +125 -6
- data/test/generators/maquina/error_context_generator_test.rb +188 -0
- data/test/generators/maquina/mcp_generator_test.rb +429 -0
- data/test/generators/maquina/mcp_tool_generator_test.rb +235 -0
- data/test/generators/maquina/mission_control_jobs_generator_test.rb +23 -0
- data/test/generators/maquina/oauth_client_metadata_fetcher_test.rb +290 -0
- data/test/generators/maquina/oauth_generator_test.rb +568 -0
- data/test/generators/maquina/passkeys_generator_test.rb +62 -2
- data/test/generators/maquina/rack_attack_generator_test.rb +71 -0
- data/test/generators/maquina/rack_attack_rules_test.rb +304 -0
- data/test/generators/maquina/registration_generator_test.rb +62 -0
- data/test/generators/maquina/security_generator_test.rb +188 -13
- data/test/generators/maquina/solid_errors_generator_test.rb +299 -33
- data/test/generators/maquina/solid_queue_generator_test.rb +175 -25
- data/test/support/rails_auth_app.rb +48 -0
- data/test/test_helper.rb +1 -0
- metadata +90 -41
- data/lib/generators/maquina/solid_errors/templates/app/controllers/failures_mcp_controller.rb.tt +0 -65
- data/test/tmp/Gemfile +0 -2
- data/test/tmp/app/controllers/application_controller.rb +0 -3
- data/test/tmp/app/controllers/concerns/authentication.rb +0 -63
- data/test/tmp/app/controllers/registration/verification_resends_controller.rb +0 -38
- data/test/tmp/app/controllers/registration/verifications_controller.rb +0 -64
- data/test/tmp/app/controllers/registrations_controller.rb +0 -63
- data/test/tmp/app/controllers/session/verification_resends_controller.rb +0 -44
- data/test/tmp/app/controllers/session/verifications_controller.rb +0 -64
- data/test/tmp/app/controllers/sessions_controller.rb +0 -56
- data/test/tmp/app/helpers/authentication_helper.rb +0 -20
- data/test/tmp/app/jobs/authentication_cleanup_job.rb +0 -13
- data/test/tmp/app/mailers/verification_mailer.rb +0 -15
- data/test/tmp/app/models/account.rb +0 -5
- data/test/tmp/app/models/current.rb +0 -5
- data/test/tmp/app/models/email_verification.rb +0 -58
- data/test/tmp/app/models/session.rb +0 -18
- data/test/tmp/app/models/user.rb +0 -37
- data/test/tmp/app/views/registration/verifications/new.html.erb +0 -43
- data/test/tmp/app/views/registrations/new.html.erb +0 -39
- data/test/tmp/app/views/session/verifications/new.html.erb +0 -43
- data/test/tmp/app/views/sessions/new.html.erb +0 -40
- data/test/tmp/app/views/verification_mailer/verification_code.html.erb +0 -37
- data/test/tmp/app/views/verification_mailer/verification_code.text.erb +0 -11
- data/test/tmp/config/locales/clave.en.yml +0 -102
- data/test/tmp/config/locales/clave.es.yml +0 -102
- data/test/tmp/config/routes.rb +0 -12
- data/test/tmp/db/migrate/20261019191386_create_accounts.rb +0 -9
- data/test/tmp/db/migrate/20261019191387_create_users.rb +0 -17
- data/test/tmp/db/migrate/20261019191388_create_sessions.rb +0 -12
- data/test/tmp/db/migrate/20261019191389_create_email_verifications.rb +0 -17
- data/test/tmp/test/test_helpers/session_test_helper.rb +0 -19
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4014b01c776f1e37d61dddd592e30a6acac76546082105ad3ca12c8b2233693c
|
|
4
|
+
data.tar.gz: 8eb3326660cd36814d52a6324f3147b2912d1fe412326655dd6bf344e313a9c8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c547266a74a99a4dd11fd11124ccdd21f59dafe12215e8250060e6e5b11cb6181d6643cd140b1c38262513d9cff3c99889f2bdf3e07437e0479a128d918064b4
|
|
7
|
+
data.tar.gz: 13e67350b2e101c184875128d9c651dc3fd2d7661a1f7ba0ecfb9e50a32b7506de652146b0a9e882e9d17b1a77b12683d9ef0dd150ef6d7eae6cb0557e4a688c
|
data/README.md
CHANGED
|
@@ -62,9 +62,9 @@ All generated code lives in your app -- edit it directly:
|
|
|
62
62
|
- **Email sender:** Edit `app/mailers/verification_mailer.rb`
|
|
63
63
|
- **Translations:** Edit `config/locales/clave.*.yml`
|
|
64
64
|
|
|
65
|
-
### Passkeys -- Passkey Sign-In
|
|
65
|
+
### Passkeys -- Passkey Sign-In
|
|
66
66
|
|
|
67
|
-
**Passkeys** adds WebAuthn passkeys as a second way to sign in,
|
|
67
|
+
**Passkeys** adds WebAuthn passkeys as a second way to sign in, beside Clave's email code or Rails' password (`maquina:registration`). People add passkeys from a `/passkeys` page and sign in with Face ID, a fingerprint or a device PIN, either with a button or straight from the email field's autofill. The email code or the password stays as the way in without a passkey, so removing every passkey never locks anyone out.
|
|
68
68
|
|
|
69
69
|
The [`webauthn`](https://github.com/cedarcode/webauthn-ruby) gem handles only the cryptography (attestation and assertion parsing, signature, origin, challenge and user-verification checks). The flow itself, including controllers, model, views and JavaScript, is generated into your app. There is no JavaScript dependency: the Stimulus controllers use the browser's own `PublicKeyCredential.parseCreationOptionsFromJSON` / `parseRequestOptionsFromJSON` / `toJSON()`. The names (`passkeys` table, `credential_id`, `Session::PasskeysController`) follow the passkeys work proposed for Rails itself (rails/rails#57100).
|
|
70
70
|
|
|
@@ -84,7 +84,7 @@ The [`webauthn`](https://github.com/cedarcode/webauthn-ruby) gem handles only th
|
|
|
84
84
|
#### Usage
|
|
85
85
|
|
|
86
86
|
```bash
|
|
87
|
-
rails g maquina:clave # first
|
|
87
|
+
rails g maquina:clave # first (or maquina:registration)
|
|
88
88
|
rails g maquina:passkeys
|
|
89
89
|
rails db:migrate
|
|
90
90
|
```
|
|
@@ -115,6 +115,141 @@ WEBAUTHN_ORIGINS=https://example.com,https://app.example.com
|
|
|
115
115
|
- **In a browser:** Chrome's virtual authenticator works in DevTools (More tools > WebAuthn) or over CDP (`WebAuthn.addVirtualAuthenticator` with `ctap2`, `internal`, a resident key and user verification). It answers the sign-in page's autofill request on its own, so loading `/session/new` signs you in without a click. To test the button, make `PublicKeyCredential.isConditionalMediationAvailable` return `false`.
|
|
116
116
|
- **Dev server on another port:** set `WEBAUTHN_ORIGINS=http://localhost:<port>`.
|
|
117
117
|
|
|
118
|
+
### OAuth -- OAuth 2.1 Sign-In for AI Clients
|
|
119
|
+
|
|
120
|
+
**OAuth** lets AI clients (the MCP Inspector, Claude, any MCP client) sign people in to your app on top of its own sign-in, Clave's or Rails' (`maquina:registration`). It is the authorization server behind `maquina:mcp`. Clients identify themselves with a Client ID Metadata Document (CIMD): the `client_id` is an `https` URL whose JSON names the client and its redirect URIs, so there is no dynamic registration and no client secret. Every flow is PKCE (`S256` only), and people sign in the way they already do. Tokens and codes go through `Mcp.enabled_for?(user)` in `app/models/mcp.rb`, the gate the app owns; with Clave it turns away a blocked user, and with Rails' sign-in it is where a deactivation check goes.
|
|
121
|
+
|
|
122
|
+
No OAuth gem is added: the endpoints, models and fetcher are generated into your app.
|
|
123
|
+
|
|
124
|
+
#### What it generates
|
|
125
|
+
|
|
126
|
+
- **Migrations:** `create_oauth_clients`, `create_oauth_authorization_codes`, `create_access_tokens` (refresh tokens live on the access token row)
|
|
127
|
+
- **Models:** `OauthClient` (fetched metadata, refreshed after 24 hours), `OauthAuthorizationCode` (10-minute, single-use, PKCE-checked), `AccessToken` (1-hour access token, rotating refresh token, `read`/`write` scopes; only SHA-256 digests are stored) and `ConnectedApplication`, which groups a person's grants per client
|
|
128
|
+
- **CIMD fetcher:** `OauthClient::MetadataFetcher`, plain `Net::HTTP`. It refuses non-`https` URLs, literal IPs, hosts that resolve to loopback, private, link-local, unspecified or `100.64.0.0/10` addresses, redirects, bodies over 16 KB, responses slower than 3 seconds and documents whose `client_id` does not match
|
|
129
|
+
- **Discovery:** `GET /.well-known/oauth-authorization-server` and `GET /.well-known/oauth-protected-resource/mcp`
|
|
130
|
+
- **Authorize:** `Oauth::AuthorizationsController` at `/oauth/authorize`, the consent screen. A signed-out visitor signs in with Clave and lands back on the exact authorize URL. An unknown client or a redirect URI the client does not list gets an error page and is never redirected
|
|
131
|
+
- **Token and revoke:** `POST /oauth/token` (authorization code and refresh token grants) and `POST /oauth/revoke` (RFC 7009), JSON with `Cache-Control: no-store`
|
|
132
|
+
- **Connected apps:** `ConnectedApplicationsController` at `<prefix>/connected_apps`, where people see each connected client with its scopes and last use, and revoke it. Revoking stops its tokens at once
|
|
133
|
+
- **Gate:** `app/models/mcp.rb` with `Mcp.enabled_for?(user)`, written only if missing. Your app owns it
|
|
134
|
+
- **Rack::Attack:** `/mcp` and `/oauth/token` leave the per-IP throttle and flood ban (they are limited per token and per client instead), plus an `oauth/token/client` throttle of 30 per minute, when `config/initializers/rack_attack.rb` exists
|
|
135
|
+
- **Locale files:** English and Spanish (`config/locales/oauth.*.yml`)
|
|
136
|
+
- **Tests:** fixtures (`oauth_clients`, `oauth_authorization_codes`, `access_tokens`, and `mcp_*` users and account), `OauthTestHelper`, and tests for PKCE, code reuse and expiry, refresh rotation and reuse, `resource` and `iss` checks, the return-to after sign-in and revoking
|
|
137
|
+
|
|
138
|
+
#### Usage
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
rails g maquina:clave # first (or maquina:registration)
|
|
142
|
+
rails g maquina:oauth
|
|
143
|
+
rails db:migrate
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Anything the generator cannot place safely (a Rack::Attack initializer that no longer has the expected shape) is listed after the install instead of being forced.
|
|
147
|
+
|
|
148
|
+
#### Options
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
rails g maquina:oauth # Full install
|
|
152
|
+
rails g maquina:oauth --skip-views # Endpoints only; bring your own consent and Connected apps views
|
|
153
|
+
rails g maquina:oauth --prefix /account # Connected apps at /account/connected_apps (default: /settings)
|
|
154
|
+
rails g maquina:oauth --flag beta_mcp # Gate consent and Connected apps behind a feature flag
|
|
155
|
+
rails g maquina:oauth --quiet # No post-install message
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
#### Feature flag
|
|
159
|
+
|
|
160
|
+
Without `--flag`, `Mcp.enabled_for?` returns `true` for everyone. With `--flag beta_mcp`, it reads `Rails.application.credentials.features.beta_mcp`, then `ENV["BETA_MCP"]`. When it is off for someone, consent answers `access_denied`, Connected apps is a 404, their MCP tools return nothing and `server/discover` still answers. Replace the method body with Flipper or a column when you need per-user rollout.
|
|
161
|
+
|
|
162
|
+
### MCP -- Model Context Protocol Server
|
|
163
|
+
|
|
164
|
+
**MCP** gives your app a standalone [MCP](https://modelcontextprotocol.io) server at `POST /mcp`, signed in through `maquina:oauth`. It speaks protocol `2026-07-28` over plain HTTP: no SSE, no sessions, no `mcp` gem. It ships a `whoami` tool that proves the wiring works, and `maquina:mcp_tool` adds more.
|
|
165
|
+
|
|
166
|
+
#### What it generates
|
|
167
|
+
|
|
168
|
+
- **Controller:** `McpController` (`ActionController::API`) with `McpAuthenticatable`, which reads the `Authorization: Bearer` token and checks that it was issued for `<base>/mcp`. A missing or bad token gets 401 with `WWW-Authenticate` pointing at the protected-resource metadata. `GET` and `DELETE /mcp` return 405
|
|
169
|
+
- **Protocol:** `server/discover` (no token needed), `tools/list` and `tools/call`. The `Mcp-Method` and `Mcp-Name` headers must match the body, `params._meta` must carry protocol `2026-07-28`, and the JSON-RPC error codes live in one table in `McpController`. A write tool called with a `read` token gets 403 `insufficient_scope`
|
|
170
|
+
- **Rate limit:** 120 requests per minute per token (per IP without one)
|
|
171
|
+
- **CORS:** `config/initializers/mcp_cors.rb`, a small Rack middleware for `/mcp`, `/oauth/token`, `/oauth/revoke` and `/.well-known/oauth-*` (never `/oauth/authorize`); no `rack-cors`
|
|
172
|
+
- **Registry:** `app/models/mcp/` -- `Mcp::Tools` (dispatch), `Mcp::ToolDefinitions` (what a user sees), `Mcp::ToolError` and `Mcp::UserScope` (the token's user and the records it may reach). Every file in `app/models/mcp/tools/` is a module with `DEFINITIONS`, `WRITE_TOOLS`, `ADMIN_ONLY` and one method per tool. Arguments are checked against the tool's JSON Schema (required keys, types, enums) before dispatch
|
|
173
|
+
- **Tool:** `app/models/mcp/tools/app.rb` with `whoami` (email, granted scope, server and protocol versions, and the flag state with `--flag`), written only if missing
|
|
174
|
+
- **Tests:** `McpTestHelper` (`mcp_post`, `oauth_token_for`), `test/integration/mcp_flow_test.rb` (discover, authorize, consent, token, `whoami`, revoke, 401), `test/integration/mcp_conformance_test.rb` and `test/models/mcp/tools_test.rb`, which fails when a tool that writes is missing from its module's `WRITE_TOOLS`
|
|
175
|
+
|
|
176
|
+
#### Usage
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
rails g maquina:oauth # first
|
|
180
|
+
rails g maquina:mcp
|
|
181
|
+
rails db:migrate
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Or all at once: `rails g maquina:app --auth clave --mcp`.
|
|
185
|
+
|
|
186
|
+
#### Options
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
rails g maquina:mcp # Full install
|
|
190
|
+
rails g maquina:mcp --flag beta_mcp # Set the flag in app/models/mcp.rb if it still says FLAG = nil
|
|
191
|
+
rails g maquina:mcp --prefix /account # The Connected apps prefix you gave maquina:oauth (default: /settings)
|
|
192
|
+
rails g maquina:mcp --skip-views # You ran maquina:oauth --skip-views: the flow test skips the consent and Connected apps pages
|
|
193
|
+
rails g maquina:mcp --quiet # No post-install message
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
#### Connecting a client
|
|
197
|
+
|
|
198
|
+
Start the app and run the [MCP Inspector](https://github.com/modelcontextprotocol/inspector):
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
bin/dev
|
|
202
|
+
npx @modelcontextprotocol/inspector
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Choose the Streamable HTTP transport, enter `http://localhost:3000/mcp` and connect. The Inspector discovers the authorization server, sends you to the consent screen (sign in with your email code if needed), and lists `whoami`. The app then shows up at `/settings/connected_apps`, where revoking it makes the next call answer 401.
|
|
206
|
+
|
|
207
|
+
#### Operational tools from other generators
|
|
208
|
+
|
|
209
|
+
When `app/models/mcp/tools.rb` exists, these generators also write an MCP tool module. Every one is `ADMIN_ONLY`: they read data across every account, so only people on the backstage list (`User#backstage_access?`, see [Backstage access](#backstage-access----app-sign-in-or-basic-auth)) see or call them. An account's `admin` role is not enough, since registration makes everyone who signs up the admin of their own account. Anyone else's token gets "unknown tool". Lists are capped at 50 rows and times are ISO 8601 UTC.
|
|
210
|
+
|
|
211
|
+
The tools are read-only unless the generator runs with `--mcp-write`, which adds write tools that need a token with the `write` scope and log each call with the user's id.
|
|
212
|
+
|
|
213
|
+
| Generator | Tool file | Tools |
|
|
214
|
+
|-----------|-----------|-------|
|
|
215
|
+
| `maquina:solid_errors` | `tools/solid_errors.rb` | `list_failures`, `get_failure`, `top_exceptions` (copies `ErrorsQuery`, `FailureTriage` and `ErrorRedactor` into `app/agents/` if missing); `resolve_failure` with `--mcp-write` |
|
|
216
|
+
| `maquina:solid_queue` | `tools/solid_queue.rb` | `queue_status`, `list_failed_jobs`, `get_failed_job` (arguments redacted); `retry_failed_job` and `discard_failed_job` with `--mcp-write` |
|
|
217
|
+
| `maquina:security` | `tools/security.rb` | `recent_blocks`, `security_summary`; `unban_address` with `--mcp-write` (adds `Rack::Attack.unban!` to an initializer written before it existed) |
|
|
218
|
+
| `maquina:csp_reports` | `tools/csp_reports.rb` | `list_csp_reports`, `csp_report_summary` |
|
|
219
|
+
|
|
220
|
+
The install order does not matter. A sibling run after `maquina:mcp` writes its own tool file. `maquina:mcp` run after the siblings backfills a tool file for each one it finds (`config/initializers/solid_errors.rb`, `config/solid_queue.yml` or `config/queue.yml`, `app/models/security/abuse_event.rb`, `csp_violations` in `db/security_schema.rb`), using the read-only variants. Existing tool files are never overwritten (to add the write tools later, delete the file and run the generator again with `--mcp-write`), and without MCP the siblings write and print nothing about it.
|
|
221
|
+
|
|
222
|
+
### MCP Tool -- Add a Tool to the MCP Server
|
|
223
|
+
|
|
224
|
+
**MCP Tool** adds a tool to `app/models/mcp/tools/app.rb`: its JSON Schema definition, a method stub and a test, without editing the registry by hand. It needs `maquina:mcp`.
|
|
225
|
+
|
|
226
|
+
#### Usage
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
rails g maquina:mcp_tool list_posts status:enum[draft,published]? limit:integer?
|
|
230
|
+
rails g maquina:mcp_tool publish_post id:integer --write
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
#### Arguments
|
|
234
|
+
|
|
235
|
+
- `NAME`: lowercase letters, digits and underscores, starting with a letter. A name already in `tools/app.rb` changes nothing; a name in another tool file stops the generator.
|
|
236
|
+
- `name:type`: `string`, `integer`, `number`, `boolean` or `enum[a,b]` (a string limited to those values). A trailing `?` makes the argument optional; every other argument is required.
|
|
237
|
+
|
|
238
|
+
#### Options
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
rails g maquina:mcp_tool NAME [arg:type ...] # Read-only tool (readOnlyHint: true)
|
|
242
|
+
rails g maquina:mcp_tool NAME [arg:type ...] --write # Needs the write scope; added to WRITE_TOOLS
|
|
243
|
+
rails g maquina:mcp_tool NAME --quiet # No "Items to finish" message
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
#### What it generates
|
|
247
|
+
|
|
248
|
+
- The definition in `DEFINITIONS`, the name in `WRITE_TOOLS` with `--write`, and `def self.<name>(scope:, ...)` that raises `Mcp::ToolError, "<name> is not implemented yet"`. If a marker comment in `tools/app.rb` is gone, the snippet is printed instead.
|
|
249
|
+
- `test/models/mcp/tools/<name>_test.rb`: listed for a `read` token, -32602 for a missing required argument, 403 `insufficient_scope` for a `read` token with `--write`, and a skipped cross-user test (a record owned by `users(:mcp_other)` must come back as not found) to fill in.
|
|
250
|
+
|
|
251
|
+
Afterwards, write the description for the model (plain English, units stated), the method body (reach records through `scope.records(:posts)` or `scope.find(:posts, id)` so a tool never sees another user's data) and the cross-user test setup.
|
|
252
|
+
|
|
118
253
|
### Registration -- Password-Based Authentication with Accounts
|
|
119
254
|
|
|
120
255
|
**Registration** generates a password-based authentication system with multi-tenant account support. It builds on top of the Rails 8 authentication generator, adding an Account model (tenant), user roles, and a registration flow.
|
|
@@ -162,6 +297,38 @@ All generated code lives in your app -- edit it directly:
|
|
|
162
297
|
|
|
163
298
|
---
|
|
164
299
|
|
|
300
|
+
### Backstage Access -- App Sign-In or Basic Auth
|
|
301
|
+
|
|
302
|
+
Solid Errors, Mission Control Jobs and Security share one `BackstageController` and one way in.
|
|
303
|
+
|
|
304
|
+
**With the app's own sign-in installed**, Clave's email code (`app/models/email_verification.rb` is there) or Rails' password (`maquina:registration`: `has_secure_password` and a `Session` model), each of them puts the backstage behind it:
|
|
305
|
+
|
|
306
|
+
- `BackstageController` includes `Authentication` and raises `ActiveRecord::RecordNotFound` unless `Current.user.backstage_access?`. Signed out, a page redirects to the sign-in (303 for PATCH/PUT/DELETE, so the engines' Resolve and Discard buttons are not re-sent); signed in but not listed, it is a 404, so the pages never confirm they exist.
|
|
307
|
+
- With Clave, `User.backstage_emails` and `User#backstage_access?` are added to `app/models/user.rb`. Access is an unblocked user whose email is on the list in credentials:
|
|
308
|
+
|
|
309
|
+
```yaml
|
|
310
|
+
backstage:
|
|
311
|
+
emails:
|
|
312
|
+
- you@example.com
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
An empty list is nobody.
|
|
316
|
+
- With Rails' sign-in, a migration adds `accounts.allow_backstage` (boolean, off by default) and `User#backstage_access?` is `account.allow_backstage? && admin?`. Signing up makes you the admin of your own account, so the flag, which only the console sets, is what keeps the backstage closed:
|
|
317
|
+
|
|
318
|
+
```ruby
|
|
319
|
+
Account.find_by!(name: "...").update!(allow_backstage: true)
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
An app's own `backstage_access?` is kept as it is, and a `User` without `admin?` (no role enum) is left for you to fill in.
|
|
323
|
+
- Either way, the same predicate gates the admin-only MCP tools.
|
|
324
|
+
- The Basic Auth comes out of the overview, the Security page and both engines' initializers (Mission Control gets `http_basic_auth_enabled = false`). Do not set `backstage.username` or `password`: Solid Errors turns its Basic Auth back on when a password is set.
|
|
325
|
+
- `test/integration/backstage_access_test.rb` checks signed out, not listed, blocked, an empty list and a listed user (with Rails' sign-in: signed out, not an admin, the flag off and an admin with it on), with `backstage_operator` and `backstage_member` fixtures.
|
|
326
|
+
- A generator run later keeps the backstage on the sign-in. A file you changed by hand keeps its Basic Auth, and the post-install message names it.
|
|
327
|
+
|
|
328
|
+
**Without a sign-in**, the backstage uses HTTP Basic Auth with `backstage.username` / `password` from credentials, or each generator's ENV variables, and answers 503 until they are set.
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
165
332
|
### Solid Errors -- Error Tracking Dashboard
|
|
166
333
|
|
|
167
334
|
**Solid Errors** installs the [solid_errors](https://github.com/fractaledmind/solid_errors) gem with HTTP authentication and engine mounting.
|
|
@@ -169,11 +336,12 @@ All generated code lives in your app -- edit it directly:
|
|
|
169
336
|
#### What it generates
|
|
170
337
|
|
|
171
338
|
- **BackstageController:** Inherits from `ActionController::Base` (bypasses app's ApplicationController concerns)
|
|
172
|
-
- **
|
|
339
|
+
- **Error context:** `config/initializers/error_context.rb`, a Rails error reporter middleware that tags every reported error with its request id, method, path and the signed-in user's and account's ids (ids only). It reads `Current` when the error is reported, so it sees an account a tenant scope sets late, and covers jobs and controllers outside `ApplicationController`. An app installed before 0.11 gets it from `rails g maquina:error_context`, which changes nothing `maquina:solid_errors` would overwrite and replaces the query and tool files only where they are unedited
|
|
340
|
+
- **Initializer:** Database connection config, and Basic Auth from credentials or ENV when the app has no sign-in (see [Backstage access](#backstage-access----app-sign-in-or-basic-auth))
|
|
173
341
|
- **Route:** Mounts `SolidErrors::Engine` at `<prefix>/errors`
|
|
174
342
|
- **Mailer templates:** Self-contained `error_occurred` HTML and text templates, so `send_emails` works without the dashboard's helpers
|
|
175
343
|
- **Admin navigation:** Shared navigation bar with Overview, Errors, Jobs and Security tabs
|
|
176
|
-
- **Admin overview:** `BackstageDashboardController` at the prefix root with cards for each installed dashboard and a `@metrics` slot for your own aggregate counts; answers 503 until backstage credentials are set
|
|
344
|
+
- **Admin overview:** `BackstageDashboardController` at the prefix root with cards for each installed dashboard and a `@metrics` slot for your own aggregate counts; behind the backstage sign-in, or with Basic Auth answers 503 until backstage credentials are set
|
|
177
345
|
- **Custom layout:** Tailwind-styled layout with admin navigation and toast flash messages
|
|
178
346
|
- **Stimulus controllers:** `clipboard_controller.js` and `backtrace_filter_controller.js`
|
|
179
347
|
- **Custom views:** Tailwind-styled views to override the gem defaults (included by default, use `--no-copy-views` to skip)
|
|
@@ -192,17 +360,22 @@ The generator automatically runs `bundle install`. After running, execute `bin/r
|
|
|
192
360
|
```bash
|
|
193
361
|
rails g maquina:solid_errors --prefix /admin # Default (with custom views)
|
|
194
362
|
rails g maquina:solid_errors --prefix /admin --no-copy-views # Without custom views
|
|
363
|
+
rails g maquina:solid_errors --prefix /admin --mcp-write # Also generate the resolve_failure MCP tool
|
|
195
364
|
rails g maquina:solid_errors --prefix /backstage \
|
|
196
365
|
--user-env-var ADMIN_USER --password-env-var ADMIN_PASSWORD # Custom env vars
|
|
197
366
|
```
|
|
198
367
|
|
|
199
368
|
#### Authentication
|
|
200
369
|
|
|
201
|
-
|
|
370
|
+
With the app's sign-in, the backstage gate; see [Backstage access](#backstage-access----app-sign-in-or-basic-auth). Without it, Basic Auth credentials are resolved in order:
|
|
202
371
|
|
|
203
372
|
1. `Rails.application.credentials.backstage.username` / `.password`
|
|
204
373
|
2. `ENV["SOLID_ERRORS_USER"]` / `ENV["SOLID_ERRORS_PASSWORD"]` (configurable)
|
|
205
374
|
|
|
375
|
+
#### MCP
|
|
376
|
+
|
|
377
|
+
With `maquina:mcp` installed, it also writes admin-only MCP tools (`list_failures`, `get_failure`, `top_exceptions`) to `app/models/mcp/tools/solid_errors.rb`. `list_failures` takes `user_id`, `account_id` and `since` (ISO 8601; seven days back by default with a user or account), so you can see the errors one person hit. `--mcp-write` adds `resolve_failure`, which needs the `write` scope. See [Operational tools from other generators](#operational-tools-from-other-generators). The old `--mcp-http` endpoint is gone; `--agent` still generates `bin/failures` and the stdio `bin/failures-mcp`.
|
|
378
|
+
|
|
206
379
|
---
|
|
207
380
|
|
|
208
381
|
### Mission Control Jobs -- Job Queue Dashboard
|
|
@@ -216,7 +389,7 @@ Credentials are resolved in order:
|
|
|
216
389
|
- **Initializer:** Sets base controller class, credentials-first auth with ENV variable fallback
|
|
217
390
|
- **Route:** Mounts `MissionControl::Jobs::Engine` at `<prefix>/jobs`
|
|
218
391
|
- **Admin navigation:** Shared navigation bar with Overview, Errors, Jobs and Security tabs
|
|
219
|
-
- **Admin overview:** `BackstageDashboardController` at the prefix root with cards for each installed dashboard and a `@metrics` slot for your own aggregate counts; answers 503 until backstage credentials are set
|
|
392
|
+
- **Admin overview:** `BackstageDashboardController` at the prefix root with cards for each installed dashboard and a `@metrics` slot for your own aggregate counts; behind the backstage sign-in, or with Basic Auth answers 503 until backstage credentials are set
|
|
220
393
|
- **Custom layout:** Tailwind-styled layout with admin navigation, toast flash messages, application/server selection, and tab navigation
|
|
221
394
|
- **Custom views:** Tailwind-styled views for jobs, queues, workers, and recurring tasks (included by default, use `--no-copy-views` to skip)
|
|
222
395
|
|
|
@@ -240,7 +413,7 @@ rails g maquina:mission_control_jobs --prefix /backstage \
|
|
|
240
413
|
|
|
241
414
|
#### Authentication
|
|
242
415
|
|
|
243
|
-
|
|
416
|
+
With the app's sign-in, the backstage gate; see [Backstage access](#backstage-access----app-sign-in-or-basic-auth). Without it, Basic Auth credentials are resolved in order:
|
|
244
417
|
|
|
245
418
|
1. `Rails.application.credentials.backstage.username` / `.password`
|
|
246
419
|
2. `ENV["MISSION_CONTROL_JOBS_USER"]` / `ENV["MISSION_CONTROL_JOBS_PASSWORD"]` (configurable)
|
|
@@ -271,8 +444,11 @@ The generator automatically runs `bundle install` and installs migrations.
|
|
|
271
444
|
```bash
|
|
272
445
|
rails g maquina:solid_queue # Default (sqlite3)
|
|
273
446
|
rails g maquina:solid_queue --database postgresql # PostgreSQL
|
|
447
|
+
rails g maquina:solid_queue --mcp-write # Also generate the retry_failed_job and discard_failed_job MCP tools
|
|
274
448
|
```
|
|
275
449
|
|
|
450
|
+
With `maquina:mcp` installed, it also writes admin-only MCP tools (`queue_status`, `list_failed_jobs`, `get_failed_job`) to `app/models/mcp/tools/solid_queue.rb`. `--mcp-write` adds `retry_failed_job` and `discard_failed_job`, which need the `write` scope.
|
|
451
|
+
|
|
276
452
|
---
|
|
277
453
|
|
|
278
454
|
### Rack Attack -- Request Protection
|
|
@@ -282,6 +458,7 @@ rails g maquina:solid_queue --database postgresql # PostgreSQL
|
|
|
282
458
|
#### What it generates
|
|
283
459
|
|
|
284
460
|
- **Initializer:** `config/initializers/rack_attack.rb` with the bans, throttles, safelist, 403 responder and an `[ATTACK]` log line per refusal. Its knobs are constants on `Rack::Attack` (`SCANNER_*`, `GENERAL_*`, `FLOOD_*`, `LOGIN_*`) and `Rack::Attack.banned?(ip)` answers whether an address is banned now.
|
|
461
|
+
- **Route guard:** `Rack::Attack.app_route?(path)` answers whether the app itself routes a path.
|
|
285
462
|
|
|
286
463
|
#### Usage
|
|
287
464
|
|
|
@@ -295,6 +472,9 @@ The generator automatically runs `bundle install`.
|
|
|
295
472
|
#### Default Protections
|
|
296
473
|
|
|
297
474
|
- **Scanner ban (Fail2Ban):** three scanner paths in 10 minutes bans the IP for 7 days. Scanner paths are PHP files (`*.php`), WordPress paths (`wp-admin`, `wp-login`, etc.), sensitive files anywhere in the path (`.env`, `.git`, `/etc/passwd`, etc.), backup archives (`.zip`, `.sql`, `.tar.gz`, `.bak`, etc.) and scanner targets (`phpmyadmin`, `cgi-bin`, etc.). `/rails/active_storage` is exempt.
|
|
475
|
+
- The list also names what a modern scanner reaches for first: cloud provider credentials (`service-account.json`, `firebase-adminsdk.json`), container runtime internals (`/var/run/secrets/...`, `/proc/self/environ`), infrastructure as code (`docker-compose.yml`, `terraform.tfstate`), bare secret files (`secrets.json`, `credentials.json`), dev-server artefacts (`__vite_rsc_findSourceMapURL`, `/@fs/...`), source maps, dotfile credentials and encoded path traversal (`..%2F`).
|
|
476
|
+
- The path is unhidden before it is matched, so an encoded traversal is caught like a plain one. A public key is not a private key: `/public_key.pem` is still served.
|
|
477
|
+
- **Route guard:** a scanner rule stands down when the app itself routes the path, so a broad pattern cannot break a real route. A format Rails knows counts as the route, so `/service-worker.js` is `/service-worker(.:format)`, but `/login.php` is not `/login`. A root dynamic segment or catch-all (`/:slug`, `/*path`) does not count, because it would match every path; the app's other routes stay protected.
|
|
298
478
|
- **Flood ban (Allow2Ban):** 600 requests in 5 minutes (twice the general throttle) bans the IP for 1 day.
|
|
299
479
|
- **Throttles:** 300 requests/5min per IP (general; `/assets` and `/rails/active_storage` exempt), 5 `POST /session`/20s per IP
|
|
300
480
|
- **Safelists:** Localhost (`127.0.0.1`, `::1`)
|
|
@@ -347,18 +527,23 @@ The generator automatically runs `bundle install`. The page needs maquina_compon
|
|
|
347
527
|
rails g maquina:security --prefix /admin # Default
|
|
348
528
|
rails g maquina:security --prefix /admin --login-path /sign_in # Different sign-in path
|
|
349
529
|
rails g maquina:security --prefix /admin --no-copy-views # Without views
|
|
530
|
+
rails g maquina:security --prefix /admin --mcp-write # Also generate the unban_address MCP tool
|
|
350
531
|
rails g maquina:security --prefix /backstage \
|
|
351
532
|
--user-env-var ADMIN_USER --password-env-var ADMIN_PASSWORD # Custom env vars
|
|
352
533
|
```
|
|
353
534
|
|
|
354
535
|
#### Authentication
|
|
355
536
|
|
|
356
|
-
HTTP Basic Auth, with credentials resolved in order:
|
|
537
|
+
With the app's sign-in, the backstage gate; see [Backstage access](#backstage-access----app-sign-in-or-basic-auth). Without it, HTTP Basic Auth, with credentials resolved in order:
|
|
357
538
|
|
|
358
539
|
1. `Rails.application.credentials.backstage.username` / `.password`
|
|
359
540
|
2. `ENV["SECURITY_USER"]` / `ENV["SECURITY_PASSWORD"]` (configurable)
|
|
360
541
|
|
|
361
|
-
|
|
542
|
+
With Basic Auth the page answers 503 until one of them is set, so it is never left open.
|
|
543
|
+
|
|
544
|
+
#### MCP
|
|
545
|
+
|
|
546
|
+
With `maquina:mcp` installed, it also writes admin-only MCP tools (`recent_blocks`, `security_summary`). `--mcp-write` adds `unban_address`, which lifts the scanner and flood bans on one address through `Rack::Attack.unban!` and needs the `write` scope.
|
|
362
547
|
|
|
363
548
|
#### Trying it locally
|
|
364
549
|
|
|
@@ -423,7 +608,7 @@ Watch the Security page while the policy is report-only, then set `content_secur
|
|
|
423
608
|
9. Adds turbo morphing, `yield :head`, and simplifies `<main>` tag in layout
|
|
424
609
|
10. Optionally installs authentication (`maquina:clave` or `maquina:registration`)
|
|
425
610
|
11. Invokes sub-generators: `maquina:mission_control_jobs`, `maquina:solid_errors`
|
|
426
|
-
12. Runs external installers: `solid_queue:install`, `solid_errors:install`, `solid_cache:install`, `solid_cable:install`, `maquina_components:install`, then `maquina:security` (which installs the `maquina:rack_attack` rules),
|
|
611
|
+
12. Runs external installers: `solid_queue:install`, `solid_errors:install`, `solid_cache:install`, `solid_cable:install`, `maquina_components:install`, then `maquina:security` (which installs the `maquina:rack_attack` rules), `maquina:passkeys` with `--passkeys`, and `maquina:oauth` plus `maquina:mcp` with `--mcp`
|
|
427
612
|
13. Restores custom layouts overwritten by gem installers
|
|
428
613
|
14. Configures multi-database `database.yml` (primary, queue, cache, cable, errors, security)
|
|
429
614
|
15. Creates a HomeController with root route
|
|
@@ -437,6 +622,8 @@ rails g maquina:app
|
|
|
437
622
|
rails g maquina:app --prefix /backstage --port 3100
|
|
438
623
|
rails g maquina:app --auth registration
|
|
439
624
|
rails g maquina:app --auth clave --passkeys
|
|
625
|
+
rails g maquina:app --auth clave --mcp
|
|
626
|
+
rails g maquina:app --auth clave --mcp --mcp-flag beta_mcp
|
|
440
627
|
```
|
|
441
628
|
|
|
442
629
|
#### Options
|
|
@@ -445,11 +632,13 @@ rails g maquina:app --auth clave --passkeys
|
|
|
445
632
|
- `--port` (default: `3000`) -- Default port for the development server
|
|
446
633
|
- `--auth` (default: `none`) -- Authentication type: `none`, `clave`, or `registration`
|
|
447
634
|
- `--passkeys` (default: `false`) -- Adds passkey sign-in with `maquina:passkeys`. It needs `--auth clave` and refuses to run without it. The passkey origin follows `--port`, and the home page links to `/passkeys`.
|
|
635
|
+
- `--mcp` (default: `false`) -- Adds the OAuth-backed MCP server with `maquina:oauth` and `maquina:mcp`, after Security and Passkeys so the Rack::Attack rules and the admin tools from the other generators land. It needs `--auth clave` and refuses to run without it. The README and post-install message point to `/settings/connected_apps` and the MCP Inspector.
|
|
636
|
+
- `--mcp-flag NAME` -- Passed to both as `--flag NAME`, to gate MCP access behind a feature flag.
|
|
448
637
|
|
|
449
638
|
#### After running
|
|
450
639
|
|
|
451
640
|
```bash
|
|
452
|
-
bin/rails credentials:edit #
|
|
641
|
+
bin/rails credentials:edit # --auth clave: backstage.emails; otherwise backstage username/password
|
|
453
642
|
bin/dev
|
|
454
643
|
```
|
|
455
644
|
|
|
@@ -12,13 +12,18 @@ module Maquina
|
|
|
12
12
|
class_option :auth, type: :string, default: "none",
|
|
13
13
|
desc: "Authentication type: none, clave, or registration"
|
|
14
14
|
class_option :passkeys, type: :boolean, default: false,
|
|
15
|
-
desc: "Add passkey sign-in
|
|
15
|
+
desc: "Add passkey sign-in beside the app's sign-in (requires --auth clave or registration)"
|
|
16
|
+
class_option :mcp, type: :boolean, default: false,
|
|
17
|
+
desc: "Add an OAuth-backed MCP server on the app's sign-in (requires --auth clave or registration)"
|
|
18
|
+
class_option :mcp_flag, type: :string,
|
|
19
|
+
desc: "Feature flag that gates MCP access (e.g. beta_mcp)"
|
|
16
20
|
|
|
17
21
|
# 0. Check options before touching anything
|
|
18
22
|
def check_options
|
|
19
|
-
return
|
|
23
|
+
return if %w[clave registration].include?(options[:auth])
|
|
20
24
|
|
|
21
|
-
raise Thor::Error, "--passkeys builds on
|
|
25
|
+
raise Thor::Error, "--passkeys builds on the app's sign-in. Run with `--auth clave` or `--auth registration`." if options[:passkeys]
|
|
26
|
+
raise Thor::Error, "--mcp builds on the app's sign-in. Run with `--auth clave` or `--auth registration`." if options[:mcp]
|
|
22
27
|
end
|
|
23
28
|
|
|
24
29
|
# 1. Add gems
|
|
@@ -242,6 +247,16 @@ module Maquina
|
|
|
242
247
|
'"http://localhost:3000"', %("http://localhost:#{options[:port]}")
|
|
243
248
|
end
|
|
244
249
|
|
|
250
|
+
# 12d. Install the MCP server (after security and passkeys, so the
|
|
251
|
+
# Rack::Attack rules and every sibling tool marker already exist)
|
|
252
|
+
def install_mcp
|
|
253
|
+
return unless options[:mcp] && rails_app?
|
|
254
|
+
|
|
255
|
+
flag = options[:mcp_flag].to_s.empty? ? [] : ["--flag", options[:mcp_flag]]
|
|
256
|
+
generate "maquina:oauth", "--quiet", *flag
|
|
257
|
+
generate "maquina:mcp", "--quiet", *flag
|
|
258
|
+
end
|
|
259
|
+
|
|
245
260
|
# 13. Restore custom layouts overwritten by gem installers
|
|
246
261
|
def restore_custom_layouts
|
|
247
262
|
return unless rails_app?
|
|
@@ -346,10 +361,20 @@ module Maquina
|
|
|
346
361
|
say "=" * 60, :green
|
|
347
362
|
say ""
|
|
348
363
|
say "Next steps:", :yellow
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
364
|
+
if options[:auth] == "clave"
|
|
365
|
+
say " 1. Set credentials: bin/rails credentials:edit"
|
|
366
|
+
say " backstage:"
|
|
367
|
+
say " emails:"
|
|
368
|
+
say " - you@example.com # who may open #{options[:prefix]} (signed in with Clave)"
|
|
369
|
+
elsif options[:auth] == "registration"
|
|
370
|
+
say " 1. Sign up, then let your account's admins open #{options[:prefix]} (bin/rails console):"
|
|
371
|
+
say " Account.find_by!(name: \"...\").update!(allow_backstage: true)"
|
|
372
|
+
else
|
|
373
|
+
say " 1. Set credentials: bin/rails credentials:edit"
|
|
374
|
+
say " backstage:"
|
|
375
|
+
say " username: your_user"
|
|
376
|
+
say " password: your_password"
|
|
377
|
+
end
|
|
353
378
|
say " 2. Start the app: bin/dev"
|
|
354
379
|
say ""
|
|
355
380
|
say "Installed components:", :yellow
|
|
@@ -370,6 +395,12 @@ module Maquina
|
|
|
370
395
|
say " - Visit /passkeys to add a passkey"
|
|
371
396
|
say " - Production: set WEBAUTHN_RP_ID and WEBAUTHN_ORIGINS before the first passkey"
|
|
372
397
|
end
|
|
398
|
+
if options[:mcp]
|
|
399
|
+
say " - Visit /settings/connected_apps to see and revoke connected AI apps"
|
|
400
|
+
say " - Connect an MCP client: npx @modelcontextprotocol/inspector"
|
|
401
|
+
say " and point it at http://localhost:#{options[:port]}/mcp"
|
|
402
|
+
say " - MCP access is gated by the #{options[:mcp_flag]} flag (app/models/mcp.rb)" unless options[:mcp_flag].to_s.empty?
|
|
403
|
+
end
|
|
373
404
|
say " - Customize: app/controllers/concerns/authentication.rb"
|
|
374
405
|
say " - Locales: config/locales/"
|
|
375
406
|
end
|
|
@@ -29,6 +29,9 @@ Your app will be running at **http://localhost:<%= options[:port] %>**.
|
|
|
29
29
|
<% if options[:passkeys] -%>
|
|
30
30
|
| **Passkeys** | Passkey sign-in with Face ID, a fingerprint or a device PIN; the email code stays as the way in without one |
|
|
31
31
|
<% end -%>
|
|
32
|
+
<% if options[:mcp] -%>
|
|
33
|
+
| **MCP Server** | OAuth 2.1-backed MCP server at `/mcp` for AI clients, with a Connected apps page to revoke them<%= " (gated by the `#{options[:mcp_flag]}` flag)" unless options[:mcp_flag].to_s.empty? %> |
|
|
34
|
+
<% end -%>
|
|
32
35
|
| **Background Jobs** | Solid Queue with Mission Control Jobs dashboard |
|
|
33
36
|
| **Error Tracking** | Solid Errors with custom UI |
|
|
34
37
|
| **Rate Limiting** | Rack::Attack with sensible defaults |
|
|
@@ -58,6 +61,10 @@ Your app will be running at **http://localhost:<%= options[:port] %>**.
|
|
|
58
61
|
<% if options[:passkeys] -%>
|
|
59
62
|
| http://localhost:<%= options[:port] %>/passkeys | Passkeys |
|
|
60
63
|
<% end -%>
|
|
64
|
+
<% if options[:mcp] -%>
|
|
65
|
+
| http://localhost:<%= options[:port] %>/settings/connected_apps | Connected apps |
|
|
66
|
+
| http://localhost:<%= options[:port] %>/mcp | MCP endpoint (`npx @modelcontextprotocol/inspector`) |
|
|
67
|
+
<% end -%>
|
|
61
68
|
<% end -%>
|
|
62
69
|
|
|
63
70
|
## Scripts
|
|
@@ -73,6 +80,19 @@ Edit credentials with:
|
|
|
73
80
|
bin/rails credentials:edit
|
|
74
81
|
```
|
|
75
82
|
|
|
83
|
+
<% if options[:auth] == "clave" -%>
|
|
84
|
+
The admin dashboards (overview, errors, jobs, security) are behind the app's sign-in. List who may open them; anyone else gets a 404:
|
|
85
|
+
|
|
86
|
+
```yaml
|
|
87
|
+
backstage:
|
|
88
|
+
emails:
|
|
89
|
+
- you@example.com
|
|
90
|
+
```
|
|
91
|
+
<% if options[:mcp] -%>
|
|
92
|
+
|
|
93
|
+
The same list decides who sees the admin-only MCP tools (errors, jobs, security).
|
|
94
|
+
<% end -%>
|
|
95
|
+
<% else -%>
|
|
76
96
|
Add backstage credentials for the admin dashboards (overview, errors, jobs, security):
|
|
77
97
|
|
|
78
98
|
```yaml
|
|
@@ -80,6 +100,7 @@ backstage:
|
|
|
80
100
|
username: your_user
|
|
81
101
|
password: your_password
|
|
82
102
|
```
|
|
103
|
+
<% end -%>
|
|
83
104
|
|
|
84
105
|
## Maquina Ecosystem
|
|
85
106
|
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
<%%= render "components/card" do %>
|
|
66
66
|
<%%= render "components/card/header" do %>
|
|
67
67
|
<div class="flex items-center gap-2">
|
|
68
|
-
|
|
68
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="size-5 text-primary" aria-hidden="true"><path d="M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"/><path d="m9 12 2 2 4-4"/></svg>
|
|
69
69
|
<%%= render "components/card/title", text: "Security" %>
|
|
70
70
|
</div>
|
|
71
71
|
<%%= render "components/card/description", text: "See what Rack::Attack throttled, blocked, and banned this week." %>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module Maquina
|
|
2
|
+
module Generators
|
|
3
|
+
# Which sign-in the app has, for the generators that build on it (oauth,
|
|
4
|
+
# passkeys, mcp and the backstage sign-in):
|
|
5
|
+
#
|
|
6
|
+
# - :clave, maquina:clave's email code. Its User can be blocked (blocked?,
|
|
7
|
+
# block!), and who opens the backstage is a list of emails in credentials.
|
|
8
|
+
# - :rails, Rails' authentication generator (maquina:registration): a
|
|
9
|
+
# password, a Session record and Account-owned users with a role. It has
|
|
10
|
+
# no blocking, and who opens the backstage is an admin of an account with
|
|
11
|
+
# allow_backstage on.
|
|
12
|
+
#
|
|
13
|
+
# Every method is private: a public method on a generator is a Thor step.
|
|
14
|
+
module AuthFlavor
|
|
15
|
+
AUTHENTICATION_CONCERN = "app/controllers/concerns/authentication.rb"
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def auth_flavor
|
|
20
|
+
return @auth_flavor if defined?(@auth_flavor)
|
|
21
|
+
|
|
22
|
+
@auth_flavor = if !auth_file?(AUTHENTICATION_CONCERN) then nil
|
|
23
|
+
elsif auth_file?("app/models/email_verification.rb") then :clave
|
|
24
|
+
elsif auth_file?("app/models/session.rb") && auth_file_include?("app/models/user.rb", "has_secure_password") then :rails
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def clave? = auth_flavor == :clave
|
|
29
|
+
|
|
30
|
+
def rails_auth? = auth_flavor == :rails
|
|
31
|
+
|
|
32
|
+
# The registration generator's `enum :role` (member/admin), which gives
|
|
33
|
+
# User#admin? and the role column a fixture can set.
|
|
34
|
+
def user_role_enum? = auth_file_include?("app/models/user.rb", /enum :role\b/)
|
|
35
|
+
|
|
36
|
+
def require_authentication!(generator)
|
|
37
|
+
return if auth_flavor
|
|
38
|
+
|
|
39
|
+
raise Thor::Error, "maquina:#{generator} needs the app's sign-in. Run `rails g maquina:clave` " \
|
|
40
|
+
"(email code) or `rails g maquina:registration` (password) first."
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# A fixture user who can sign in: Clave's sign in by email code, Rails'
|
|
44
|
+
# need a password digest, and a role when the User has the enum.
|
|
45
|
+
def auth_fixture_attributes(role:)
|
|
46
|
+
attributes = {}
|
|
47
|
+
attributes["password_digest"] = %(<%= BCrypt::Password.create("password") %>) if rails_auth?
|
|
48
|
+
attributes["role"] = role if clave? || user_role_enum?
|
|
49
|
+
attributes
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def auth_file?(path) = File.exist?(File.join(destination_root, path))
|
|
53
|
+
|
|
54
|
+
def auth_file_include?(path, text)
|
|
55
|
+
auth_file?(path) && File.read(File.join(destination_root, path)).match?(text)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|