Skip to content

feat: add WithInteger and WithIntegerItems options #458

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Cali0707
Copy link

@Cali0707 Cali0707 commented Jun 27, 2025

Description

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • MCP spec compatibility implementation
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring (no functional changes)
  • Performance improvement
  • Tests only (no functional changes)
  • Other (please describe):

Checklist

  • My code follows the code style of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the documentation accordingly

Additional Information

The WithInteger tool option is already in the docs, but does not exist in the source code yet. This PR adds the option and some associated tests, as well as an option for specifying that array items are of type integer.

Summary by CodeRabbit

  • New Features

    • Added support for defining integer properties and integer array items in tool input schemas.
    • Property option functions for numbers now support int, int64, and float64 types.
  • Tests

    • Introduced tests to verify correct handling of string and integer properties.
    • Added compatibility tests for integer array item definitions using new and existing APIs.

Copy link
Contributor

coderabbitai bot commented Jun 27, 2025

Walkthrough

This change generalizes number-related property option functions to support int, int64, and float64 types using generics. It introduces WithInteger and WithIntegerItems functions for defining integer properties and array items in tool schemas. Corresponding tests are added to ensure correct schema generation and compatibility with previous APIs.

Changes

Files / Areas Change Summary
mcp/tools.go Generalized number property options with generics; added WithInteger and WithIntegerItems functions.
mcp/tools_test.go Added tests for integer property and array item schema generation, including API compatibility checks.

Possibly related PRs

Suggested reviewers

  • ezynda3
  • rwjblue-glean
  • pottekkat
  • dugenkui03

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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 (3)
mcp/tools.go (1)

822-842: Fix typo in the function documentation.

The function implementation is correct and follows established patterns, but there's a typo in the comment.

Apply this diff to fix the typo:

-// It accepts propety operations to configure the integer property's behavior and constraints.
+// It accepts property options to configure the integer property's behavior and constraints.
mcp/tools_test.go (2)

147-193: Fix comment error in the test.

The test correctly verifies the new WithInteger functionality, but there's a copy-paste error in the comment.

Apply this diff to fix the comment:

-	// Verify itemName object
+	// Verify itemCount object

707-746: Fix inconsistent description in test case.

The test cases correctly verify backward compatibility for integer array items, but there's an inconsistent description in the second test case.

Apply this diff to fix the description:

-				WithDescription("Tool with constrained number array using new API"),
+				WithDescription("Tool with constrained integer array using new API"),
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8f5b048 and 980db96.

📒 Files selected for processing (2)
  • mcp/tools.go (3 hunks)
  • mcp/tools_test.go (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
mcp/tools_test.go (5)
Learnt from: xinwo
PR: mark3labs/mcp-go#35
File: mcp/tools.go:0-0
Timestamp: 2025-03-04T07:00:57.111Z
Learning: The Tool struct in the mark3labs/mcp-go project should handle both InputSchema and RawInputSchema consistently between MarshalJSON and UnmarshalJSON methods, even though the tools response from MCP server typically doesn't contain rawInputSchema.
Learnt from: xinwo
PR: mark3labs/mcp-go#35
File: mcp/tools.go:107-137
Timestamp: 2025-03-04T06:59:43.882Z
Learning: Tool responses from the MCP server shouldn't contain RawInputSchema, which is why the UnmarshalJSON method for the Tool struct is implemented to handle only the structured InputSchema format.
Learnt from: xinwo
PR: mark3labs/mcp-go#35
File: mcp/tools.go:0-0
Timestamp: 2025-03-04T07:00:57.111Z
Learning: The Tool struct in mark3labs/mcp-go handles both InputSchema and RawInputSchema formats. When unmarshaling JSON, it first tries to parse into a structured ToolInputSchema format, and if that fails, it falls back to using the raw schema format, providing symmetry with the MarshalJSON method.
Learnt from: octo
PR: mark3labs/mcp-go#149
File: mcptest/mcptest.go:0-0
Timestamp: 2025-04-21T21:26:32.945Z
Learning: In the mcptest package, prefer returning errors from helper functions rather than calling t.Fatalf() directly, giving callers flexibility in how to handle errors.
Learnt from: floatingIce91
PR: mark3labs/mcp-go#401
File: server/server.go:1082-1092
Timestamp: 2025-06-23T11:10:42.948Z
Learning: In Go MCP server, ServerTool.Tool field is only used for tool listing and indexing, not for tool execution or middleware. During handleToolCall, only the Handler field is used, so dynamic tools don't need the Tool field populated.
mcp/tools.go (2)
Learnt from: xinwo
PR: mark3labs/mcp-go#35
File: mcp/tools.go:0-0
Timestamp: 2025-03-04T07:00:57.111Z
Learning: The Tool struct in the mark3labs/mcp-go project should handle both InputSchema and RawInputSchema consistently between MarshalJSON and UnmarshalJSON methods, even though the tools response from MCP server typically doesn't contain rawInputSchema.
Learnt from: xinwo
PR: mark3labs/mcp-go#35
File: mcp/tools.go:0-0
Timestamp: 2025-03-04T07:00:57.111Z
Learning: The Tool struct in mark3labs/mcp-go handles both InputSchema and RawInputSchema formats. When unmarshaling JSON, it first tries to parse into a structured ToolInputSchema format, and if that fails, it falls back to using the raw schema format, providing symmetry with the MarshalJSON method.
🧬 Code Graph Analysis (1)
mcp/tools_test.go (1)
mcp/tools.go (11)
  • NewTool (569-591)
  • WithDescription (612-616)
  • WithString (868-886)
  • Description (671-675)
  • Required (679-683)
  • WithInteger (824-842)
  • WithArray (913-931)
  • Items (983-987)
  • WithIntegerItems (1087-1099)
  • Min (759-763)
  • Max (751-755)
🔇 Additional comments (5)
mcp/tools.go (5)

743-747: LGTM! Good use of generics for numeric types.

The generalization to support int, int64, and float64 improves API flexibility while maintaining backward compatibility.


751-755: LGTM! Consistent generalization.

The generic type constraints align well with the DefaultNumber function changes and improve usability.


759-763: LGTM! Consistent with other numeric function generalizations.

The generic type constraints maintain consistency across all numeric property option functions.


767-771: LGTM! Completes the numeric function generalization.

All numeric property option functions now consistently support the same generic type constraints.


1076-1099: LGTM! Well-implemented integer array items function.

The function follows established patterns, includes comprehensive documentation with examples, and correctly implements integer item schema configuration.

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