Class: Otto::MCP::Auth::TokenMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/otto/mcp/auth/token.rb

Overview

Middleware for token authentication in MCP protocol

Instance Method Summary collapse

Constructor Details

#initialize(app, security_config = nil) ⇒ TokenMiddleware

Returns a new instance of TokenMiddleware.



37
38
39
40
# File 'lib/otto/mcp/auth/token.rb', line 37

def initialize(app, security_config = nil)
  @app             = app
  @security_config = security_config
end

Instance Method Details

#call(env) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/otto/mcp/auth/token.rb', line 42

def call(env)
  # Only apply to MCP endpoints
  return @app.call(env) unless mcp_endpoint?(env)

  # Get auth instance from security config
  auth = @security_config&.mcp_auth
  return unauthorized_response if auth && !auth.authenticate(env)

  @app.call(env)
end