Skip to content

Conversation

@sd2k
Copy link
Contributor

@sd2k sd2k commented Nov 26, 2025

Older versions of the JSON Schema spec use the "definitions" field,
while newer versions use "$defs". This can be seen in the Honeycomb
MCP, which uses "definitions".

This commit adds support for both fields, and prefers "$defs" over
"definitions" if both are present.

Summary by CodeRabbit

  • Improvements

    • Enhanced JSON schema format compatibility to properly handle definitions from both older standards (draft-07) and newer specifications (2019-09+), automatically converting between formats for seamless integration.
  • Tests

    • Added comprehensive unit tests verifying JSON schema deserialization across multiple format variations, including nested definitions, preference handling, and complete round-trip data integrity validation.

✏️ Tip: You can customize this high-level summary in your review settings.

…rgumentsSchema

Older versions of the JSON Schema spec use the "definitions" field,
while newer versions use "$defs". This can be seen in the Honeycomb
MCP, which uses "definitions".

This commit adds support for both fields, and prefers "$defs" over
"definitions" if both are present.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 26, 2025

Walkthrough

Adds custom JSON deserialization support to ToolArgumentsSchema to handle both JSON Schema draft-07 "definitions" and 2019-09+ "$defs" fields, mapping both into the Defs field with appropriate precedence rules, supported by comprehensive unit tests.

Changes

Cohort / File(s) Summary
JSON Schema Compatibility Handler
mcp/tools.go
Implements UnmarshalJSON method on ToolArgumentsSchema using an alias to deserialize both "definitions" (draft-07) and "$defs" (2019-09+) fields, populating Defs with $defs taking precedence over definitions.
ToolArgumentsSchema Deserialization Tests
mcp/tools_test.go
Adds unit tests validating UnmarshalJSON behavior across draft-07 definitions, 2019-09 $defs, $defs/definitions precedence, and marshal/unmarshal round-trip integrity.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Review UnmarshalJSON implementation for correct alias usage and nil-safety in Defs field assignment
  • Verify $defs precedence logic over definitions when both are present
  • Confirm test coverage adequately exercises all conditional paths

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete. While it explains the change motivation, it lacks the required template structure with sections like Type of Change and Checklist. Fill out the description template with appropriate sections: Type of Change (mark 'Bug fix'), Checklist items, and any MCP Spec Compliance details if applicable.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding support for both $defs and definitions fields when unmarshaling ToolArgumentsSchema.
✨ 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.

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_test.go (1)

1553-1684: Good coverage of $defs/definitions behavior on ToolArgumentsSchema

These tests nicely pin down the intended semantics:

  • TestToolArgumentsSchema_UnmarshalWithDefinitions and _WithDefs cover both draft‑07 definitions and 2019‑09+ $defs.
  • TestToolArgumentsSchema_UnmarshalPrefersDefs verifies the precedence rule.
  • TestToolArgumentsSchema_MarshalRoundTrip checks that $defs survives a marshal/unmarshal cycle.

All of that aligns with the new UnmarshalJSON implementation and gives clear regression protection.

If you want extra safety later, you could add an integration‑style test that unmarshals a full Tool JSON payload whose inputSchema uses definitions/$defs, to ensure the wiring from ToolToolInputSchemaToolArgumentsSchema behaves as expected, but that’s an optional enhancement rather than a blocker.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6bd3269 and 908cf30.

📒 Files selected for processing (2)
  • mcp/tools.go (1 hunks)
  • mcp/tools_test.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

**/*.go: Order imports: standard library first, then third-party, then local packages (goimports enforces this)
Follow Go naming conventions: exported identifiers in PascalCase; unexported in camelCase; acronyms uppercase (HTTP, JSON, MCP)
Error handling: return sentinel errors, wrap with fmt.Errorf("context: %w", err), and check with errors.Is/As
Prefer explicit types and strongly-typed structs; avoid using any except where protocol flexibility is required (e.g., Arguments any)
All exported types and functions must have GoDoc comments starting with the identifier name; avoid inline comments unless necessary
Functions that are handlers or long-running must accept context.Context as the first parameter
Ensure thread safety for shared state using sync.Mutex and document thread-safety requirements in comments
For JSON: use json struct tags with omitempty for optional fields; use json.RawMessage for flexible/deferred parsing

Files:

  • mcp/tools_test.go
  • mcp/tools.go
**/*_test.go

📄 CodeRabbit inference engine (AGENTS.md)

**/*_test.go: Testing: use testify/assert and testify/require
Write table-driven tests using a tests := []struct{ name, ... } pattern
Go test files must end with _test.go

Files:

  • mcp/tools_test.go
🧠 Learnings (6)
📓 Common learnings
Learnt from: xinwo
Repo: mark3labs/mcp-go PR: 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
Repo: mark3labs/mcp-go PR: 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.
📚 Learning: 2025-03-04T07:00:57.111Z
Learnt from: xinwo
Repo: mark3labs/mcp-go PR: 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.

Applied to files:

  • mcp/tools_test.go
  • mcp/tools.go
📚 Learning: 2025-03-04T07:00:57.111Z
Learnt from: xinwo
Repo: mark3labs/mcp-go PR: 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.

Applied to files:

  • mcp/tools_test.go
  • mcp/tools.go
📚 Learning: 2025-03-04T06:59:43.882Z
Learnt from: xinwo
Repo: mark3labs/mcp-go PR: 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.

Applied to files:

  • mcp/tools_test.go
  • mcp/tools.go
📚 Learning: 2025-10-13T09:35:20.180Z
Learnt from: CR
Repo: mark3labs/mcp-go PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-10-13T09:35:20.180Z
Learning: Applies to **/*_test.go : Write table-driven tests using a tests := []struct{ name, ... } pattern

Applied to files:

  • mcp/tools_test.go
📚 Learning: 2025-10-13T09:35:20.180Z
Learnt from: CR
Repo: mark3labs/mcp-go PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-10-13T09:35:20.180Z
Learning: Applies to **/*_test.go : Testing: use testify/assert and testify/require

Applied to files:

  • mcp/tools_test.go
🧬 Code graph analysis (1)
mcp/tools_test.go (1)
mcp/tools.go (3)
  • ToolArgumentsSchema (625-630)
  • Properties (1166-1170)
  • Required (908-912)
🔇 Additional comments (1)
mcp/tools.go (1)

656-679: Let me try the shell script again:
<function_calls>

#!/bin/bash

Find type definitions for ToolInputSchema, ToolOutputSchema, and ToolArgumentsSchema

rg -n 'type ToolInputSchema|type ToolOutputSchema|type ToolArgumentsSchema' -A2


</function_calls>

@ezynda3 ezynda3 merged commit 670a95a into mark3labs:main Nov 28, 2025
5 of 6 checks passed
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