MCP

OAuth endpoints for MCP clients.

This page documents the current Ruby port behavior. Ruby uses snake_case option names and auth.api method names; HTTP paths and JSON keys keep the upstream wire shape where implemented.

Some UI or provider-specific setup from upstream is app-provided in Ruby. The protocol endpoints below are implemented, but you must supply your own pages, callbacks, client objects, or provider metadata where noted by the option names.

Configure

config/auth.rb
require "better_auth"

auth = BetterAuth.auth(
  secret: ENV.fetch("BETTER_AUTH_SECRET"),
  base_url: ENV.fetch("BETTER_AUTH_URL", "http://localhost:3000"),
  plugins: [
    BetterAuth::Plugins.mcp(resource: "https://api.example.com/mcp", login_page: "/login")
  ]
)

Usage

server.rb
server = auth.api.get_mcp_o_auth_config
resource = auth.api.get_mcp_protected_resource

token = auth.api.mcp_o_auth_token(
  body: {
    grant_type: "authorization_code",
    code: params[:code],
    client_id: client_id
  }
)

Routes

MethodPathRuby API method
GET/.well-known/oauth-authorization-serverauth.api.get_mcp_o_auth_config
GET/.well-known/oauth-protected-resourceauth.api.get_mcp_protected_resource
POST/mcp/registerauth.api.mcp_register
GET/mcp/authorizeauth.api.mcp_o_auth_authorize
POST/mcp/tokenauth.api.mcp_o_auth_token
GET/mcp/userinfoauth.api.mcp_o_auth_user_info

Options

Current Ruby options accepted by BetterAuth::Plugins.mcp:

  • scopes
  • oidc_config
  • resource
  • login_page
  • store

Support Notes

  • The examples above are based on Ruby plugin source and tests in packages/better_auth.
  • If an upstream section is not represented here, treat it as not yet documented or not yet supported by the Ruby port until the matching Ruby implementation exists.

On this page