fix: support langchain upgrade - #300
Draft
NicoleMGomes wants to merge 4 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
mcp_tool_to_langchaininconverters.pyproduced aStructuredToolwhose innerruncoroutine forwarded all**kwargsdirectly tocall_tool. Starting withlangchain-core0.3.x,StructuredTool._arun()injects two extra keyword arguments —config(aRunnableConfig) andrun_manager— into every coroutine call. Because those keys are not accepted bycall_tool, every MCP tool invocation raised:The fix changes the filtering strategy from a deny-list (explicitly popping known LangChain internals) to an allow-list:
runnow closes overallowed_keys = frozenset(properties)— the set of parameter names declared in the MCP tool'sinput_schema— and only forwards kwargs that appear in that set. Any kwarg LangChain injects, now or in future versions, is silently ignored without requiring code changes.Three regression tests were added to
test_converters.pyto verify thatconfig,run_manager, and any combination thereof are stripped while real tool parameters still pass through correctly.Related Issue
Closes #
Type of Change
How to Test
mcp_tool_to_langchainwith anyMCPTool.agent.ainvoke(...)).TypeError: StructuredTool._arun() missing 1 required keyword-only argument: 'config'is raised.Or run the unit tests directly:
All 27 tests should pass, including the three new regression tests:
test_langchain_config_kwarg_not_forwarded_to_call_tooltest_langchain_run_manager_kwarg_not_forwarded_to_call_tooltest_langchain_injected_kwargs_stripped_while_tool_params_pass_throughChecklist
Additional Notes
The bug manifests on
langchain-core >= 0.3.xand was confirmed from production logs where the agent recovered by returning the error as a string to the LLM, so it appeared as degraded behaviour rather than a hard crash. The fix is backwards-compatible: on olderlangchain-coreversions whereconfigandrun_managerare never injected, the allow-list filter is a no-op.