Class: Llmemory::MCP::Authentication
- Inherits:
-
Object
- Object
- Llmemory::MCP::Authentication
- Defined in:
- lib/llmemory/mcp/authentication.rb
Overview
Rack middleware for token-based authentication Validates requests against MCP_TOKEN environment variable
Constant Summary collapse
- UNAUTHORIZED_RESPONSE =
[ 401, { "Content-Type" => "application/json" }, ['{"error":"Unauthorized: Invalid or missing token"}'] ].freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, token: nil) ⇒ Authentication
constructor
A new instance of Authentication.
Constructor Details
#initialize(app, token: nil) ⇒ Authentication
Returns a new instance of Authentication.
16 17 18 19 |
# File 'lib/llmemory/mcp/authentication.rb', line 16 def initialize(app, token: nil) @app = app @token = token || ENV["MCP_TOKEN"] end |
Instance Method Details
#call(env) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/llmemory/mcp/authentication.rb', line 21 def call(env) return @app.call(env) unless @token return UNAUTHORIZED_RESPONSE unless valid_token?(env) @app.call(env) end |