Skip to content

feat(mcp): pass session_id through MCP tool calls#13124

Merged
erichare merged 2 commits into
release-1.10.0from
feat/mcp-session-id
May 14, 2026
Merged

feat(mcp): pass session_id through MCP tool calls#13124
erichare merged 2 commits into
release-1.10.0from
feat/mcp-session-id

Conversation

@erichare
Copy link
Copy Markdown
Collaborator

Summary

  • Add optional session_id parameter to flows exposed via the MCP interface so MCP clients can persist chat history across tool calls.
  • json_schema_from_flow now advertises session_id in each tool's input schema (optional, not in required).
  • handle_call_tool uses the client-provided session_id when present and falls back to a generated UUID otherwise (preserves prior behavior).

Reported by Alejandro — MCP clients had no way to maintain chat history because the server unconditionally generated a fresh conversation id per call, so memory components could never see prior turns.

Files Changed

  • src/backend/base/langflow/helpers/flow.py — inject optional session_id into the generated JSON schema.
  • src/backend/base/langflow/api/v1/mcp_utils.py — extract session_id from arguments; fall back to UUID when absent/blank.
  • src/backend/tests/unit/api/v1/test_mcp_utils.py — 5 new unit tests covering both pass-through and fallback paths plus the schema additions.

Test plan

  • uv run pytest src/backend/tests/unit/api/v1/test_mcp_utils.py — 19/19 pass (5 new).
  • uv run ruff check / uv run ruff format --check on touched files — clean.
  • Manual: call an MCP tool twice with the same session_id; second call sees prior turn in chat history.
  • Manual: call without session_id; flow still runs as before (fresh session each call).
  • Manual: tools/list against the MCP server shows session_id in inputSchema.properties and not in required.

Backward compatibility

Existing MCP clients that do not send session_id are unaffected — they continue to get an auto-generated UUID per call, matching today's behavior.

Adds optional session_id support to flows exposed via the MCP
interface so MCP clients (Claude Desktop, Cursor, etc.) can persist
conversation history across tool calls.

- json_schema_from_flow now advertises session_id as an optional
  string property on every generated tool schema, unless the flow
  already defines its own session_id input.
- handle_call_tool reads session_id from the incoming arguments and
  forwards it to simple_run_flow. When absent or blank, it falls
  back to a generated UUID, preserving the prior per-call behavior.

Reported by Alejandro: MCP clients had no way to maintain chat
history because the server unconditionally generated a fresh
conversation id per call.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 14, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

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: 856b1036-1f6c-4b1b-8102-03145825f99a

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
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/mcp-session-id

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.

@github-actions github-actions Bot added the enhancement New feature or request label May 14, 2026
@erichare erichare requested a review from Cristhianzl May 14, 2026 17:09
@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.70%. Comparing base (e21f588) to head (765d63e).

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##           release-1.10.0   #13124      +/-   ##
==================================================
- Coverage           54.71%   54.70%   -0.01%     
==================================================
  Files                2145     2145              
  Lines              200199   200142      -57     
  Branches            30199    28490    -1709     
==================================================
- Hits               109537   109491      -46     
+ Misses              89481    89469      -12     
- Partials             1181     1182       +1     
Flag Coverage Δ
backend 60.14% <100.00%> (+0.20%) ⬆️
frontend 54.66% <ø> (-0.06%) ⬇️
lfx 49.30% <ø> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
src/backend/base/langflow/api/v1/mcp_utils.py 65.56% <100.00%> (+12.08%) ⬆️
src/backend/base/langflow/helpers/flow.py 60.83% <100.00%> (+7.47%) ⬆️

... and 74 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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 14, 2026

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 38%
38.4% (47871/124659) 67.9% (6542/9634) 38.28% (1100/2873)

Unit Test Results

Tests Skipped Failures Errors Time
4302 0 💤 0 ❌ 0 🔥 11m 20s ⏱️

@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels May 14, 2026
@erichare erichare merged commit 3da78df into release-1.10.0 May 14, 2026
115 of 116 checks passed
@erichare erichare deleted the feat/mcp-session-id branch May 14, 2026 18:34
@carlosrcoelho carlosrcoelho requested review from carlosrcoelho and removed request for carlosrcoelho May 14, 2026 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant