fix: store mcp sse headers and use them on connection#9148
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 WalkthroughThe changes introduce support for passing and handling custom HTTP headers when adding, patching, and validating MCP server connections. Both backend methods and frontend utilities/controllers are updated to accept, propagate, and serialize a Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Frontend
participant Backend
User->>Frontend: Submit MCP server add/patch form (with optional headers)
Frontend->>Backend: POST/PATCH MCP server (payload includes headers if provided)
Backend->>Backend: validate_url(url, headers)
Backend->>Backend: pre_check_redirect(url, headers)
Backend-->>Frontend: Response (success/failure)
Frontend-->>User: Display result
Estimated code review effort2 (~15 minutes) Possibly related PRs
Suggested labels
Suggested reviewers
✨ Finishing Touches🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/backend/base/langflow/base/mcp/util.py(4 hunks)src/frontend/src/controllers/API/queries/mcp/use-add-mcp-server.ts(2 hunks)src/frontend/src/controllers/API/queries/mcp/use-patch-mcp-server.ts(2 hunks)src/frontend/src/utils/mcpUtils.ts(1 hunks)
📓 Path-based instructions (3)
{src/backend/**/*.py,tests/**/*.py,Makefile}
📄 CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)
{src/backend/**/*.py,tests/**/*.py,Makefile}: Run make format_backend to format Python code before linting or committing changes
Run make lint to perform linting checks on backend Python code
Files:
src/backend/base/langflow/base/mcp/util.py
src/frontend/src/**/*.{ts,tsx,js,jsx}
📄 CodeRabbit Inference Engine (.cursor/rules/frontend_development.mdc)
src/frontend/src/**/*.{ts,tsx,js,jsx}: All frontend TypeScript and JavaScript code should be located under src/frontend/src/ and organized into components, pages, icons, stores, types, utils, hooks, services, and assets directories as per the specified directory layout.
Use React 18 with TypeScript for all UI components in the frontend.
Format all TypeScript and JavaScript code using the make format_frontend command.
Lint all TypeScript and JavaScript code using the make lint command.
Files:
src/frontend/src/utils/mcpUtils.tssrc/frontend/src/controllers/API/queries/mcp/use-add-mcp-server.tssrc/frontend/src/controllers/API/queries/mcp/use-patch-mcp-server.ts
src/frontend/src/utils/**/*.{ts,tsx,js,jsx}
📄 CodeRabbit Inference Engine (.cursor/rules/frontend_development.mdc)
All utility functions should be placed in the utils directory.
Files:
src/frontend/src/utils/mcpUtils.ts
🧠 Learnings (2)
src/frontend/src/controllers/API/queries/mcp/use-add-mcp-server.ts (1)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-23T12:46:42.048Z
Learning: Error handling for API calls in React should be abstracted into custom hooks (e.g., useApi), which manage loading and error state and expose an execute function for invoking the API.
src/frontend/src/controllers/API/queries/mcp/use-patch-mcp-server.ts (2)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/frontend/**/*.@(test|spec).{ts,tsx,js,jsx} : Mock external dependencies appropriately in frontend test files to isolate unit tests from external services.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-23T12:46:42.048Z
Learning: Error handling for API calls in React should be abstracted into custom hooks (e.g., useApi), which manage loading and error state and expose an execute function for invoking the API.
🧰 Additional context used
📓 Path-based instructions (3)
{src/backend/**/*.py,tests/**/*.py,Makefile}
📄 CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)
{src/backend/**/*.py,tests/**/*.py,Makefile}: Run make format_backend to format Python code before linting or committing changes
Run make lint to perform linting checks on backend Python code
Files:
src/backend/base/langflow/base/mcp/util.py
src/frontend/src/**/*.{ts,tsx,js,jsx}
📄 CodeRabbit Inference Engine (.cursor/rules/frontend_development.mdc)
src/frontend/src/**/*.{ts,tsx,js,jsx}: All frontend TypeScript and JavaScript code should be located under src/frontend/src/ and organized into components, pages, icons, stores, types, utils, hooks, services, and assets directories as per the specified directory layout.
Use React 18 with TypeScript for all UI components in the frontend.
Format all TypeScript and JavaScript code using the make format_frontend command.
Lint all TypeScript and JavaScript code using the make lint command.
Files:
src/frontend/src/utils/mcpUtils.tssrc/frontend/src/controllers/API/queries/mcp/use-add-mcp-server.tssrc/frontend/src/controllers/API/queries/mcp/use-patch-mcp-server.ts
src/frontend/src/utils/**/*.{ts,tsx,js,jsx}
📄 CodeRabbit Inference Engine (.cursor/rules/frontend_development.mdc)
All utility functions should be placed in the utils directory.
Files:
src/frontend/src/utils/mcpUtils.ts
🧠 Learnings (2)
src/frontend/src/controllers/API/queries/mcp/use-add-mcp-server.ts (1)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-23T12:46:42.048Z
Learning: Error handling for API calls in React should be abstracted into custom hooks (e.g., useApi), which manage loading and error state and expose an execute function for invoking the API.
src/frontend/src/controllers/API/queries/mcp/use-patch-mcp-server.ts (2)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/frontend/**/*.@(test|spec).{ts,tsx,js,jsx} : Mock external dependencies appropriately in frontend test files to isolate unit tests from external services.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-23T12:46:42.048Z
Learning: Error handling for API calls in React should be abstracted into custom hooks (e.g., useApi), which manage loading and error state and expose an execute function for invoking the API.
🔇 Additional comments (9)
src/frontend/src/controllers/API/queries/mcp/use-add-mcp-server.ts (2)
37-39: LGTM! Consistent implementation pattern.The conditional headers inclusion follows the same pattern as other optional fields (
args,env) and properly validates that headers exist and are non-empty before adding to the payload.
3-3: Import reordering looks good.The import reorganization places external library imports appropriately.
src/frontend/src/utils/mcpUtils.ts (1)
98-98: LGTM! Consistent with existing pattern.The headers extraction follows the same defensive pattern as the
envfield, with proper type checking and safe defaults.src/frontend/src/controllers/API/queries/mcp/use-patch-mcp-server.ts (2)
37-39: LGTM! Consistent with add server implementation.The headers inclusion follows the exact same pattern as
use-add-mcp-server.ts, ensuring consistency across the codebase.
3-3: Import reordering approved.Consistent with the organizational changes in the add server hook.
src/backend/base/langflow/base/mcp/util.py (4)
927-927: LGTM! Proper method signature with optional headers.The method signature correctly adds optional headers parameter with proper type hints.
938-938: Headers integration looks good.The headers are properly merged into the HTTP request using the spread operator, with appropriate fallback handling.
970-970: Consistent method signature update.The
pre_check_redirectmethod signature matches the pattern established invalidate_url.
977-977: Headers properly integrated in redirect check.Consistent implementation with the validation method.
Cristhianzl
left a comment
There was a problem hiding this comment.
can we add tests to validate this change?
|
Build successful! ✅ |
|
Build successful! ✅ |
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project status has failed because the head coverage (52.43%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #9148 +/- ##
==========================================
+ Coverage 51.83% 52.43% +0.59%
==========================================
Files 633 633
Lines 43397 43422 +25
Branches 125 125
==========================================
+ Hits 22496 22768 +272
+ Misses 20851 20604 -247
Partials 50 50
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Edwin Jose <edwin.jose@datastax.com> Co-authored-by: Cristhian Zanforlin Lousa <cristhian.lousa@gmail.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> Co-authored-by: Lucas Oliveira <62335616+lucaseduoli@users.noreply.github.com> Co-authored-by: Rodrigo Nader <rodrigosilvanader@gmail.com> Co-authored-by: Deon Sanchez <69873175+deon-sanchez@users.noreply.github.com> Co-authored-by: April I. Murphy <36110273+aimurphy@users.noreply.github.com> Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com> Co-authored-by: Yuqi Tang <yuqi.tang@datastax.com> fix: store mcp sse headers and use them on connection (#9148) fix: prevent unintentional sidebar text selection (#8895) fix: Exclude base path from custom component loading (#9098) fix.py): remove unnecessary test case for GitHub issue #8967 and fix test_component_merging_logic method to handle custom component loading failure properly
* Store mcp server headers * Add headers on pre check url and is valid url * adds validation of headers according to RFC 7230 * Fixed sanitized value * Added backend tests for mcp util.py to increase coverage * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes (attempt 2/3) * make key pair input use flatmap id on data test ids * added testids * added random test names and added tests for persistence * fix ruff lint * [autofix.ci] apply automated fixes * Fix mypy lint errors --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Edwin Jose <edwin.jose@datastax.com> Co-authored-by: Cristhian Zanforlin Lousa <cristhian.lousa@gmail.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> Co-authored-by: Lucas Oliveira <62335616+lucaseduoli@users.noreply.github.com> Co-authored-by: Rodrigo Nader <rodrigosilvanader@gmail.com> Co-authored-by: Deon Sanchez <69873175+deon-sanchez@users.noreply.github.com> Co-authored-by: April I. Murphy <36110273+aimurphy@users.noreply.github.com> Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com> Co-authored-by: Yuqi Tang <yuqi.tang@datastax.com> fix: store mcp sse headers and use them on connection (#9148) fix: prevent unintentional sidebar text selection (#8895) fix: Exclude base path from custom component loading (#9098) fix.py): remove unnecessary test case for GitHub issue #8967 and fix test_component_merging_logic method to handle custom component loading failure properly
This pull request introduces support for custom headers in MCP server interactions, including validation, redirection, and API requests. Key changes span both backend and frontend, ensuring headers can be passed, processed, and utilized effectively.
Backend Changes:
validate_urlandpre_check_redirectmethods insrc/backend/base/langflow/base/mcp/util.pyto accept and utilizeheadersfor HTTP requests. ([[1]](https://github.com/langflow-ai/langflow/pull/9148/files#diff-37c079efebed1e9da327c409abb8b1b6ec68d70c6a2a98885f0e1a11c087283cL927-R927),[[2]](https://github.com/langflow-ai/langflow/pull/9148/files#diff-37c079efebed1e9da327c409abb8b1b6ec68d70c6a2a98885f0e1a11c087283cL938-R938),[[3]](https://github.com/langflow-ai/langflow/pull/9148/files#diff-37c079efebed1e9da327c409abb8b1b6ec68d70c6a2a98885f0e1a11c087283cL970-R977))_connect_to_serverto passheadersto these methods. ([src/backend/base/langflow/base/mcp/util.pyL998-R1003](https://github.com/langflow-ai/langflow/pull/9148/files#diff-37c079efebed1e9da327c409abb8b1b6ec68d70c6a2a98885f0e1a11c087283cL998-R1003))Frontend Changes:
API Enhancements:
useAddMCPServerandusePatchMCPServerinsrc/frontend/src/controllers/API/queries/mcp/to includeheadersin the payload if provided. ([[1]](https://github.com/langflow-ai/langflow/pull/9148/files#diff-eb3556b7e2327e8f9a70e5a8c0a225e1a96a351cd725a88b94a31f3560ee1292R37-R39),[[2]](https://github.com/langflow-ai/langflow/pull/9148/files#diff-0ed4637c835049341bff01ad5d2f8c2f61192c42bc6b3f3dfce6846cb0338189R37-R39))Utility Update:
extractMcpServersFromJsoninsrc/frontend/src/utils/mcpUtils.tsto extractheadersfrom JSON input, ensuring they are properly parsed. ([src/frontend/src/utils/mcpUtils.tsR98](https://github.com/langflow-ai/langflow/pull/9148/files#diff-59d3c671587ae8007fa0c5be5fc91e7a23274e39e654770a16ee0510c6adb9adR98))Summary by CodeRabbit
New Features
Bug Fixes