-
Notifications
You must be signed in to change notification settings - Fork 8.2k
feat: Transform All Component Inputs into MCP Parameters #11025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: Transform All Component Inputs into MCP Parameters #11025
Conversation
…d' inputs in Chat and Text components, update flow processing to handle new input structure, and refactor argument transformation for improved clarity.
|
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 WalkthroughThese 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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 error, 3 warnings)
✅ Passed checks (3 passed)
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 |
There was a problem hiding this 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
📒 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 withawaitfor async operations in component execution methods
Useasyncio.create_task()for background tasks and implement proper cleanup with try/except forasyncio.CancelledError
Usequeue.put_nowait()for non-blocking queue operations andasyncio.wait_for()with timeouts for controlled get operations
Files:
src/backend/base/langflow/helpers/flow.pysrc/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 contractThe new
transform_argumentscorrectly wraps each MCP argument as{node_id: {"input_value": value}}, which matches the tweaks shape used byrun_flowinhelpers/flow.pyand keeps node IDs aligned withjson_schema_from_flow. TheSimplifiedAPIRequestnow relies solely onsession_idandtweaks(withinput_valuecommented out), so please ensure the Pydantic model has been updated to makeinput_valueoptional 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‑breakingAdding
mcp_descriptionandmcp_requiredas advanced inputs cleanly exposes MCP metadata without changing runtime behavior; their names and types line up withjson_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 logicThe added
mcp_descriptionandmcp_requiredfields 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.
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
# First, verify the file exists and check its size
wc -l src/backend/base/langflow/helpers/flow.pyRepository: 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 -nRepository: 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.pyRepository: 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 2Repository: 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 5Repository: 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 -5Repository: 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 2Repository: 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 -80Repository: 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.pyRepository: 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 -80Repository: 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 2Repository: 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/nullRepository: 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 2Repository: 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 -10Repository: 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 3Repository: 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 3Repository: 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 pyRepository: 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 mdRepository: 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"] = valThis 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.
| 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.
There was a problem hiding this 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.
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:
Flow with two inputs:
Flow as a Tool.
Note the description presented with input parameters:
Tool execution:
Example with both parameters filled:
Suggested for review
@edwinjosechittilappilly
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.