feat: Add global variable support for MCP server headers#11300
feat: Add global variable support for MCP server headers#11300jordanrfrazier merged 57 commits intolangflow-ai:mainfrom
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThis PR adds global variable support to MCP server configurations. It enables runtime retrieval and decryption of global variables from the database, then resolves them in HTTP headers during MCP server initialization across frontend and backend layers. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Frontend
participant API
participant Database
participant Utility
participant Tools
User->>Frontend: Selects global variable for header value
Frontend->>Frontend: Stores selection with key-pair data
Frontend->>API: Sends MCP server config with header key-pairs
API->>Database: Query global variables for user
Database-->>API: Return encrypted variable records
API->>API: Decrypt variables via auth_utils
API->>Utility: Call update_tools with request_variables
Utility->>Utility: Resolve header values against request_variables
Utility-->>Tools: Pass resolved headers to tool initialization
Tools-->>API: Return initialized tools
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error, 2 warnings)
✅ Passed checks (4 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai how does the review look now with the latest changes? |
|
✅ Actions performedReview triggered.
|
- Add IOKeyPairInputWithVariables component for header inputs with global variable dropdown - Integrate global variable selection in MCP Server modal - Add variable resolution in MCP server headers (_resolve_global_variables_in_headers) - Add variable loading and decryption in MCP API endpoint and component - Add unit tests for variable resolution utility function
…mponent - Add 15 test cases covering rendering, user interactions, and edge cases - Test global variable dropdown functionality and selection - Test row addition/removal and input validation - Test duplicate key detection and error handling - Test initialization from existing values with variable badges - Addresses CodeRabbit review feedback for frontend test coverage
eba6c5d to
d672260
Compare
- Added proper mocks for IconComponent, InputComponent, and Input - Used explicit TypeScript types instead of 'any' for mock props - Fixed test assertions to match actual component structure (Type key.../Type a value... placeholders) - All 8 tests now pass without console warnings - Tests cover: rendering, onChange callbacks, add/delete buttons, global variables toggle
The session_scope import was moved inside _process_headers method, which broke unit tests that mock it at the module level. Restored it to module-level imports with noqa comment to prevent ruff from removing it, and removed the duplicate import from inside the method. Fixes: test_database_config_used_when_no_value_config
…hangs - Update GlobalVariableModal to handle None credential values - Allow credential updates without re-entering value - Fix userSettings test by using dispatchEvent for clicks - Add waitForTimeout after clicks to prevent hangs - Use .first() for Fields selectors to avoid strict mode violations
- Resolved conflicts in userSettings.spec.ts by adopting upstream's trySelectAvailableField() approach and .ag-cell locators - Removed duplicate useEffect in GlobalVariableModal.tsx, keeping upstream's [initialData] dependency version - Upstream already includes the conditional value inclusion logic we implemented
Address code review feedback: 1. Increase log level from debug to warning when decryption fails in auth/utils.py. Returning empty string silently could cause issues, so warning level makes failures more visible. 2. Follow established pattern in mcp.py for variable decryption: - Only decrypt CREDENTIAL type variables (encrypted in storage) - Use GENERIC type variables as-is (stored as plaintext) - Change from silent fallback (adebug) to explicit error (aerror) - This matches the pattern in get_all_decrypted_variables() These changes make error handling more explicit and consistent across the codebase.
Resolved conflict in component_index.json by accepting upstream version.


Description
Adds support for using global variables (both GENERIC and CREDENTIAL types) in MCP server headers, allowing users to securely reference API keys and other sensitive values without hardcoding them.
Changes
Frontend
IOKeyPairInputWithVariablescomponent extending key-pair input with global variable dropdownaddMcpServerModalto use the new component for HTTP headersBackend
_resolve_global_variables_in_headers()utility function for exact-match variable resolution/api/v2/mcp/settings/testendpoint to load and decrypt global variablesMCPComponentto load variables from graph context or database with decryption fallbackauth_utils.decrypt_api_key()Testing
test_mcp_util.pyHow It Works
x-api-key: MY_API_KEY)Testing Done
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.