Skip to content

Conversation

@otaviof
Copy link
Contributor

@otaviof otaviof commented Oct 18, 2025

Description

Introduces mcp.WithAny(), a new tool option that allows defining a property of any Golang type. This is useful for creating tools that can accept a variety of data structures for a given parameter.

Fixes #345

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

MCP Spec Compliance

  • This PR implements a feature defined in the MCP specification
  • Implementation follows the specification exactly

Summary by CodeRabbit

  • New Features
    • Added support for tool parameters with flexible typing, enabling tools to accept arbitrary data alongside strictly-typed fields.

Introduces `mcp.WithAny`, a new tool option that allows defining a
property of `any` type. This is useful for creating tools that can
accept a variety of data structures for a given parameter.

- `mcp.WithAny` function: A new WithAny function has been added to
  to support properties of any type in tool schemas. This allows for
  more flexible tool definitions where a property can accept a string,
  number, boolean, object, slice, etc.
- Testing: `TestToolWithAny`, has been introduced ensure the `WithAny`
  functionality is working correctly. The tests cover various data types
  to validate that the schema is correctly generated and that arguments
  are properly parsed.
- Example Usage: The `typed_tools`` example has been updated to
  demonstrate how to use `mcp.WithAny`. This includes adding a new field
  of type any to the arguments struct and updating the tool handler to
  process the new field
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 18, 2025

Walkthrough

This PR adds support for schema-less "any" type tool arguments to the mcp-go SDK. It introduces a new WithAny tool option function that creates properties with no predefined type constraint, includes comprehensive test coverage for marshaling/unmarshaling operations with various argument types, and demonstrates usage in an example.

Changes

Cohort / File(s) Summary
Core functionality
mcp/tools.go
Adds WithAny(name string, opts ...PropertyOption) function that creates input schema properties with no explicit type by starting with an empty schema map and applying provided options. Handles required flag management consistent with existing property-adding methods.
Test coverage
mcp/tools_test.go
Adds TestToolWithAny that validates the WithAny option through tool construction, JSON serialization/deserialization, and argument type handling with various payloads (string, integer, float, boolean, object, slice, struct). Verifies property structure and required field presence.
Example usage
examples/typed_tools/main.go
Adds AnyData field to GreetingArgs struct and uses mcp.WithAny("any_data", ...) in tool construction. Updates handler to utilize the new field when present.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

The PR introduces a straightforward new function following established patterns (mirroring WithBoolean, WithNumber), includes comprehensive tests exercising multiple argument types, and demonstrates practical usage. While the logic is not complex, the breadth of test scenarios and type handling variations requires careful review across all three files.

Possibly related PRs

Suggested labels

type: enhancement, area: sdk

Suggested reviewers

  • robert-jackson-glean
  • pottekkat

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "feat(mcp): Add WithAny for flexible tool properties" directly and clearly summarizes the main change—introducing a new tool option called WithAny that enables flexible property definitions. The title is concise, specific, and accurately reflects the primary objective of the pull request without unnecessary verbosity or generic language.
Linked Issues Check ✅ Passed The implementation satisfies the requirements specified in issue #345. The PR adds a new WithAny function that creates a tool property with an empty JSON Schema object (no predefined type), exactly as requested in the issue. The function signature WithAny(name string, opts ...PropertyOption) ToolOption matches the proposed pattern, the example usage demonstrates its application, and comprehensive tests validate the functionality including JSON serialization/deserialization and handling of various argument types.
Out of Scope Changes Check ✅ Passed All code changes are directly aligned with the objectives defined in issue #345. The modifications include the core WithAny function implementation, example usage demonstrating the feature, and comprehensive tests validating its behavior. There are no unrelated refactorings, unrelated bug fixes, or extraneous changes; every modification serves the primary purpose of implementing flexible tool properties via the WithAny option.
Description Check ✅ Passed The pull request description includes all main required sections: a clear and concise description explaining the new mcp.WithAny() tool option, appropriate selections in the Type of Change section, and a fully completed checklist confirming code style adherence, self-review, test coverage, and documentation updates. The description references issue #345 as intended. The MCP Spec Compliance section is partially filled out, with the main "implements a feature" checkbox unchecked and no specification link provided, though the author indicated "MCP spec compatibility implementation" in the Type of Change selections.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@otaviof
Copy link
Contributor Author

otaviof commented Oct 18, 2025

@coderabbitai generate docstrings

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 18, 2025

✅ Actions performed

Initiated docstring generation; will generate only if new commits exist.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 18, 2025

Note

Docstrings generation - SUCCESS
Generated docstrings for this pull request at #619

coderabbitai bot added a commit that referenced this pull request Oct 18, 2025
Docstrings generation was requested by @otaviof.

* #618 (comment)

The following files were modified:

* `examples/typed_tools/main.go`
* `mcp/tools.go`
@otaviof
Copy link
Contributor Author

otaviof commented Oct 18, 2025

Apologies, I didn't know CodeRabbit would create yet another PR directly. 🫥

@ezynda3 ezynda3 merged commit 881e142 into mark3labs:main Oct 20, 2025
4 of 5 checks passed
@otaviof otaviof deleted the issue-345-withany branch October 20, 2025 14:03
ezynda3 added a commit that referenced this pull request Oct 21, 2025
* 📝 Add docstrings to `issue-345-withany`

Docstrings generation was requested by @otaviof.

* #618 (comment)

The following files were modified:

* `examples/typed_tools/main.go`
* `mcp/tools.go`

* Update tools.go

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Ed Zynda <[email protected]>
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.

feature: withAny tool argument

2 participants