Skip to content

Conversation

JMLX42
Copy link

@JMLX42 JMLX42 commented Aug 30, 2025

Disclaimer

PR/patches written with Claude Code (Sonnet 4)

Summary

Fixes MCP Inspector sending empty arrays [] and objects {} for optional parameters instead of omitting them, which causes compatibility issues with OpenAPI servers.

Problem

  • MCP Inspector was automatically sending empty arrays [] for optional array parameters
  • MCP Inspector was automatically sending empty objects {} for optional object parameters
  • OpenAPI servers expect optional parameters to be completely absent when not specified
  • This caused API calls to fail or behave unexpectedly

Solution

Updated the generateDefaultValue function in schemaUtils.ts to:

  • Return undefined for optional array parameters (omits them from requests)
  • Return undefined for optional object parameters (omits them from requests)
  • Continue returning [] for required array parameters
  • Continue returning {} for required object parameters

Implementation Plan

  • Fix array handling: Update array case to check if property is required, returning [] only for required arrays and undefined for optional arrays
  • Fix object handling: Update object case to check if property is required, returning {} only for required objects and undefined for optional objects
  • Add comprehensive tests: Ensure both required and non-required cases are tested for arrays and objects
  • Verify consistency: Make sure array and object behavior aligns with other optional types (string, number, boolean)
  • Commit structure: Create separate fix: commits for arrays and objects as requested

Testing

Added comprehensive test coverage for:

  • Optional arrays → undefined
  • Required arrays → []
  • Optional objects → undefined
  • Required objects → {}
  • Non-required arrays in parent schema → undefined
  • Non-required objects in parent schema → undefined

All existing tests continue to pass, ensuring no regression.

Expected Outcome

Optional array and object parameters will be omitted from tool call arguments instead of being sent as empty arrays/objects, resolving compatibility issues with OpenAPI servers.

Fixes #771

JMLX42 added 2 commits August 30, 2025 14:45
- Update generateDefaultValue to return undefined for optional array parameters
- Add comprehensive tests for required vs non-required arrays
- Fixes issue where MCP Inspector sends empty arrays [] for optional parameters
- Resolves compatibility issues with OpenAPI servers expecting omitted optionals

Refs modelcontextprotocol#771
- Update generateDefaultValue to return undefined for optional object parameters
- Add comprehensive tests for required vs non-required objects
- Fixes issue where MCP Inspector sends empty objects {} for optional parameters
- Objects with required properties still return populated objects
- Empty optional objects now return undefined to be omitted from requests

Refs modelcontextprotocol#771
JMLX42 added a commit to lx-industries/rmcp-openapi that referenced this pull request Sep 1, 2025
This reverts commit b90c893.

The original implementation was incorrect as it made the server
second-guess client intent by omitting parameters that clients
explicitly provided. Empty values are valid and should be passed through
unchanged.

Root cause has been fixed at the client level in MCP Inspector PR:

modelcontextprotocol/inspector#772

Closes #65
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.

MCP Inspector sends empty arrays/objects for optional parameters instead of omitting them
1 participant