Skip to content

Conversation

@olaservo
Copy link
Member

@olaservo olaservo commented Jul 16, 2025

Summary

  • Updates parameter handling in ToolsTab to properly distinguish between required and optional fields
  • Optional fields with empty values are set to undefined and omitted from tool call requests
  • Required fields preserve their values even when empty
  • Adds comprehensive parameter cleaning utility with full test coverage
  • Fixes a couple issues from PR 528 (merged a little too fast without re-testing 😬 )

Motivation and Context

Fixes #623

When tool parameters are cleared in the UI, they were being sent as empty strings.

How Has This Been Tested?

  • Added comprehensive unit tests covering all parameter types and required/optional scenarios
  • Manual testing verified that empty optional fields are omitted from requests
  • Manual testing verified that required fields are preserved even when empty
  • Tested using some sample tools I set up here based on past issues with Inspector: https://github.com/olaservo/mcp-maintainer-toolkit

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 comprehensive test coverage
  • Code has been formatted with Prettier

@olaservo olaservo force-pushed the omit-optional-empty-strings branch from 87bb31e to 754c979 Compare September 24, 2025 14:04
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@olaservo olaservo marked this pull request as ready for review September 24, 2025 14:07
@olaservo olaservo changed the title Omit optional empty strings (test PR for Claude Code automation) Omit optional empty strings Sep 24, 2025
@olaservo olaservo changed the title Omit optional empty strings Update ToolsTab parameter handling to omit optional empty fields Sep 24, 2025
@olaservo olaservo added bug Something isn't working tools Issues related to testing tools labels Sep 24, 2025
- Import JsonSchemaType from utils/jsonUtils
- Cast tool.inputSchema to JsonSchemaType instead of any
- Matches typing pattern used elsewhere in codebase

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@olaservo olaservo requested a review from Copilot September 24, 2025 14:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes parameter handling in the ToolsTab component to properly distinguish between required and optional fields. When optional tool parameters are cleared in the UI, they are now set to undefined and omitted from tool call requests instead of being sent as empty strings.

Key changes:

  • Created a parameter cleaning utility that omits empty optional fields while preserving required fields
  • Updated ToolsTab input handlers to set optional fields to undefined when cleared
  • Integrated parameter cleaning into the tool call request flow

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
client/src/utils/paramUtils.ts New utility for cleaning parameters based on JSON schema requirements
client/src/utils/__tests__/paramUtils.test.ts Comprehensive test suite for parameter cleaning functionality
client/src/components/ToolsTab.tsx Updated input handlers to set optional fields to undefined when cleared
client/src/App.tsx Integrated parameter cleaning into the tool call request flow

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@olaservo olaservo force-pushed the omit-optional-empty-strings branch from 1cf9efa to 45abfe0 Compare September 26, 2025 04:19
@olaservo olaservo requested a review from Copilot September 28, 2025 03:42
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +21 to +31
if (isFieldRequired) {
// Required fields: always include, even if empty string or falsy
cleaned[key] = value;
} else {
// Optional fields: only include if they have meaningful values
if (value !== undefined && value !== "" && value !== null) {
cleaned[key] = value;
}
// Empty strings, undefined, null for optional fields → omit completely
}
}
Copy link
Member

@cliffhall cliffhall Sep 29, 2025

Choose a reason for hiding this comment

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

Just a simplification:

Suggested change
if (isFieldRequired) {
// Required fields: always include, even if empty string or falsy
cleaned[key] = value;
} else {
// Optional fields: only include if they have meaningful values
if (value !== undefined && value !== "" && value !== null) {
cleaned[key] = value;
}
// Empty strings, undefined, null for optional fields → omit completely
}
}
// Include all required fields, and optional fields if they have meaningful values
if (isFieldRequired || (value !== undefined && value !== "" && value !== null)) {
cleaned[key] = value;
}

@cliffhall cliffhall dismissed their stale review September 30, 2025 19:57

Forget the optimization, we are blocked by failing tests on main that this fixes.

@cliffhall cliffhall merged commit cd2b787 into modelcontextprotocol:main Sep 30, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working tools Issues related to testing tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optional empty fields are sent as empty strings

2 participants