Repository navigation
fix(agent_langchain, tool_mcp_client): reasoning-model agents silently drop zero-argument MCP tools - #1451
Conversation
…y drop zero-argument MCP tools Fixes rocketride-org#1404 Two independent defects combined to cause this: 1. `tool_mcp_client.IGlobal.list_namespaced_tools()` exposed a tool's JSON schema under the key `input_schema` (snake_case), but the canonical `ToolsBase.ToolDescriptor` contract in `packages/ai/src/ai/common/tools.py` -- and every framework driver that reads it -- expects `inputSchema` (camelCase). The mismatch meant `td.get('inputSchema')` always returned `None` for MCP-sourced tools, silently discarding the real schema before it ever reached the driver. 2. `agent_langchain.langchain._make_args_schema` treated "no schema info at all" and "schema explicitly declares zero properties" as the same case, falling back to the permissive `_ToolInput` (which advertises a generic `input` field) for both. A genuinely zero-argument tool therefore looked to the model like it required an `input` argument -- which is what caused reasoning models to either skip the tool or call it with an argument the MCP server didn't expect and rejected. Fix: correct the key mismatch, and give explicitly zero-argument tools a strict, field-free `_NoArgsInput` schema (rendered as `{"type":"object","properties":{}}`) instead of conflating them with the "unknown schema" fallback. Added regression tests covering both defects; verified they fail against the pre-fix code and pass after the fix.
🤖 Internal: Discord sync markerAuto-managed by the Discord notification workflow. Stores the linked Discord message ID. Do not edit or delete. |
📝 WalkthroughWalkthroughThis PR changes LangChain tool schema generation to treat explicit empty MCP tool schemas as strict no-argument models, fixes MCP tool descriptors to emit ChangesZero-argument tool schema handling
Estimated code review effort: 2 (Simple) | ~12 minutes Sequence Diagram(s)sequenceDiagram
participant MCP as IGlobal.list_namespaced_tools
participant Agent as langchain._build_langchain_tools
participant Schema as _make_args_schema
MCP->>Agent: tool descriptor with inputSchema
Agent->>Schema: derive args schema
alt properties missing
Schema-->>Agent: _ToolInput
else properties empty or non-dict
Schema-->>Agent: _NoArgsInput
else properties present
Schema-->>Agent: named fields
end
Related Issues: Suggested labels: bug, tool-mcp-client, agent-langchain Suggested reviewers: aryanshah-aparavi 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@nodes/src/nodes/agent_langchain/langchain.py`:
- Around line 168-172: The schema handling in the langchain input parser is
treating a missing properties field as an empty no-args schema, which
misclassifies unconstrained object inputs. Update the logic in the input_schema
parsing path around the isinstance(input_schema, dict) check so it first tests
whether 'properties' is present in input_schema, and only returns _NoArgsInput
when an object schema explicitly declares an empty properties map. Keep the
existing _ToolInput fallback for schemas without properties and preserve the
current _NoArgsInput behavior only for explicitly empty object schemas.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 867e8c7b-8ab1-4e49-9a51-0fda6e01dbff
📒 Files selected for processing (3)
nodes/src/nodes/agent_langchain/langchain.pynodes/src/nodes/tool_mcp_client/IGlobal.pynodes/test/agent_langchain/test_zero_arg_tool_schema.py
Fixes rocketride-org#1404 -- reasoning-model agents silently drop zero-argument MCP tools. See PR rocketride-org#1451: rocketride-org#1451
…args Addresses review feedback on rocketride-org#1404 (PR rocketride-org#1451). `input_schema.get('properties', {})` collapsed two different schemas into the same case: `{"type": "object"}` (properties key absent -- an unconstrained object shape) and `{"type": "object", "properties": {}}` (properties key explicitly present and empty -- a genuine zero-argument declaration). Both produced an empty dict from `.get(..., {})` and were routed to the new strict `_NoArgsInput` schema, so a tool with an unconstrained/unknown argument shape would incorrectly be told it takes no arguments at all. Now `'properties' not in input_schema` is checked explicitly and routed to the permissive `_ToolInput` fallback (same as "no schema info at all"), leaving `_NoArgsInput` for schemas that explicitly declare zero properties. Added a regression test for the missing-properties-key case; verified it fails against the pre-fix logic and passes after.
Pulls in the CodeRabbit review fix for rocketride-org#1404 (missing-properties-key edge case). See PR rocketride-org#1451: rocketride-org#1451
|
Good catch -- fixed in the latest commit. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@nodes/src/nodes/agent_langchain/langchain.py`:
- Around line 173-179: The `get_tool_input_schema`-style logic in `langchain.py`
now correctly handles missing vs empty `properties`, but the `props` type check
still collapses malformed non-dict `properties` into `_NoArgsInput`. Update the
branch around `input_schema`, `properties`, and `props` so that only an explicit
empty dict returns `_NoArgsInput`, while a present-but-invalid `properties`
value falls back to `_ToolInput` like the missing-key case. Keep the existing
distinction intact in the same helper that selects between `_ToolInput` and
`_NoArgsInput`.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: fc5866b5-d8bd-45c8-a736-824dbcf6aae3
📒 Files selected for processing (2)
nodes/src/nodes/agent_langchain/langchain.pynodes/test/agent_langchain/test_zero_arg_tool_schema.py
| if not isinstance(input_schema, dict): | ||
| return _ToolInput | ||
| props = input_schema.get('properties', {}) | ||
| if not isinstance(props, dict) or not props: | ||
| if 'properties' not in input_schema: | ||
| return _ToolInput | ||
| props = input_schema.get('properties') | ||
| if not isinstance(props, dict) or not props: | ||
| return _NoArgsInput |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win
Correctly fixes the missing-vs-empty properties bug.
This properly distinguishes {"type": "object"} (no properties key → _ToolInput fallback) from {"type": "object", "properties": {}} (explicit empty → _NoArgsInput), resolving the previously flagged collapse issue.
One residual edge case: Line 178 treats a properties key that is present but not a dict (malformed schema) the same as an explicitly empty object, returning _NoArgsInput. A malformed/non-dict properties isn't an explicit "no args" declaration — it's unknown/invalid schema shape, which should arguably fall back to the permissive _ToolInput like the "missing key" case above, rather than being forced into the strict no-args model.
🔧 Suggested refinement
- props = input_schema.get('properties')
- if not isinstance(props, dict) or not props:
+ props = input_schema.get('properties')
+ if not isinstance(props, dict):
+ return _ToolInput
+ if not props:
return _NoArgsInput📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if not isinstance(input_schema, dict): | |
| return _ToolInput | |
| props = input_schema.get('properties', {}) | |
| if not isinstance(props, dict) or not props: | |
| if 'properties' not in input_schema: | |
| return _ToolInput | |
| props = input_schema.get('properties') | |
| if not isinstance(props, dict) or not props: | |
| return _NoArgsInput | |
| if not isinstance(input_schema, dict): | |
| return _ToolInput | |
| if 'properties' not in input_schema: | |
| return _ToolInput | |
| props = input_schema.get('properties') | |
| if not isinstance(props, dict): | |
| return _ToolInput | |
| if not props: | |
| return _NoArgsInput |
🤖 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 `@nodes/src/nodes/agent_langchain/langchain.py` around lines 173 - 179, The
`get_tool_input_schema`-style logic in `langchain.py` now correctly handles
missing vs empty `properties`, but the `props` type check still collapses
malformed non-dict `properties` into `_NoArgsInput`. Update the branch around
`input_schema`, `properties`, and `props` so that only an explicit empty dict
returns `_NoArgsInput`, while a present-but-invalid `properties` value falls
back to `_ToolInput` like the missing-key case. Keep the existing distinction
intact in the same helper that selects between `_ToolInput` and `_NoArgsInput`.
|
Closing as superseded by #1491 (merged July 21), which resolved #1404. The inputSchema key fix here landed there verbatim (IGlobal.list_namespaced_tools now emits camelCase), and the zero-argument case is handled at the transport layer instead: all three MCP transports normalize empty or degenerate schemas via mcp_schema.normalize_tool_input_schema (an optional rr_no_args placeholder, stripped again before the real tools/call), with unit, integration, and agent-catalog tests. That means an explicitly empty properties object can no longer reach agent_langchain from an MCP tool, so the _NoArgsInput branch this PR adds would be dead code on develop, and the branch now conflicts. Thanks for the thorough diagnosis, the two-defect writeup here matched what got fixed. |
Fixes #1404
Two independent defects combined to cause reasoning-model agents (e.g.
qwen/qwen3.6-27bon Groq) to silently drop zero-argument MCP tools:tool_mcp_client.IGlobal.list_namespaced_tools()exposed a tool's JSON schema under the keyinput_schema(snake_case), but the canonicalToolsBase.ToolDescriptorcontract inpackages/ai/src/ai/common/tools.py-- and every framework driver that reads it -- expectsinputSchema(camelCase). The mismatch meanttd.get('inputSchema')inagent_langchain/langchain.pyalways returnedNonefor MCP-sourced tools, silently discarding the real schema before it ever reached the driver.agent_langchain.langchain._make_args_schematreated "no schema info at all" and "schema explicitly declares zero properties" as the same case, falling back to the permissive_ToolInput(which advertises a genericinputfield) for both. A genuinely zero-argument tool therefore looked to the model like it required aninputargument -- which is what caused reasoning models to either skip the tool or call it with an argument the MCP server did not expect and rejected.Fix
input_schema->inputSchema) inIGlobal.list_namespaced_tools()._NoArgsInputschema (rendered as{"type": "object", "properties": {}}) instead of conflating them with the "unknown schema"_ToolInputfallback. Tools with no schema info at all keep the permissive fallback so arbitrary args still get through.Testing
nodes/test/agent_langchain/test_zero_arg_tool_schema.pyandnodes/test/tool_mcp_clientcoverage (6 new tests) exercising both the key-rename and the schema-fallback split.ruff check/ruff format --diffclean on all changed files.Summary by CodeRabbit
Bug Fixes
inputSchemakey for improved downstream compatibility.Tests