Skip to content

Conversation

@smatiolids
Copy link
Contributor

@smatiolids smatiolids commented Dec 15, 2025

Enhance MCP Integration – Transform All Inputs into MCP Parameters
Key Updates

Inputs: Add mcp_description and mcp_required fields to Chat and Text components.
List Tools: Expose all component inputs as tool arguments.
Call Tool: Convert arguments into tweaks using component IDs.

How It Works

Input Parameters

The same parameters apply to both Chat Input and Text Input components:

Screenshot 2025-12-15 at 14 08 40

Flow with two inputs:

Screenshot 2025-12-15 at 14 09 04

Flow as a Tool.

Note the description presented with input parameters:

Screenshot 2025-12-15 at 14 10 59

Tool execution:

Example with both parameters filled:

Screenshot 2025-12-15 at 14 14 01

Suggested for review

@edwinjosechittilappilly

Summary by CodeRabbit

  • New Features
    • Added MCP Description and MCP Required configuration options to Chat Input and Text Input components for enhanced metadata support
    • Improved MCP field handling in flow schema generation and input argument processing for better workflow execution

✏️ Tip: You can customize this high-level summary in your review settings.

…d' inputs in Chat and Text components, update flow processing to handle new input structure, and refactor argument transformation for improved clarity.
@github-actions github-actions bot added the community Pull Request from an external contributor label Dec 15, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 15, 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

These changes introduce MCP (Model Context Protocol) support by adding metadata fields to input components, refactoring the flow schema generation to handle MCP-specific field mappings, and transforming argument handling in the MCP utilities layer to use a tweaks-based approach instead of direct input value propagation.

Changes

Cohort / File(s) Change Summary
Input Component Enhancements
src/lfx/src/lfx/components/input_output/chat.py, src/lfx/src/lfx/components/input_output/text.py
Added two new advanced input fields (mcp_description and mcp_required) to ChatInput and TextInputComponent to expose MCP metadata configuration. TextInputComponent also imports BoolInput.
Flow Schema Generation
src/backend/base/langflow/helpers/flow.py
Replaced generic field-type inference logic with targeted MCP field handling. Now inspects input nodes and conditionally processes mcp_description, mcp_type, and mcp_required fields, removing legacy type mapping and validation for non-MCP fields.
MCP Argument Transformation
src/backend/base/langflow/api/v1/mcp_utils.py
Replaced direct input_value propagation with a transform_arguments step that converts inputs into a tweaks map, where each key maps to {"input_value": value}. Input request construction now uses session_id and tweaks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • src/backend/base/langflow/helpers/flow.py: Significant refactoring of schema generation logic; verify that MCP field handling correctly replaces the removed legacy type inference without breaking non-MCP workflows.
  • src/backend/base/langflow/api/v1/mcp_utils.py: Logic change in argument transformation; confirm that the tweaks-based approach integrates properly with downstream flow execution and session handling.
  • Input component changes: Verify that the new MCP fields integrate with the schema generation logic and are properly serialized/deserialized.

Pre-merge checks and finishing touches

❌ Failed checks (1 error, 3 warnings)
Check name Status Explanation Resolution
Test Coverage For New Implementations ❌ Error PR introduces significant MCP integration across four source files but contains no corresponding test files, and a critical bug in mcp_type field handling was identified. Add comprehensive test coverage for json_schema_from_flow(), mcp_utils.py argument transformation, and MCP input fields. Fix the mcp_type bug before finalizing tests.
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Test Quality And Coverage ⚠️ Warning Pull request introduces significant functional MCP integration changes across four files but includes zero new tests, with a confirmed bug in mcp_type field assignment. Add comprehensive pytest test cases: create unit tests for json_schema_from_flow function, mcp_utils argument transformation, integration tests for MCP tool parameter flow, and edge case tests before merging.
Test File Naming And Structure ⚠️ Warning PR modifies production code files without including corresponding test files following test_*.py or *.test.ts naming patterns for validation. Add backend tests (test_.py) for mcp_utils.py and flow.py changes, and frontend tests (.test.ts) for chat.py and text.py component modifications to validate new MCP functionality.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Excessive Mock Usage Warning ✅ Passed PR modifies source code files only; no test files added or modified, so excessive mock usage assessment is not applicable.
Title check ✅ Passed The title accurately summarizes the main change: adding MCP (Model Context Protocol) parameters to all component inputs, which aligns with the file modifications adding mcp_description and mcp_required fields to Chat/Text components and transforming inputs into MCP tool arguments.

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@ogabrielluiz ogabrielluiz changed the title Enhance MCP Integration – Transform All Inputs into MCP Parameters feat: Transform All Component Inputs into MCP Parameters Dec 15, 2025
@ogabrielluiz ogabrielluiz requested a review from Copilot December 15, 2025 17:25
@github-actions github-actions bot added the enhancement New feature or request label Dec 15, 2025
Copy link
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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 53015c1 and c433e9d.

📒 Files selected for processing (4)
  • src/backend/base/langflow/api/v1/mcp_utils.py (2 hunks)
  • src/backend/base/langflow/helpers/flow.py (1 hunks)
  • src/lfx/src/lfx/components/input_output/chat.py (1 hunks)
  • src/lfx/src/lfx/components/input_output/text.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/backend/**/*.py

📄 CodeRabbit inference engine (.cursor/rules/backend_development.mdc)

src/backend/**/*.py: Use FastAPI async patterns with await for async operations in component execution methods
Use asyncio.create_task() for background tasks and implement proper cleanup with try/except for asyncio.CancelledError
Use queue.put_nowait() for non-blocking queue operations and asyncio.wait_for() with timeouts for controlled get operations

Files:

  • src/backend/base/langflow/helpers/flow.py
  • src/backend/base/langflow/api/v1/mcp_utils.py
src/backend/base/langflow/api/**/*.py

📄 CodeRabbit inference engine (.cursor/rules/backend_development.mdc)

Backend API endpoints should be organized by version (v1/, v2/) under src/backend/base/langflow/api/ with specific modules for features (chat.py, flows.py, users.py, etc.)

Files:

  • src/backend/base/langflow/api/v1/mcp_utils.py
🧠 Learnings (1)
📓 Common learnings
Learnt from: ogabrielluiz
Repo: langflow-ai/langflow PR: 0
File: :0-0
Timestamp: 2025-06-26T19:43:18.260Z
Learning: In langflow custom components, the `module_name` parameter is now propagated through template building functions to add module metadata and code hashes to frontend nodes for better component tracking and debugging.
🧬 Code graph analysis (3)
src/lfx/src/lfx/components/input_output/text.py (2)
src/lfx/src/lfx/inputs/inputs.py (2)
  • BoolInput (419-432)
  • MultilineInput (261-271)
src/lfx/src/lfx/template/field/base.py (1)
  • Output (181-260)
src/lfx/src/lfx/components/input_output/chat.py (1)
src/lfx/src/lfx/inputs/inputs.py (2)
  • MultilineInput (261-271)
  • BoolInput (419-432)
src/backend/base/langflow/api/v1/mcp_utils.py (1)
src/lfx/src/lfx/base/tools/flow_tool.py (1)
  • args (32-34)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (23)
  • GitHub Check: Run Frontend Tests / Playwright Tests - Shard 2/9
  • GitHub Check: Run Frontend Tests / Playwright Tests - Shard 6/9
  • GitHub Check: Run Frontend Tests / Playwright Tests - Shard 3/9
  • GitHub Check: Run Frontend Tests / Playwright Tests - Shard 8/9
  • GitHub Check: Run Frontend Tests / Playwright Tests - Shard 5/9
  • GitHub Check: Run Frontend Tests / Playwright Tests - Shard 1/9
  • GitHub Check: Run Frontend Tests / Playwright Tests - Shard 7/9
  • GitHub Check: Lint Backend / Run Mypy (3.12)
  • GitHub Check: Run Backend Tests / LFX Tests - Python 3.10
  • GitHub Check: Lint Backend / Run Mypy (3.13)
  • GitHub Check: Lint Backend / Run Mypy (3.10)
  • GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 1
  • GitHub Check: Lint Backend / Run Mypy (3.11)
  • GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 4
  • GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 2
  • GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 5
  • GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 3
  • GitHub Check: Run Backend Tests / Integration Tests - Python 3.10
  • GitHub Check: Test Docker Images / Test docker images
  • GitHub Check: Test Starter Templates
  • GitHub Check: Optimize new Python code in this PR
  • GitHub Check: Run Ruff Check and Format
  • GitHub Check: Update Component Index
🔇 Additional comments (3)
src/backend/base/langflow/api/v1/mcp_utils.py (1)

195-210: MCP arguments → tweaks mapping looks good; verify SimplifiedAPIRequest contract

The new transform_arguments correctly wraps each MCP argument as {node_id: {"input_value": value}}, which matches the tweaks shape used by run_flow in helpers/flow.py and keeps node IDs aligned with json_schema_from_flow. The SimplifiedAPIRequest now relies solely on session_id and tweaks (with input_value commented out), so please ensure the Pydantic model has been updated to make input_value optional and to fully support this tweaks‑only path to avoid validation errors at runtime.

src/lfx/src/lfx/components/input_output/text.py (1)

2-23: MCP metadata inputs on TextInput are consistent and non‑breaking

Adding mcp_description and mcp_required as advanced inputs cleanly exposes MCP metadata without changing runtime behavior; their names and types line up with json_schema_from_flow’s MCP handling, so this should integrate smoothly.

src/lfx/src/lfx/components/input_output/chat.py (1)

79-82: ChatInput MCP fields mirror TextInput and align with schema logic

The added mcp_description and mcp_required fields are correctly typed, advanced‑only, and named to match the MCP schema builder, so they should expose MCP metadata for chat inputs without impacting existing behavior.

Comment on lines 452 to 469
name = node.data["id"]

template = node_data["template"]

properties[name] = {"type": "string", "description": f"Input for {name}"}

for field_name, field_data in template.items():
if field_data != "Component" and field_data.get("show", False) and not field_data.get("advanced", False):
field_type = field_data.get("type", "string")
properties[field_name] = {
"type": field_type,
"description": field_data.get("info", f"Input for {field_name}"),
}
# Update field_type in properties after determining the JSON Schema type
if field_type == "str":
field_type = "string"
elif field_type == "int":
field_type = "integer"
elif field_type == "float":
field_type = "number"
elif field_type == "bool":
field_type = "boolean"
else:
logger.warning(f"Unknown field type: {field_type} defaulting to string")
field_type = "string"
properties[field_name]["type"] = field_type

if field_data.get("required", False):
required.append(field_name)
if field_name.startswith("mcp_"):
if field_name == "mcp_description":
val = field_data.get("value")
properties[name]["description"] = val or f"Input for {name}"

if field_name == "mcp_type" and field_data.get("value") != "":
val = field_data.get("value")
properties[name]["description"] = val or f"Input for {name}"

if field_name == "mcp_required" and field_data.get("value", False):
required.append(name)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, verify the file exists and check its size
wc -l src/backend/base/langflow/helpers/flow.py

Repository: langflow-ai/langflow

Length of output: 109


🏁 Script executed:

# Read lines around 452-469 with context
sed -n '440,480p' src/backend/base/langflow/helpers/flow.py | cat -n

Repository: langflow-ai/langflow

Length of output: 1575


🏁 Script executed:

# Find the function containing this code
grep -n "def json_schema_from_flow" src/backend/base/langflow/helpers/flow.py

Repository: langflow-ai/langflow

Length of output: 114


🏁 Script executed:

# Search for other references to mcp_type, mcp_description, mcp_required in the codebase
rg "mcp_type|mcp_description|mcp_required" --type py -B 2 -A 2

Repository: langflow-ai/langflow

Length of output: 2515


🏁 Script executed:

# Search for mcp_type field definition more broadly
rg "mcp_type" --type py -B 5 -A 5

Repository: langflow-ai/langflow

Length of output: 1092


🏁 Script executed:

# Check the input_output components more thoroughly for mcp_type definition
fd "input_output" --type d | head -5

Repository: langflow-ai/langflow

Length of output: 104


🏁 Script executed:

# Look for any definition or initialization of mcp_type across the codebase
rg "name.*mcp_type|mcp_type.*name" --type py -B 2 -A 2

Repository: langflow-ai/langflow

Length of output: 565


🏁 Script executed:

# Check the text.py and chat.py component files for complete field definitions
cat -n src/lfx/src/lfx/components/input_output/text.py | head -80

Repository: langflow-ai/langflow

Length of output: 1303


🏁 Script executed:

# Check if mcp_type is defined anywhere in the input components
grep -rn "mcp_type" src/lfx/src/lfx/components/input_output/

Repository: langflow-ai/langflow

Length of output: 46


🏁 Script executed:

# Look at text component to see what fields are actually defined
sed -n '1,150p' src/lfx/src/lfx/components/input_output/text.py

Repository: langflow-ai/langflow

Length of output: 1086


🏁 Script executed:

# Check the chat component to see if mcp_type is defined there
cat src/lfx/src/lfx/components/input_output/chat.py | head -80

Repository: langflow-ai/langflow

Length of output: 2578


🏁 Script executed:

# Search for any file that defines mcp_type as a field
rg "MultilineInput.*mcp_type|StringInput.*mcp_type|.*Input.*mcp_type" --type py -B 2 -A 2

Repository: langflow-ai/langflow

Length of output: 46


🏁 Script executed:

# Check if there are any other component files in input_output directory
fd -e py src/lfx/src/lfx/components/input_output/

Repository: langflow-ai/langflow

Length of output: 529


🏁 Script executed:

# Check all Python files for mcp_type mentions
fd -e py . | xargs grep -l "mcp_type" 2>/dev/null

Repository: langflow-ai/langflow

Length of output: 105


🏁 Script executed:

# Look at the complete chat.py file to find all inputs
cat src/lfx/src/lfx/components/input_output/chat.py | grep -A 100 "inputs = \["

Repository: langflow-ai/langflow

Length of output: 3130


🏁 Script executed:

# Search for JSON schema type examples to understand intended behavior
rg "type.*string|\"type\"" src/backend/base/langflow/helpers/flow.py -B 2 -A 2

Repository: langflow-ai/langflow

Length of output: 599


🏁 Script executed:

# Check if there's documentation or tests about MCP schema
fd -e py -e md . | xargs grep -l "json_schema_from_flow" 2>/dev/null | head -10

Repository: langflow-ai/langflow

Length of output: 200


🏁 Script executed:

# Check how json_schema_from_flow is used in mcp_projects.py and mcp_utils.py
grep -n "json_schema_from_flow" src/backend/base/langflow/api/v1/mcp_projects.py -B 3 -A 3

Repository: langflow-ai/langflow

Length of output: 426


🏁 Script executed:

# Check mcp_utils.py for how MCP schemas are handled
grep -n "json_schema_from_flow\|mcp_type" src/backend/base/langflow/api/v1/mcp_utils.py -B 3 -A 3

Repository: langflow-ai/langflow

Length of output: 734


🏁 Script executed:

# Look for any TODO or FIXME comments related to mcp_type
rg "TODO.*mcp_type|FIXME.*mcp_type|mcp_type.*TODO" --type py

Repository: langflow-ai/langflow

Length of output: 46


🏁 Script executed:

# Check if mcp_type is expected to be added to input components in the future
rg "mcp_type" . --type py --type md

Repository: langflow-ai/langflow

Length of output: 186


mcp_type is assigning to description instead of JSON Schema type

The mcp_type handler on line 25-27 sets the property's description instead of its type field, overwriting any prior mcp_description. The JSON Schema type should be configurable via mcp_type while mcp_description controls only the human-readable description.

Update the handler to:

-                if field_name == "mcp_type" and field_data.get("value") != "":
-                    val = field_data.get("value")
-                    properties[name]["description"] = val or f"Input for {name}"
+                if field_name == "mcp_type":
+                    val = field_data.get("value")
+                    if val:
+                        properties[name]["type"] = val

This allows mcp_type to override the default "string" type while preserving mcp_description for documentation.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
name = node.data["id"]
template = node_data["template"]
properties[name] = {"type": "string", "description": f"Input for {name}"}
for field_name, field_data in template.items():
if field_data != "Component" and field_data.get("show", False) and not field_data.get("advanced", False):
field_type = field_data.get("type", "string")
properties[field_name] = {
"type": field_type,
"description": field_data.get("info", f"Input for {field_name}"),
}
# Update field_type in properties after determining the JSON Schema type
if field_type == "str":
field_type = "string"
elif field_type == "int":
field_type = "integer"
elif field_type == "float":
field_type = "number"
elif field_type == "bool":
field_type = "boolean"
else:
logger.warning(f"Unknown field type: {field_type} defaulting to string")
field_type = "string"
properties[field_name]["type"] = field_type
if field_data.get("required", False):
required.append(field_name)
if field_name.startswith("mcp_"):
if field_name == "mcp_description":
val = field_data.get("value")
properties[name]["description"] = val or f"Input for {name}"
if field_name == "mcp_type" and field_data.get("value") != "":
val = field_data.get("value")
properties[name]["description"] = val or f"Input for {name}"
if field_name == "mcp_required" and field_data.get("value", False):
required.append(name)
name = node.data["id"]
template = node_data["template"]
properties[name] = {"type": "string", "description": f"Input for {name}"}
for field_name, field_data in template.items():
if field_name.startswith("mcp_"):
if field_name == "mcp_description":
val = field_data.get("value")
properties[name]["description"] = val or f"Input for {name}"
if field_name == "mcp_type":
val = field_data.get("value")
if val:
properties[name]["type"] = val
if field_name == "mcp_required" and field_data.get("value", False):
required.append(name)
🤖 Prompt for AI Agents
In src/backend/base/langflow/helpers/flow.py around lines 452 to 469, the
mcp_type handler currently assigns the mcp_type value to
properties[name]["description"], overwriting any mcp_description; change the
mcp_type branch to set properties[name]["type"] to the provided non-empty value
(falling back to "string" if empty or invalid), leaving the mcp_description
branch to control properties[name]["description"] so descriptions are not lost;
optionally validate/normalize common JSON Schema types (string, number, integer,
boolean, object, array) before assignment.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Pull Request from an external contributor enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants