Skip to content

fix: support langchain upgrade - #300

Draft
NicoleMGomes wants to merge 4 commits into
mainfrom
fix/langchain-upgrade
Draft

fix: support langchain upgrade#300
NicoleMGomes wants to merge 4 commits into
mainfrom
fix/langchain-upgrade

Conversation

@NicoleMGomes

@NicoleMGomes NicoleMGomes commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Disclaimer: Do not include SAP-internal or customer-specific information in this PR (e.g. internal system URLs, customer names, tenant IDs, or confidential configurations). This is a public repository.

Description

mcp_tool_to_langchain in converters.py produced a StructuredTool whose inner run coroutine forwarded all **kwargs directly to call_tool. Starting with langchain-core 0.3.x, StructuredTool._arun() injects two extra keyword arguments — config (a RunnableConfig) and run_manager — into every coroutine call. Because those keys are not accepted by call_tool, every MCP tool invocation raised:

TypeError: StructuredTool._arun() missing 1 required keyword-only argument: 'config'

The fix changes the filtering strategy from a deny-list (explicitly popping known LangChain internals) to an allow-list: run now closes over allowed_keys = frozenset(properties) — the set of parameter names declared in the MCP tool's input_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.py to verify that config, run_manager, and any combination thereof are stripped while real tool parameters still pass through correctly.

Related Issue

Closes #

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring

How to Test

  1. Create a LangChain agent that uses mcp_tool_to_langchain with any MCPTool.
  2. Invoke a tool through the agent (e.g. agent.ainvoke(...)).
  3. Confirm no TypeError: StructuredTool._arun() missing 1 required keyword-only argument: 'config' is raised.

Or run the unit tests directly:

uv run python3 -m pytest tests/agentgateway/unit/test_converters.py -v

All 27 tests should pass, including the three new regression tests:

  • test_langchain_config_kwarg_not_forwarded_to_call_tool
  • test_langchain_run_manager_kwarg_not_forwarded_to_call_tool
  • test_langchain_injected_kwargs_stripped_while_tool_params_pass_through

Checklist

  • I have read the Contributing Guidelines
  • I have verified that my changes solve the issue
  • I have added/updated automated tests to cover my changes
  • All tests pass locally
  • I have verified that my code follows the Code Guidelines
  • I have updated documentation (if applicable)
  • I have added type hints for all public APIs
  • My code does not contain sensitive information (credentials, tokens, etc.)
  • I have followed Conventional Commits for commit messages

Additional Notes

The bug manifests on langchain-core >= 0.3.x and 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 older langchain-core versions where config and run_manager are never injected, the allow-list filter is a no-op.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant