feat(mcp): pass session_id through MCP tool calls#13124
Conversation
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.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 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:
✨ 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Summary
session_idparameter to flows exposed via the MCP interface so MCP clients can persist chat history across tool calls.json_schema_from_flownow advertisessession_idin each tool's input schema (optional, not inrequired).handle_call_tooluses the client-providedsession_idwhen 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 optionalsession_idinto the generated JSON schema.src/backend/base/langflow/api/v1/mcp_utils.py— extractsession_idfrom 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 --checkon touched files — clean.session_id; second call sees prior turn in chat history.session_id; flow still runs as before (fresh session each call).tools/listagainst the MCP server showssession_idininputSchema.propertiesand not inrequired.Backward compatibility
Existing MCP clients that do not send
session_idare unaffected — they continue to get an auto-generated UUID per call, matching today's behavior.