-
Notifications
You must be signed in to change notification settings - Fork 0
CMP-354 | Add an MCP generator to bootstrap an MCP server with Oauth #187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
justwiebe
merged 22 commits into
master
from
cmp-354-add-generator-for-bootstrapping-an-mcp-server
Apr 3, 2026
Merged
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
c6ce875
CMP-354 | Add an MCP generator to bootstrap an MCP server with Oauth
justwiebe 96bd9fa
Update logo
justwiebe b58ce2c
Templatize templates
justwiebe 0c8f581
Update lib/generators/rolemodel/mcp/templates/app/views/layouts/doork…
justwiebe 8896578
Update lib/generators/rolemodel/mcp/USAGE
justwiebe a09a9ed
Update lib/generators/rolemodel/mcp/README.md
justwiebe 625d1a4
Code review and add some sample resources, tools, and prompts
justwiebe 5a81a16
Update auth
justwiebe 6d9b45b
Try adding doorkeeper to the gemfile
justwiebe 490ea38
Add the handler
justwiebe fd59d22
Uncapture stderr
justwiebe ab6e59a
Fix tests?
justwiebe 2a14f4c
fix
justwiebe 0b6fdd9
re-arrange
justwiebe 0c54718
Try again?
justwiebe f879a88
Add logging
justwiebe 828d6f2
More logging
justwiebe 7c6d272
MOAR
justwiebe 20f1ea4
Add mcp?
justwiebe 83b8697
update
justwiebe 0758b44
Rename doc handlers to controllers
justwiebe c1bedd3
Revert
justwiebe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # MCP Generator | ||
|
|
||
| Install boilerplate for your very own MCP server. | ||
|
|
||
| ## What you get | ||
|
|
||
| ### Doorkeeper | ||
|
|
||
| Oauth 2.1-enabled flow with dynamic application registration. | ||
|
|
||
| ### MCP | ||
|
|
||
| A basic MCP controller that you can build on to serve tools, resources, and prompts. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| Description: | ||
| Sets up our standard ActionMailer configuration with layout using CSS base styles | ||
|
|
||
| Example: | ||
| rails generate rolemodel:mailers | ||
|
|
||
| This will create: | ||
| app/javascript/packs/mailer_stylesheets.scss | ||
| app/mailers/user_mailer.rb | ||
| app/views/layouts/mailer.html.slim | ||
| app/views/user_mailer/welcome_email.html.slim | ||
| config/initializers/premailer_rails.rb | ||
| public/logo.png | ||
| spec/mailers/previews/user_preview.rb | ||
|
|
||
| This will modify: | ||
| config/environments/development.rb | ||
| config/environments/production.rb | ||
|
|
||
| This will remove: | ||
| app/views/layouts/mailer.html.erb | ||
| app/views/layouts/mailer.text.erb | ||
justwiebe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Rolemodel | ||
| class MCPGenerator < BaseGenerator | ||
| source_root File.expand_path('templates', __dir__) | ||
|
|
||
| def install_mcp | ||
| bundle_command 'add mcp' | ||
| template 'app/controllers/mcp_controller.rb' | ||
justwiebe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| copy_file 'spec/requests/mcp_controller_spec.rb' | ||
|
|
||
| route <<~RUBY | ||
| match '/mcp', to: 'mcp#handle', via: %i[get post delete] | ||
| RUBY | ||
| end | ||
|
|
||
| def install_doorkeeper | ||
| bundle_command 'add doorkeeper' | ||
| generate 'doorkeeper:install' | ||
| end | ||
|
|
||
| def configure_doorkeeper | ||
| copy_file 'config/initializers/doorkeeper.rb', force: true | ||
| copy_file 'app/controllers/doorkeeper/base_controller.rb' | ||
|
|
||
| copy_file 'app/views/layouts/doorkeeper.html.slim' | ||
| template 'app/views/doorkeeper/authorizations/new.html.slim' | ||
| template 'app/views/doorkeeper/authorizations/error.html.slim' | ||
justwiebe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| copy_file 'app/assets/stylesheets/components/doorkeeper.css' | ||
|
|
||
| route 'use_doorkeeper' | ||
| end | ||
|
|
||
| def apply_doorkeeper_css | ||
| css_manifest = if File.exist?(File.join(destination_root, 'app/assets/stylesheets/application.scss')) | ||
| 'app/assets/stylesheets/application.scss' | ||
| else | ||
| 'app/assets/stylesheets/application.css' | ||
| end | ||
|
|
||
| return if File.read(File.join(destination_root, css_manifest)).include?("@import 'components/doorkeeper.css';") | ||
|
|
||
| append_to_file css_manifest, <<~CSS | ||
| @import 'components/doorkeeper.css'; | ||
| CSS | ||
| end | ||
|
|
||
justwiebe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def add_oauth_dynamic_registrations | ||
| copy_file 'app/controllers/oauth_registrations_controller.rb' | ||
| copy_file 'spec/requests/oauth_registrations_controller_spec.rb' | ||
| route <<~RUBY | ||
| post '/oauth/register', to: 'oauth_registrations#create' | ||
| RUBY | ||
| end | ||
|
|
||
| def add_well_known_route | ||
| copy_file 'app/controllers/well_known_controller.rb' | ||
| copy_file 'spec/requests/well_known_controller_spec.rb' | ||
| route <<~RUBY | ||
| get '/.well-known/oauth-protected-resource', to: 'well_known#oauth_protected_resource' | ||
| get '/.well-known/oauth-authorization-server', to: 'well_known#oauth_authorization_server' | ||
| RUBY | ||
| end | ||
|
|
||
| def update_inflections | ||
| inflections_path = File.join(destination_root, 'config/initializers/inflections.rb') | ||
| block_start = "\nActiveSupport::Inflector.inflections(:en) do |inflect|\n" | ||
|
|
||
| return if File.read(inflections_path).include?("inflect.acronym 'MCP'") | ||
|
|
||
| if File.read(inflections_path).include?(block_start) | ||
| inject_into_file inflections_path, " inflect.acronym 'MCP'\n", after: block_start | ||
| else | ||
| append_to_file inflections_path, <<~RUBY | ||
|
|
||
| ActiveSupport::Inflector.inflections(:en) do |inflect| | ||
| inflect.acronym 'MCP' | ||
| end | ||
| RUBY | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def application_name | ||
| Rails.application.class.try(:parent_name) || Rails.application.class.module_parent_name | ||
| end | ||
| end | ||
| end | ||
140 changes: 140 additions & 0 deletions
140
lib/generators/rolemodel/mcp/templates/app/assets/stylesheets/components/doorkeeper.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| .doorkeeper { | ||
| position: fixed; | ||
| inset: 0; | ||
| box-sizing: border-box; | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| padding: var(--op-space-x-large) var(--op-space-large); | ||
| overflow: auto; | ||
| background-color: var(--op-color-neutral-plus-eight); | ||
| color: var(--op-color-neutral-minus-max); | ||
| font-family: var(--op-font-family); | ||
| } | ||
|
|
||
| .doorkeeper__card { | ||
| width: min(100%, 48rem); | ||
| background-color: var(--op-color-white); | ||
| border: var(--op-border-width) solid var(--op-color-neutral-plus-six); | ||
| border-radius: var(--op-radius-x-large); | ||
| box-shadow: var(--op-shadow-large); | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: var(--op-space-large); | ||
| padding: var(--op-space-2x-large); | ||
| } | ||
|
|
||
| .doorkeeper__brand { | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| gap: var(--op-space-large); | ||
| margin-bottom: var(--op-space-small); | ||
| } | ||
|
|
||
| .doorkeeper__logo { | ||
| width: 180px; | ||
| height: auto; | ||
| } | ||
|
|
||
| .doorkeeper__title { | ||
| margin: 0; | ||
| font-size: var(--op-font-2x-large); | ||
| font-weight: var(--op-font-weight-bold); | ||
| color: var(--op-color-primary-minus-two); | ||
| text-align: center; | ||
| letter-spacing: -0.04em; | ||
| } | ||
|
|
||
| .doorkeeper__prompt { | ||
| margin: 0; | ||
| font-size: var(--op-font-large); | ||
| line-height: var(--op-line-height-loose); | ||
| color: var(--op-color-neutral-minus-three); | ||
| text-align: center; | ||
| } | ||
|
|
||
| .doorkeeper__client-name { | ||
| color: var(--op-color-primary-base); | ||
| font-weight: var(--op-font-weight-bold); | ||
| } | ||
|
|
||
| .doorkeeper__permissions { | ||
| background-color: var(--op-color-primary-plus-eight); | ||
| border: var(--op-border-width) solid var(--op-color-primary-plus-six); | ||
| border-radius: var(--op-radius-medium); | ||
| padding: var(--op-space-large); | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: var(--op-space-medium); | ||
| } | ||
|
|
||
| .doorkeeper__permissions-label { | ||
| margin: 0; | ||
| font-size: var(--op-font-small); | ||
| text-transform: uppercase; | ||
| letter-spacing: 0.05em; | ||
| font-weight: var(--op-font-weight-bold); | ||
| color: var(--op-color-primary-minus-three); | ||
| } | ||
|
|
||
| .doorkeeper__scope-list { | ||
| margin: 0; | ||
| padding-left: var(--op-space-large); | ||
| display: grid; | ||
| gap: var(--op-space-small); | ||
| color: var(--op-color-primary-minus-max); | ||
| } | ||
|
|
||
| .doorkeeper__scope-item { | ||
| line-height: var(--op-line-height-base); | ||
| font-weight: var(--op-font-weight-medium); | ||
| } | ||
|
|
||
| .doorkeeper__actions { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: var(--op-space-medium); | ||
| margin-top: var(--op-space-medium); | ||
| } | ||
|
|
||
| .doorkeeper__error { | ||
| align-self: stretch; | ||
| } | ||
|
|
||
| .doorkeeper__error-description { | ||
| margin: 0; | ||
| font-size: var(--op-font-medium); | ||
| line-height: var(--op-line-height-base); | ||
| white-space: pre-wrap; | ||
| overflow-wrap: anywhere; | ||
| } | ||
|
|
||
| .doorkeeper__form { | ||
| margin: 0; | ||
| } | ||
|
|
||
| .doorkeeper__button { | ||
| width: 100%; | ||
| justify-content: center; | ||
| font-weight: var(--op-font-weight-semi-bold); | ||
| } | ||
|
|
||
| @media (max-width: 640px) { | ||
| .doorkeeper { | ||
| padding: var(--op-space-large) var(--op-space-medium); | ||
| } | ||
|
|
||
| .doorkeeper__card { | ||
| padding: var(--op-space-large); | ||
| border-radius: var(--op-radius-large); | ||
| } | ||
|
|
||
| .doorkeeper__logo { | ||
| width: 140px; | ||
| } | ||
|
|
||
| .doorkeeper__title { | ||
| font-size: var(--op-font-x-large); | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
lib/generators/rolemodel/mcp/templates/app/controllers/doorkeeper/base_controller.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Doorkeeper | ||
| class BaseController < ::ApplicationController | ||
| skip_before_action :authenticate_oauth, raise: false | ||
| skip_forgery_protection | ||
justwiebe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.