Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve on tool input handling and add tests #159

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

olaservo
Copy link
Collaborator

@olaservo olaservo commented Feb 27, 2025

Motivation and Context

The ToolTab JSON input handling still has some quirks and testing it manually isn't very sustainable. This PR adds the Jest testing framework to the client side of the MCP Inspector, enabling unit testing for the more complex client-side utilities and components.

The intent here is to improve maintainability by:

  1. Extracting utility functions from components into dedicated utility files
    • jsonPathUtils.ts: Handles JSON path operations (updating and retrieving values)
    • schemaUtils.ts: Handles schema-related operations (generating default values, formatting labels)
  2. Adding unit tests for these utilities
  3. Improving the DynamicJsonForm component with better error handling and state management, for better handling of edge cases (empty objects, missing schema properties).
  4. Enhancing the JsonEditor component with better state management and formatting capabilities
  5. Address this issue: Cannot pass an integer correctly #154

Another option to consider is using a JSON editing library which handles more of this stuff out of the box. I prefer to avoid adding libraries which might be overkill and introduce their own overhead. But it's still an option, if trying to cover all the more complex tool input testing scenarios doesn't seem sustainable in the long term.

How Has This Been Tested?

The PR includes new Jest tests for the utility functions that were extracted from components:

  • Tests for jsonPathUtils (updateValueAtPath, getValueAtPath)
  • Tests for schemaUtils (generateDefaultValue, formatFieldLabel, validateValueAgainstSchema)

I also updated the GitHub workflow to run these tests automatically during CI.

After these changes I also confirmed that I could update JSON fields for object tool inputs, which appears to be broken right now.

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

@olaservo olaservo changed the title Handle empty json fields Improve on tool input handling and add tests Feb 28, 2025
@olaservo olaservo mentioned this pull request Feb 28, 2025
9 tasks
@olaservo olaservo marked this pull request as ready for review February 28, 2025 05:10
@olaservo olaservo requested a review from jspahrsummers March 5, 2025 03:57
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.

1 participant