Skip to content

Conversation

@xhd2015
Copy link
Contributor

@xhd2015 xhd2015 commented Mar 9, 2025

The problem: current With* only provides basic strings and numbers, which is insufficient for practical usage.

In my program, I need to pass an args []string to the server.

Summary by CodeRabbit

  • New Features

    • Introduced enhanced configuration options for schema definition, enabling more robust setup for structured data.
    • Added capabilities for defining detailed object and array constraints, such as minimum/maximum counts and unique item requirements.
    • Expanded options for managing additional properties and property naming, offering greater flexibility in data structuring.
  • Tests

    • Added a new test case to validate the functionality of tools with object and array properties, ensuring proper schema structure and constraints.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 9, 2025

Walkthrough

This update introduces multiple new functions in the mcp/tools.go file to enhance the tool schema functionality. The changes include functions for adding object and array properties, defining their attributes, and setting constraints such as minimum and maximum counts and required fields. Additionally, a new test function has been added to mcp/tools_test.go to validate the structure and functionality of the tool schema with these enhancements.

Changes

File Change Summary
mcp/tools.go Added new functions: WithObject, WithArray, Properties, AdditionalProperties, MinProperties, MaxProperties, PropertyNames, Items, MinItems, MaxItems, and UniqueItems.
mcp/tools_test.go Added new test function: TestToolWithObjectAndArray. This function tests the creation of a tool with both object and array properties, verifying the structure and constraints.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 90e3f8f and 814795c.

📒 Files selected for processing (2)
  • mcp/tools.go (1 hunks)
  • mcp/tools_test.go (1 hunks)
🔇 Additional comments (14)
mcp/tools.go (9)

371-396: Well-designed addition of WithObject method that follows existing patterns

The implementation follows the same structure as the existing With* methods, which makes the codebase consistent and maintainable. The function properly handles the required fields by moving them from the property schema to the InputSchema.Required slice.


398-422: Well-implemented WithArray method for array schema support

This implementation matches the pattern of other With* functions and correctly processes the array schema type. Good handling of the required property, ensuring consistency with the existing code structure.


424-429: Good implementation of the Properties option function

The function provides a clean way to define properties for an object schema, maintaining the functional option pattern used throughout the codebase.


431-437: Well-documented and flexible AdditionalProperties implementation

The implementation allows for both boolean values and schema objects to be passed, following the JSON Schema specification. The comments clearly explain the purpose of the function.


439-451: Good paired implementation of MinProperties and MaxProperties

These functions work together to set constraints on object property counts, following the established pattern for property options.


453-458: Correctly implemented PropertyNames function

This function allows for schema validation of property names in accordance with JSON Schema specifications.


460-465: Flexible Items implementation for array schemas

The function accepts an interface{} parameter which allows for both simple types and complex schema objects to define array items.


467-479: Well-paired MinItems and MaxItems functions

These functions set constraints on array lengths, following the same pattern used for other constraint functions in the codebase.


481-486: Properly implemented UniqueItems function

This function adds support for the uniqueItems constraint in JSON Schema, completing the set of array-related options.

mcp/tools_test.go (5)

146-187: Comprehensive test creation for object and array properties

The test case creates a complex tool schema with both object and array properties, testing nested structures and various constraints. It provides good coverage for the new functionality.


188-205: Well-structured JSON serialization and validation

The test properly marshals and unmarshals the tool to verify that the JSON structure is correctly generated. The assertions validate the top-level schema properties effectively.


206-220: Thorough validation of object property structure

The test comprehensively checks the "preferences" object schema, including its type, description, and nested properties (theme and maxItems).


221-237: Effective array schema validation

The test validates all aspects of the "books" array, including its type, description, and the structure of its items. The verification of nested object properties within array items is particularly valuable.


238-242: Properly verifies required fields in the schema

The test confirms that the "books" property is correctly marked as required in the schema, validating that the Required() option functions as expected when used with arrays.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
mcp/tools.go (1)

371-486: Overall implementation addresses the PR objectives well

The additions effectively extend the schema capabilities to support complex data structures like objects and arrays, addressing the limitation mentioned in the PR objectives. The implementation is consistent with the existing codebase patterns and follows JSON Schema standards.

A potential enhancement could be to add some example usage in the function comments to make it clearer how to use these new functions together, especially for complex nested structures.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 258aee9 and 90e3f8f.

📒 Files selected for processing (1)
  • mcp/tools.go (1 hunks)
🔇 Additional comments (9)
mcp/tools.go (9)

371-396: Implementation of WithObject looks good

This function extends the schema capabilities by allowing you to define object properties, following the same pattern as the existing WithString, WithNumber, and WithBoolean functions. It correctly initializes an empty properties map and handles the "required" attribute properly.


398-422: Implementation of WithArray looks good

The WithArray function complements WithObject and follows the same established pattern. It correctly handles the array type and the required attribute logic.


424-429: Properties function implementation is correct

This function allows defining the properties for an object schema, which is essential for working with object types.


431-437: AdditionalProperties implementation is flexible and correct

Using interface{} as the parameter type is appropriate here since JSON Schema supports both boolean values and schema objects for additionalProperties.


439-451: MinProperties and MaxProperties implementations look good

These functions correctly implement the corresponding JSON Schema validation keywords for objects.


453-458: PropertyNames implementation is correct

This function appropriately sets up the schema for property names validation.


460-465: Items implementation is correct and flexible

The use of interface{} as the parameter type allows for both single schema and tuple validation approaches in JSON Schema.


467-479: MinItems and MaxItems implementations look good

These functions correctly implement the corresponding JSON Schema validation keywords for arrays.


481-486: UniqueItems implementation is correct

This function appropriately handles the uniqueItems constraint for arrays.

@ezynda3 ezynda3 self-assigned this Mar 10, 2025
@xhd2015
Copy link
Contributor Author

xhd2015 commented Mar 11, 2025

@ezynda3 hi May I know how is this going? MCP is cooking, we gophers need also catch up, a better library can boost go MCP!

@ezynda3
Copy link
Contributor

ezynda3 commented Mar 11, 2025

@xhd2015 would you mind adding one or two tests showing that this new code works as intended?

@xhd2015
Copy link
Contributor Author

xhd2015 commented Mar 12, 2025

Will update soon

@xhd2015
Copy link
Contributor Author

xhd2015 commented Mar 12, 2025

@ezynda3 hi please kindly review, thanks!

@ezynda3 ezynda3 merged commit a73d7cf into mark3labs:main Mar 12, 2025
2 checks passed
@xhd2015 xhd2015 deleted the add-array-obj branch April 9, 2025 09:39
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