Skip to content

fix(sdk): accept underscore-prefixed MCP argument names - #6381

Merged
VascoSch92 merged 3 commits into
OpenHands:mainfrom
yftx293:fix/mcp-underscore-argument-names
Nov 5, 2026
Merged

VascoSch92 merged 3 commits into
OpenHands:mainfrom
yftx293:fix/mcp-underscore-argument-names

Conversation

@yftx293

@yftx293 yftx293 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

HUMAN:

Fixed the underscore-prefixed MCP argument crash from #6348. I reviewed the diff and the test; MCP argument names are the server's choice, not ours.


AGENT:

Why

Schema.from_mcp_schema passes MCP argument names straight to pydantic.create_model, which refuses names with a leading underscore (NameError: Fields must not use names with leading underscores). A tool that declares an argument such as _cursor — a normal JSON key for its producer — crashed action construction in Agent._get_action_event, which catches ValidationError but not NameError.

Summary

  • Route underscore-prefixed argument names through the alias mechanism already used for discriminator collisions (kind): keep the external name as the Pydantic alias and use a safe internal field name, so model_dump(by_alias=True) still emits the original key.
  • Port the pinned test test_mcp_action_from_arguments_accepts_underscore_prefixed_argument from the worktree-test-edge-cases branch (commit f2fcf6e) without its xfail(strict=True) marker, per the [Bug]: Edge-case tests expose ~70 bugs across the SDK, agent server, tools and workspaces #6348 menu's acceptance criteria.

Issue Number

Part of #6348 (menu sub-item: "Schema.from_mcp_schema passes MCP argument names straight to pydantic.create_model, so '_'-prefixed names ...")

How to Test

uv run pytest tests/sdk/mcp/test_mcp_nested_schema.py -k underscore

Before this change the tool raises NameError; after, action_from_arguments({"_cursor": "abc"}).data == {"_cursor": "abc"}. tests/sdk/mcp/ plus tests/sdk/tool/ is 433 passed, with one pre-existing environment failure (test_create_mcp_tools_connection_to_nonexistent_server, which fails the same way without this change). ruff check/format on the touched files are clean.

Type

  • Bug fix

Notes

Only the leading-underscore case is aliased; ordinary argument names keep their current field names.

@VascoSch92
VascoSch92 enabled auto-merge (squash) November 4, 2026 09:50

@VascoSch92 VascoSch92 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

auto-merge was automatically disabled November 4, 2026 09:54

Head branch was modified

@VascoSch92
VascoSch92 enabled auto-merge (squash) November 4, 2026 09:57
auto-merge was automatically disabled November 4, 2026 09:58

Head branch was modified

@VascoSch92
VascoSch92 enabled auto-merge (squash) November 5, 2026 08:50
auto-merge was automatically disabled November 5, 2026 08:53

Head branch was modified

@VascoSch92 VascoSch92 closed this Nov 5, 2026
@VascoSch92 VascoSch92 reopened this Nov 5, 2026
@VascoSch92
VascoSch92 enabled auto-merge (squash) November 5, 2026 15:32
@VascoSch92

Copy link
Copy Markdown
Member

sorry I had to close it and re-open it. GH was buggy

@VascoSch92
VascoSch92 merged commit 67b61b1 into OpenHands:main Nov 5, 2026
37 checks passed
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.

2 participants