Skip to content

Conversation

@ebeigarts
Copy link

@ebeigarts ebeigarts commented Dec 12, 2025

This refactoring extracts common schema validation logic into a base Schema class, eliminating ~100 lines of duplicate code between InputSchema and OutputSchema. It also adds support for the JSON Schema additionalProperties keyword to allow fine-grained control over extra properties in tool arguments.

Previously additionalParameters could be set only on OutputSchema.

Key changes:

  • Created MCP::Tool::Schema base class consolidating:

    • Schema validation against JSON Schema Draft 4 metaschema
    • Deep key transformation (string to symbol conversion)
    • $ref disallowance checking
    • Common validation methods
  • Refactored InputSchema to inherit from Schema:

    • Simplified constructor to accept full schema hash
    • Changed required fields storage from symbols to strings
    • Removed ~40 lines of duplicated validation logic
  • Refactored OutputSchema to inherit from Schema:

    • Removed ~54 lines of duplicated validation logic
    • Now shares all common functionality with InputSchema
  • Updated Tool.input_schema setter:

    • Simplified to pass full hash directly to InputSchema
  • Added additionalProperties support:

    • By default, tools now allow additional properties (JSON Schema default)
    • Can explicitly set additionalProperties: false to disallow extras
    • Added comprehensive test coverage for both behaviors

Breaking Changes

InputSchema doesn't have required and properties readers.
Required params are now strings instead of symbols to match OutputSchema.

Before:

input_schema.required   # => [:message, :name]
input_schema.properties # => { ... }

After:

input_schema.schema[:required]   # => ["message", "name"]
input_schema.schema[:properties] # => { ... }

Error messages are unified:

Invalid JSON Schema: $ref is not allowed in tool schemas

instead of

Invalid JSON Schema: $ref is not allowed in tool input schemas
Invalid JSON Schema: $ref is not allowed in tool output schemas

Impact:

  • Direct access to properties attribute removed
  • Direct access to required attribute removed
  • Must use schema hash or to_h method instead

@ebeigarts ebeigarts force-pushed the feature/schema-additional-properties branch 2 times, most recently from dc80f62 to b862468 Compare December 12, 2025 10:42
…operties support

This refactoring extracts common schema validation logic into a base Schema
class, eliminating ~100 lines of duplicate code between InputSchema and
OutputSchema. It also adds support for the JSON Schema `additionalProperties`
keyword to allow fine-grained control over extra properties in tool arguments.

Previously `additionalParameters` could be set only on OutputSchema.

Key changes:

- Created MCP::Tool::Schema base class consolidating:
  - Schema validation against JSON Schema Draft 4 metaschema
  - Deep key transformation (string to symbol conversion)
  - $ref disallowance checking
  - Common validation methods

- Refactored InputSchema to inherit from Schema:
  - Simplified constructor to accept full schema hash
  - Changed required fields storage from symbols to strings
  - Removed ~40 lines of duplicated validation logic

- Refactored OutputSchema to inherit from Schema:
  - Removed ~54 lines of duplicated validation logic
  - Now shares all common functionality with InputSchema

- Updated Tool.input_schema setter:
  - Simplified to pass full hash directly to InputSchema

- Added additionalProperties support:
  - By default, tools now allow additional properties (JSON Schema default)
  - Can explicitly set `additionalProperties: false` to disallow extras
  - Added comprehensive test coverage for both behaviors
@ebeigarts ebeigarts force-pushed the feature/schema-additional-properties branch from b862468 to a3c24d2 Compare December 12, 2025 10:49
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