Add Proc and Array support for auth_token#175
Open
kpheasey wants to merge 5 commits into
Open
Conversation
- Initialize method now evaluates Proc auth tokens and stores result - valid_token? method checks for token existence in Array auth tokens - Maintains backward compatibility with existing string tokens 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Cover the multi-token authentication changes: Proc resolution at initialization (single string, array, and nil return values) and Array-based token validation via include? matching. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Update all documentation, YARD docstrings, examples, and generator templates to reflect that auth_token accepts a String, Array of Strings, or a Proc that returns either. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
auth_tokento accept a Proc (evaluated once at initialization) in addition to a static string, enabling dynamic token resolution from environment variables or secrets managersauth_tokento accept an Array of Strings, so multiple valid tokens can authenticate against the same serverMotivation
In production deployments, it's common to need multiple valid API tokens (e.g., during token rotation, or when multiple clients each have their own token). It's also useful to resolve tokens dynamically from environment variables or a secrets manager rather than hardcoding them. This change enables both patterns with minimal API surface change.
Changes
lib/mcp/transports/authenticated_rack_transport.rb— Resolve Proc at init, check Array viainclude?spec/mcp/transports/authenticated_rack_transport_spec.rb— 15 new tests (38 total, all passing)README.md,docs/security.md— Expanded authentication docs with exampleslib/fast_mcp.rb— Updated YARD@optiondocstringsexamples/authenticated_rack_middleware.rb— Added usage commentsexamples/rails-demo-app/config/initializers/fast_mcp.rb— Updated commentlib/generators/fast_mcp/install/templates/fast_mcp_initializer.rb— Updated generator templateUsage
Test plan