Skip to content

Fix Prompt#validate_arguments! crash when arguments are nil#246

Merged
koic merged 1 commit intomodelcontextprotocol:mainfrom
koic:fix_prompt_nil_arguments
Mar 1, 2026
Merged

Fix Prompt#validate_arguments! crash when arguments are nil#246
koic merged 1 commit intomodelcontextprotocol:mainfrom
koic:fix_prompt_nil_arguments

Conversation

@koic
Copy link
Member

@koic koic commented Feb 27, 2026

Motivation and Context

Prompt#validate_arguments! called required_args which does arguments_value.filter_map, crashing with NoMethodError when arguments_value is nil (the default for prompts without declared arguments). Additionally, passing nil as args caused a crash on args.keys.

Fix by defaulting arguments_value to [] and guarding against nil args.

How Has This Been Tested?

Added a repro test to verify the fix and prevent regression.

Breaking Changes

None.

Types of changes

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

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

atesgoral
atesgoral previously approved these changes Mar 1, 2026
`Prompt#validate_arguments!` called `required_args` which does `arguments_value.filter_map`,
crashing with `NoMethodError` when `arguments_value` is `nil` (the default for prompts without
declared arguments). Additionally, passing `nil` as args caused a crash on `args.keys`.

Fix by defaulting `arguments_value` to `[]` and guarding against `nil` args.
@koic koic merged commit 29a3290 into modelcontextprotocol:main Mar 1, 2026
10 checks passed
@koic koic deleted the fix_prompt_nil_arguments branch March 1, 2026 09:38
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