Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mcp/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,8 @@ type ToolArgumentsSchema struct {
AdditionalProperties any `json:"additionalProperties,omitempty"`
}

type ToolInputSchema ToolArgumentsSchema // For retro-compatibility
type ToolOutputSchema ToolArgumentsSchema
type ToolInputSchema = ToolArgumentsSchema // For retro-compatibility (true alias, inherits methods)
type ToolOutputSchema = ToolArgumentsSchema
Comment on lines +645 to +646
Copy link
Contributor

@coderabbitai coderabbitai bot Jan 17, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# Check the current state of mcp/tools.go around lines 645-646
sed -n '640,650p' mcp/tools.go

Repository: mark3labs/mcp-go

Length of output: 583


🏁 Script executed:

# Search for context around ToolInputSchema and ToolOutputSchema
rg -B 3 -A 3 'type ToolInputSchema|type ToolOutputSchema' mcp/tools.go

Repository: mark3labs/mcp-go

Length of output: 424


🏁 Script executed:

# Check if there are GoDoc comments anywhere above these lines
sed -n '630,650p' mcp/tools.go

Repository: mark3labs/mcp-go

Length of output: 852


🏁 Script executed:

# Check how ToolInputSchema and ToolOutputSchema are used in the codebase
rg 'ToolInputSchema|ToolOutputSchema' mcp/tools.go -B 2 -A 2

Repository: mark3labs/mcp-go

Length of output: 1108


🏁 Script executed:

# Check if there are any other type alias examples in the codebase with GoDoc comments
rg 'type \w+ = \w+' --type go -B 2 -A 0

Repository: mark3labs/mcp-go

Length of output: 1111


Add GoDoc comments for the exported aliases.

ToolInputSchema and ToolOutputSchema are exported type aliases but lack GoDoc comments. Other type aliases in the codebase (e.g., OAuthConfig, Token in client/oauth.go) follow the pattern of having GoDoc comments starting with the identifier name. Align these aliases with the project's documentation standard.

✍️ Proposed fix
+// ToolInputSchema is an alias of ToolArgumentsSchema for backward compatibility.
+// It inherits ToolArgumentsSchema's JSON marshaling behavior.
 type ToolInputSchema = ToolArgumentsSchema // For retro-compatibility (true alias, inherits methods)
+
+// ToolOutputSchema is an alias of ToolArgumentsSchema for backward compatibility.
+// It inherits ToolArgumentsSchema's JSON marshaling behavior.
 type ToolOutputSchema = ToolArgumentsSchema
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
type ToolInputSchema = ToolArgumentsSchema // For retro-compatibility (true alias, inherits methods)
type ToolOutputSchema = ToolArgumentsSchema
// ToolInputSchema is an alias of ToolArgumentsSchema for backward compatibility.
// It inherits ToolArgumentsSchema's JSON marshaling behavior.
type ToolInputSchema = ToolArgumentsSchema // For retro-compatibility (true alias, inherits methods)
// ToolOutputSchema is an alias of ToolArgumentsSchema for backward compatibility.
// It inherits ToolArgumentsSchema's JSON marshaling behavior.
type ToolOutputSchema = ToolArgumentsSchema
🤖 Prompt for AI Agents
In `@mcp/tools.go` around lines 645 - 646, Add GoDoc comments for the exported
type aliases: prepend a comment starting with "ToolInputSchema" above the
declaration "type ToolInputSchema = ToolArgumentsSchema" and a comment starting
with "ToolOutputSchema" above "type ToolOutputSchema = ToolArgumentsSchema" that
briefly explains they are retro-compatible aliases of ToolArgumentsSchema and
inherit its methods; follow the project's style used for other aliases (e.g.,
OAuthConfig, Token) so the comments begin with the identifier name and
succinctly describe purpose/compatibility.

Copy link
Contributor

Choose a reason for hiding this comment

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

@proyuen can you add these please?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Contributor

Choose a reason for hiding this comment

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

@proyuen ping


// MarshalJSON implements the json.Marshaler interface for ToolInputSchema.
func (tis ToolArgumentsSchema) MarshalJSON() ([]byte, error) {
Expand Down
34 changes: 34 additions & 0 deletions mcp/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1765,3 +1765,37 @@ func TestWithSchemaAdditionalProperties(t *testing.T) {
assert.NoError(t, err)
assert.Contains(t, string(data), `"additionalProperties":false`)
}

// TestToolInputSchema_MarshalJSON_EmptyProperties verifies that ToolInputSchema
// inherits the MarshalJSON method from ToolArgumentsSchema, ensuring that
// the 'properties' field is included in JSON output even when empty.
// This fixes issue #694.
func TestToolInputSchema_MarshalJSON_EmptyProperties(t *testing.T) {
schema := ToolInputSchema{
Type: "object",
Properties: map[string]any{}, // empty but not nil
}

b, err := json.Marshal(schema)
assert.NoError(t, err)

result := string(b)
// Ensure 'properties' field is present in JSON output
assert.Contains(t, result, `"properties"`, "Expected properties field in JSON output")
// Verify the full expected output
assert.Contains(t, result, `"properties":{}`, "Expected empty properties object in JSON output")
}

// TestToolOutputSchema_MarshalJSON_EmptyProperties verifies the same for ToolOutputSchema.
func TestToolOutputSchema_MarshalJSON_EmptyProperties(t *testing.T) {
schema := ToolOutputSchema{
Type: "object",
Properties: map[string]any{}, // empty but not nil
}

b, err := json.Marshal(schema)
assert.NoError(t, err)

result := string(b)
assert.Contains(t, result, `"properties":{}`, "Expected empty properties object in JSON output")
}