Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/ruby_llm/mcp/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def expires_soon?
# Format token for Authorization header
# @return [String] formatted as "Bearer {access_token}"
def to_header
"#{@token_type} #{@access_token}"
token_type = @token_type.to_s.strip
token_type = "Bearer" if token_type.empty? || token_type.casecmp("bearer").zero?
"#{token_type} #{@access_token}"
end

# Serialize token to hash
Expand Down
25 changes: 25 additions & 0 deletions spec/ruby_llm/mcp/auth/token_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require "spec_helper"

RSpec.describe RubyLLM::MCP::Auth::Token do
describe "#to_header" do
it "formats default bearer token type" do
token = described_class.new(access_token: "abc123")

expect(token.to_header).to eq("Bearer abc123")
end

it "normalizes lowercase bearer token type to canonical Bearer" do
token = described_class.new(access_token: "abc123", token_type: "bearer")

expect(token.to_header).to eq("Bearer abc123")
end

it "preserves non-bearer token types" do
token = described_class.new(access_token: "abc123", token_type: "DPoP")

expect(token.to_header).to eq("DPoP abc123")
end
end
end