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.
14 15 16 17 |
# File 'lib/llmemory/mcp/authentication.rb', line 14 def initialize(app, token: nil) @app = app @token = token || ENV["MCP_TOKEN"] end |
Instance Method Details
#call(env) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/llmemory/mcp/authentication.rb', line 19 def call(env) # If no token is configured, skip authentication return @app.call(env) unless @token # Check for valid token return UNAUTHORIZED_RESPONSE unless valid_token?(env) @app.call(env) end |