Skip to content

fix(mcp): forward extra advertised input fields as tweaks during tool execution#14016

Open
Juanmidev1 wants to merge 2 commits into
langflow-ai:release-1.11.0from
Juanmidev1:fix/mcp-extra-fields-forwarded-as-tweaks
Open

fix(mcp): forward extra advertised input fields as tweaks during tool execution#14016
Juanmidev1 wants to merge 2 commits into
langflow-ai:release-1.11.0from
Juanmidev1:fix/mcp-extra-fields-forwarded-as-tweaks

Conversation

@Juanmidev1

@Juanmidev1 Juanmidev1 commented Jul 11, 2026

Copy link
Copy Markdown

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'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.

Root cause: handle_call_tool (line 313) called processed_inputs.get("input_value", "") without removing input_value, and never forwarded the remaining keys.

Fix: Pop input_value and session_id from processed_inputs first, then pass the remaining keys as tweaks to SimplifiedAPIRequest.

process_tweaks already 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 in handle_call_tool
  • src/backend/tests/unit/api/v1/test_mcp_utils.py — 2 new tests added

Test plan

  • uv run pytest src/backend/tests/unit/api/v1/test_mcp_utils.py -v — 21/21 pass
  • test_handle_call_tool_forwards_extra_fields_as_tweaks — extra fields arrive as tweaks
  • test_handle_call_tool_tweaks_none_when_no_extra_fields — backward-compatible: tweaks is None when only input_value is supplied
  • Manual: create a flow with a custom input field, expose it via MCP, call the tool with that field — verify it reaches the component

Summary by CodeRabbit

  • Bug Fixes

    • Tool calls now correctly forward additional input fields as execution settings.
    • Tool calls containing only the primary input continue to work without additional settings.
  • Tests

    • Added coverage for forwarding extra tool inputs and preserving existing behavior when none are provided.

… 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.
@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 68801364-5727-4ba4-830b-5acc8cf39cbf

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

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

MCP tool execution now removes input_value from submitted arguments and forwards remaining fields as tweaks. Unit tests cover both extra arguments and calls with no additional fields.

Changes

MCP tweak forwarding

Layer / File(s) Summary
Forward tool arguments and validate request construction
src/backend/base/langflow/api/v1/mcp_utils.py, src/backend/tests/unit/api/v1/test_mcp_utils.py
execute_tool extracts input_value, forwards remaining arguments as tweaks, and sets tweaks to None when no extra fields exist. Tests cover both cases.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 9
✅ Passed checks (9 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: forwarding extra MCP inputs as tweaks during tool execution.
Linked Issues check ✅ Passed The change addresses #14002 by forwarding advertised extra arguments to the flow and adding tests for both extra fields and empty tweaks.
Out of Scope Changes check ✅ Passed The PR stays focused on MCP tool argument forwarding and matching unit tests, with no obvious unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Test Coverage For New Implementations ✅ Passed Added backend regression unit tests in test_mcp_utils.py for extra-field forwarding to tweaks and None fallback, matching naming conventions.
Test Quality And Coverage ✅ Passed New async pytest unit tests assert forwarded input_request data, cover extra tweaks and None fallback, and match backend test patterns.
Test File Naming And Structure ✅ Passed The new backend test file follows pytest naming/layout, uses descriptive test names, isolates setup via a helper, and covers both positive and negative cases.
Excessive Mock Usage Warning ✅ Passed Mocks are limited to external deps (simple_run_flow, session, graph), while assertions inspect forwarded_request.tweaks/input_value directly; not excessive.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ Share

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

@github-actions github-actions Bot added the bug Something isn't working label Jul 11, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jul 11, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/backend/tests/unit/api/v1/test_mcp_utils.py (1)

535-578: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove unnecessary @pytest.mark.asyncio decorators.

The repo is configured with asyncio_mode = 'auto' in pyproject.toml, so async test functions are auto-detected without explicit decorators. The @pytest.mark.asyncio decorators 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.asyncio decorators 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7f28257 and f3899e9.

📒 Files selected for processing (2)
  • src/backend/base/langflow/api/v1/mcp_utils.py
  • src/backend/tests/unit/api/v1/test_mcp_utils.py

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant