feat: MCP lock enforcement + UI/tests
Summary
Implements MCP server management locking by enforcing authentication gates on the v2 MCP server write endpoints that the Langflow UI actually calls. Non-admin users are blocked at both the backend (403) and the frontend (locked modal state).
Changes
Backend
- Add
mcp_servers_lockedgate to POST/api/v2/mcp/servers/{server_name}(add server) - Add
mcp_servers_lockedgate to PATCH/api/v2/mcp/servers/{server_name}(update server) - Add
mcp_servers_lockedgate to DELETE/api/v2/mcp/servers/{server_name}(remove server) - Non-superuser requests blocked with 403 Forbidden when flag is enabled
mcp_servers_lockedfield declared inSettingsmodel (env var:LANGFLOW_MCP_SERVERS_LOCKED)- Hardened checks using
getattr(..., False) is Truepattern to handle mocked settings in tests
Note on v1 endpoints: The v1
POST /{project_id}/installendpoint writes MCP client config files onto the user's local machine (for Cursor/Windsurf/Claude). This is a distinct operation from managing external MCP server entries in Langflow and is intentionally not gated here. The current UI does not call v1 for MCP server CRUD — all add/edit/delete operations go through v2.
Frontend
- Update
AddMcpServerModalto show locked state message whenmcp_servers_lockedis active - Fix JSX structure (fragment wrapper for proper nesting)
Security
- Prevents non-admin users from adding/modifying/removing external MCP servers via the UI path (v2)
- ContextForge remains single secure ingress for MCP configuration
Type
Security/Feature
Related
Part 2 of 4 in LE-906 split (supersedes combined PR #13089) Addresses: MCP lock coverage incomplete — gate moved to v2 endpoints which the UI actually uses
[!IMPORTANT]
Review skipped
Auto incremental reviews are disabled on this repository.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID:
74838f97-d85c-4b26-8948-35c8a82b6b22You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- [ ] 🔍 Trigger review
Walkthrough
This PR adds MCP server management locking to prevent non-superusers from modifying external MCP server settings when locked. The backend provides a lock-detection helper and authorization gates; the frontend shows a lock-state modal with localized text in eight languages when the feature is active.
Changes
MCP Server Management Lock
| Layer / File(s) | Summary |
|---|---|
Backend lock detection and validation src/backend/base/langflow/api/v1/mcp_projects.py, src/backend/tests/unit/api/v1/test_mcp_projects.py |
Introduces is_mcp_servers_locked(settings) helper that explicitly checks settings.mcp_servers_locked to avoid MagicMock truthy defaults. Unit tests validate correct behavior for both locked and unlocked cases. |
Backend authorization gates for locked servers src/backend/base/langflow/api/v1/mcp_projects.py |
Adds authorization checks in update_project_mcp_settings and install_mcp_config endpoints that return HTTP 403 with an admin-contact message when MCP servers are locked and the caller is not a superuser. |
Locked state UI localization src/frontend/src/locales/en.json, src/frontend/src/locales/de.json, src/frontend/src/locales/es.json, src/frontend/src/locales/fr.json, src/frontend/src/locales/ja.json, src/frontend/src/locales/pt.json, src/frontend/src/locales/zh-Hans.json |
Adds mcp.modal.lockedTitle and mcp.modal.lockedDescription translation keys across eight locales for the locked-management UI state. |
Modal conditional locked-state rendering src/frontend/src/modals/addMcpServerModal/index.tsx |
Updates AddMcpServerModal to read mcpServersLocked and isAdmin from global stores, computing isModalLocked, and conditionally renders a locked-state UI instead of the form when the lock is active for non-admin users. |
🎯 3 (Moderate) | ⏱️ ~20 minutes
[!IMPORTANT]
Pre-merge checks failed
Please resolve all errors before merging. Addressing warnings is optional.
❌ Failed checks (1 error, 3 warnings)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Test Coverage For New Implementations | ❌ Error | New authorization gates (403 responses) in update_project_mcp_settings and install_mcp_config lack tests. AddMcpServerModal locked UI also lacks tests. Only is_mcp_servers_locked has 2 tests. | Add tests verifying 403 responses from endpoints when mcp_servers_locked=true for non-superusers, and tests for AddMcpServerModal locked UI rendering. |
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
| Test Quality And Coverage | ⚠️ Warning | PR tests lack coverage for 403 authorization gates on endpoints and locked modal UI. Only 2 unit tests validate the helper function; missing are endpoint 403 tests and frontend locked state tests. | Add integration tests for 403 responses when mcp_servers_locked=True, and frontend tests for locked-state modal rendering when mcpServersLocked and !isAdmin. |
| Test File Naming And Structure | ⚠️ Warning | Tests lack coverage for new lock enforcement gates: no tests verify 403 responses when locked for non-superusers, frontend locked UI state untested, and endpoint authorization gates uncovered. | Add tests verifying 403 responses for non-superusers when locked (update/install endpoints), superuser bypass, and frontend locked modal state to cover edge cases and positive/negative scenarios. |
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title 'feat: MCP lock enforcement + UI/tests' directly and clearly summarizes the main change: adding MCP server locking enforcement alongside UI updates and tests. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Excessive Mock Usage Warning | ✅ Passed | New tests appropriately use mocks: one tests a designed edge case with MagicMock, the other uses SimpleNamespace. Both are minimal unit tests of a pure function with no excessive mocking. |
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
✨ Finishing Touches
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Commit unit tests in branch
feature/le-906-pr2-mcp-lock
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 help to get the list of available commands and usage tips.
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 57.62%. Comparing base (6049fe0) to head (895cba2).
Additional details and impacted files
@@ Coverage Diff @@
## release-1.10.0 #13097 +/- ##
==================================================
- Coverage 57.63% 57.62% -0.01%
==================================================
Files 2264 2264
Lines 216093 216101 +8
Branches 32309 30565 -1744
==================================================
- Hits 124543 124526 -17
- Misses 90134 90160 +26
+ Partials 1416 1415 -1
| Flag | Coverage Δ | |
|---|---|---|
| backend | 64.72% <100.00%> (-0.07%) |
:arrow_down: |
| frontend | 56.99% <ø> (+<0.01%) |
:arrow_up: |
| lfx | 52.86% <ø> (+<0.01%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Files with missing lines | Coverage Δ | |
|---|---|---|
| src/backend/base/langflow/api/v2/mcp.py | 59.37% <100.00%> (+4.11%) |
:arrow_up: |
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Frontend Unit Test Coverage Report
Coverage Summary
| Lines | Statements | Branches | Functions |
|---|---|---|---|
| 42% (55450/132006) | 69.22% (7539/10890) | 40.75% (1249/3065) |
Unit Test Results
| Tests | Skipped | Failures | Errors | Time |
|---|---|---|---|---|
| 4848 | 0 :zzz: | 0 :x: | 0 :fire: | 12m 1s :stopwatch: |
Hey @vjgit96, great work on the lock enforcement logic — the helper, the v2 endpoint checks, and the UI state all look solid. One thing I noticed while testing locally though: the lock never actually activates. is_mcp_servers_locked() uses getattr(settings, "mcp_servers_locked", False) is True, which means it safely defaults to False when the attribute doesn't exist — but mcp_servers_locked was never declared in the settings model: https://github.com/langflow-ai/langflow/blob/release-1.10.0/src/lfx/src/lfx/services/settings/base.py#L402-L408 Without a field declaration there, extra="ignore" on the Pydantic model silently drops any LANGFLOW_MCP_SERVERS_LOCKED env var passed at startup, so there's no way to turn this on in production. The entire feature — endpoints, UI, tests — is in place but permanently disabled.
Was there something I missed?
@andifilhohub Thanks, you were right. mcp_servers_locked wasn’t declared in Settings, so env-based activation could be dropped. I pushed a fix to declare the field and added a regression test that verifies LANGFLOW_MCP_SERVERS_LOCKED=true is honored.
✅ Test Coverage Advisor
No source changes detected without accompanying tests. Thanks for keeping coverage up! 🎉
Advisory check only — never blocks merge.