Skip to content

fix: store mcp sse headers and use them on connection#9148

Merged
lucaseduoli merged 15 commits into
mainfrom
fix/mcp_headers_storing
Jul 26, 2025
Merged

fix: store mcp sse headers and use them on connection#9148
lucaseduoli merged 15 commits into
mainfrom
fix/mcp_headers_storing

Conversation

@lucaseduoli
Copy link
Copy Markdown
Collaborator

@lucaseduoli lucaseduoli commented Jul 23, 2025

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:

  • Enhanced URL Validation and Redirection:
    • Updated validate_url and pre_check_redirect methods in src/backend/base/langflow/base/mcp/util.py to accept and utilize headers for 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))
    • Adjusted _connect_to_server to pass headers to 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:

    • Updated useAddMCPServer and usePatchMCPServer in src/frontend/src/controllers/API/queries/mcp/ to include headers in 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:

    • Modified extractMcpServersFromJson in src/frontend/src/utils/mcpUtils.ts to extract headers from 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

    • Added support for including custom headers when adding or updating MCP servers.
    • MCP server objects now display and store headers if provided.
  • Bug Fixes

    • Improved handling of MCP server data to ensure headers are correctly extracted and included where applicable.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 23, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The 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 headers field as part of the server payload and validation logic. No changes to error handling or control flow were made.

Changes

Files/Paths Change Summary
src/backend/base/langflow/base/mcp/util.py Updated validate_url and pre_check_redirect methods in MCPSseClient to accept and merge optional headers.
src/frontend/src/controllers/API/queries/mcp/use-add-mcp-server.ts Modified to conditionally include headers in the payload when adding an MCP server.
src/frontend/src/controllers/API/queries/mcp/use-patch-mcp-server.ts Modified to conditionally include headers in the payload when patching an MCP server.
src/frontend/src/utils/mcpUtils.ts Updated extractMcpServersFromJson to extract and include a headers field in returned server objects.

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
Loading

Estimated code review effort

2 (~15 minutes)

Possibly related PRs

Suggested labels

bug, size:M, lgtm

Suggested reviewers

  • mfortman11
  • ogabrielluiz
  • edwinjosechittilappilly
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/mcp_headers_storing

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions Bot added the bug Something isn't working label Jul 23, 2025
@lucaseduoli lucaseduoli linked an issue Jul 23, 2025 that may be closed by this pull request
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jul 23, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9e24202 and 3253824.

📒 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.ts
  • src/frontend/src/controllers/API/queries/mcp/use-add-mcp-server.ts
  • src/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.ts
  • src/frontend/src/controllers/API/queries/mcp/use-add-mcp-server.ts
  • src/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 env field, 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_redirect method signature matches the pattern established in validate_url.


977-977: Headers properly integrated in redirect check.

Consistent implementation with the validation method.

Comment thread src/backend/base/langflow/base/mcp/util.py Outdated
@lucaseduoli lucaseduoli enabled auto-merge July 23, 2025 13:30
Copy link
Copy Markdown
Member

@Cristhianzl Cristhianzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add tests to validate this change?

@SonicDMG SonicDMG temporarily deployed to fix/mcp_headers_storing - langflow-manual-install PR #9148 July 24, 2025 21:51 — with Render Destroyed
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jul 24, 2025
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jul 24, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 24, 2025

Build successful! ✅
Deploying docs draft.
Deploy successful! View draft

@SonicDMG SonicDMG temporarily deployed to fix/mcp_headers_storing - langflow-manual-install PR #9148 July 24, 2025 22:25 — with Render Destroyed
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jul 24, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 24, 2025

Build successful! ✅
Deploying docs draft.
Deploy successful! View draft

@SonicDMG SonicDMG temporarily deployed to fix/mcp_headers_storing - langflow-manual-install PR #9148 July 26, 2025 00:55 — with Render Destroyed
@SonicDMG SonicDMG temporarily deployed to fix/mcp_headers_storing - langflow-manual-install PR #9148 July 26, 2025 00:56 — with Render Destroyed
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jul 26, 2025
@SonicDMG SonicDMG temporarily deployed to fix/mcp_headers_storing - langflow-manual-install PR #9148 July 26, 2025 00:57 — with Render Destroyed
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jul 26, 2025
@SonicDMG SonicDMG temporarily deployed to fix/mcp_headers_storing - langflow-manual-install PR #9148 July 26, 2025 00:58 — with Render Destroyed
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jul 26, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 26, 2025

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 82%
81.44% (373/458) 64.82% (223/344) 67.69% (44/65)

Unit Test Results

Tests Skipped Failures Errors Time
93 0 💤 0 ❌ 0 🔥 3.009s ⏱️

@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52.43%. Comparing base (324caf4) to head (2dfec89).
⚠️ Report is 1 commits behind head on main.

❌ 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

Impacted file tree graph

@@            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              
Flag Coverage Δ
backend 52.27% <100.00%> (+0.60%) ⬆️
frontend 69.41% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/backend/base/langflow/base/mcp/util.py 46.97% <100.00%> (+36.22%) ⬆️

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@SonicDMG SonicDMG temporarily deployed to fix/mcp_headers_storing - langflow-manual-install PR #9148 July 26, 2025 01:02 — with Render Destroyed
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jul 26, 2025
@lucaseduoli lucaseduoli added this pull request to the merge queue Jul 26, 2025
Merged via the queue into main with commit 41e1014 Jul 26, 2025
71 of 72 checks passed
@lucaseduoli lucaseduoli deleted the fix/mcp_headers_storing branch July 26, 2025 01:29
edwinjosechittilappilly added a commit that referenced this pull request Jul 28, 2025
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
2getsandesh pushed a commit to 2getsandesh/langflow-IBM that referenced this pull request Aug 6, 2025
* 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>
HimavarshaVS pushed a commit that referenced this pull request Oct 21, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Headers are not being saved for MCP Server SSE

3 participants