fix(mcp): forward extra advertised input fields as tweaks during tool execution#14016
Conversation
… execution Fixes langflow-ai#14002 When a flow is exposed as an MCP tool, `json_schema_from_flow()` advertises all visible input-node fields (e.g. `backend_token`, `backend_url`) in the tool's `inputSchema`. However, `handle_call_tool()` was constructing `SimplifiedAPIRequest` with only `input_value` and `session_id`, silently discarding every other argument supplied by the MCP client. Pop `input_value` and `session_id` from `processed_inputs` first, then pass the remaining keys as `tweaks` to `SimplifiedAPIRequest`. `process_tweaks` already accepts a flat `{field_name: value}` dict and applies it to any node whose template contains a matching field; nodes without that field skip it safely (`apply_tweaks` line 148: `if tweak_name not in template_data: continue`). This aligns the published MCP tool contract with actual execution behaviour without introducing new API surface or UI changes.
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughMCP tool execution now removes ChangesMCP tweak forwarding
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 9✅ Passed checks (9 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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.
🧹 Nitpick comments (1)
src/backend/tests/unit/api/v1/test_mcp_utils.py (1)
535-578: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove unnecessary
@pytest.mark.asynciodecorators.The repo is configured with
asyncio_mode = 'auto'inpyproject.toml, so async test functions are auto-detected without explicit decorators. The@pytest.mark.asynciodecorators on lines 537 and 565 are redundant.Based on learnings, in the langflow-ai/langflow repository, pytest-asyncio is configured with
asyncio_mode = 'auto'in pyproject.toml, meaning@pytest.mark.asynciodecorators are unnecessary.♻️ Remove redundant decorators
`@pytest.mark.asyncio` async def test_handle_call_tool_forwards_extra_fields_as_tweaks(monkeypatch):to:
async def test_handle_call_tool_forwards_extra_fields_as_tweaks(monkeypatch):and
`@pytest.mark.asyncio` async def test_handle_call_tool_tweaks_none_when_no_extra_fields(monkeypatch):to:
async def test_handle_call_tool_tweaks_none_when_no_extra_fields(monkeypatch):🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/backend/tests/unit/api/v1/test_mcp_utils.py` around lines 535 - 578, Remove the redundant `@pytest.mark.asyncio` decorators from test_handle_call_tool_forwards_extra_fields_as_tweaks and test_handle_call_tool_tweaks_none_when_no_extra_fields, leaving both async test functions and their existing assertions unchanged.Source: Learnings
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/backend/tests/unit/api/v1/test_mcp_utils.py`:
- Around line 535-578: Remove the redundant `@pytest.mark.asyncio` decorators from
test_handle_call_tool_forwards_extra_fields_as_tweaks and
test_handle_call_tool_tweaks_none_when_no_extra_fields, leaving both async test
functions and their existing assertions unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: db11a293-f9cc-4586-b9b3-addc34d1d016
📒 Files selected for processing (2)
src/backend/base/langflow/api/v1/mcp_utils.pysrc/backend/tests/unit/api/v1/test_mcp_utils.py
Summary
Fixes #14002
When a flow is exposed as an MCP tool,
json_schema_from_flow()advertises all visible input-node fields (e.g.backend_token,backend_url) in the tool'sinputSchema. However,handle_call_tool()was constructingSimplifiedAPIRequestwith onlyinput_valueandsession_id, silently discarding every other argument supplied by the MCP client.Root cause:
handle_call_tool(line 313) calledprocessed_inputs.get("input_value", "")without removinginput_value, and never forwarded the remaining keys.Fix: Pop
input_valueandsession_idfromprocessed_inputsfirst, then pass the remaining keys astweakstoSimplifiedAPIRequest.process_tweaksalready handles a flat{field_name: value}dict and applies it to every node whose template contains a matching field. Nodes that don't have that field skip it silently (apply_tweaks,if tweak_name not in template_data: continue), so the change is safe for all existing flows.Changes
src/backend/base/langflow/api/v1/mcp_utils.py— 8 lines changed inhandle_call_toolsrc/backend/tests/unit/api/v1/test_mcp_utils.py— 2 new tests addedTest plan
uv run pytest src/backend/tests/unit/api/v1/test_mcp_utils.py -v— 21/21 passtest_handle_call_tool_forwards_extra_fields_as_tweaks— extra fields arrive as tweakstest_handle_call_tool_tweaks_none_when_no_extra_fields— backward-compatible: tweaks isNonewhen onlyinput_valueis suppliedSummary by CodeRabbit
Bug Fixes
Tests