Skip to content

Conversation

alex210501
Copy link
Contributor

@alex210501 alex210501 commented Sep 2, 2025

Description

If the output schema is not specify, we do not return it as we break the MCP specification that are expecting the following format:

  "outputSchema": {
    "type": "object",
    "properties": {},
    "required": []
  }

Fixes #572 (if applicable)

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
  • Link to relevant spec section: Link text
  • Implementation follows the specification exactly

Additional Information

Summary by CodeRabbit

  • Bug Fixes

    • Tool JSON now omits the outputSchema field unless an explicit output schema is provided, reducing noise and avoiding misleading metadata; behavior remains unchanged when a schema is defined.
  • Tests

    • Added table-driven tests that marshal tools to JSON and verify outputSchema is present only when expected, validating observable JSON rather than internal fields.

If the output schema is not specify, we do not return it as we break the MCP specification that are expecting the following format:

```json
  "outputSchema": {
    "type": "object",
    "properties": {},
    "required": []
  }
```
Copy link
Contributor

coderabbitai bot commented Sep 2, 2025

Walkthrough

Tool.MarshalJSON now omits outputSchema unless a RawOutputSchema is present or OutputSchema.Type is non-empty; tests updated to assert presence/absence of outputSchema in marshaled JSON.

Changes

Cohort / File(s) Summary
Tool JSON marshaling
mcp/tools.go
Change MarshalJSON to emit outputSchema only when RawOutputSchema exists or OutputSchema.Type is non-empty; add clarifying comment.
Tests for tool JSON output
mcp/tools_test.go
Replace single assertion with table-driven tests that marshal Tool to JSON and assert outputSchema presence/absence in the resulting JSON map.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Fix tool discovery failure in v0.39.0 (#572) The change adjusts outputSchema serialization only; the linked issue describes a broader failure to list/query tools across transports — this PR's scope may not fully resolve that.

Possibly related PRs


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9ff7712 and 4fee986.

📒 Files selected for processing (1)
  • mcp/tools_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • mcp/tools_test.go
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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
🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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 (2)
mcp/tools_test.go (2)

589-633: LGTM; add a quick type check when schema exists.

Nice table test verifying presence/absence. Strengthen the “default behavior” branch by asserting the type field.

Apply this diff inside the true-branch to assert the schema shape:

       if tt.expectedOutputSchema {
         assert.True(t, exists)
         assert.NotNil(t, outputSchema)
+        schemaMap, ok := outputSchema.(map[string]any)
+        assert.True(t, ok)
+        assert.Equal(t, "object", schemaMap["type"])
       } else {

589-633: Consider adding a RawOutputSchema case.

Add a small test to ensure raw schemas are emitted (guards regressions on the raw path).

func TestToolWithRawOutputSchema_Included(t *testing.T) {
  raw := json.RawMessage(`{"type":"object","properties":{"ok":{"type":"boolean"}},"required":["ok"]}`)
  tool := NewTool("raw_tool", WithString("input", Required()), WithRawOutputSchema(raw))
  data, err := json.Marshal(tool)
  assert.NoError(t, err)

  var m map[string]any
  assert.NoError(t, json.Unmarshal(data, &m))
  os, exists := m["outputSchema"].(map[string]any)
  assert.True(t, exists)
  assert.Equal(t, "object", os["type"])
  props, _ := os["properties"].(map[string]any)
  _, hasOK := props["ok"]
  assert.True(t, hasOK)
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 35fc389 and 9ff7712.

📒 Files selected for processing (2)
  • mcp/tools.go (1 hunks)
  • mcp/tools_test.go (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
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.
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.
📚 Learning: 2025-03-04T07:00:57.111Z
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.

Applied to files:

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

Applied to files:

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

Applied to files:

  • mcp/tools_test.go
  • mcp/tools.go
🧬 Code graph analysis (1)
mcp/tools_test.go (1)
mcp/tools.go (6)
  • Tool (557-574)
  • NewTool (679-701)
  • WithDescription (722-726)
  • WithOutputSchema (771-804)
  • WithString (1046-1064)
  • Required (878-882)
🔇 Additional comments (1)
mcp/tools.go (1)

604-612: Correct: omit outputSchema when not explicitly set (matches MCP spec).

This conditional now serializes outputSchema only when RawOutputSchema is provided or OutputSchema.Type is non-empty. That aligns with the 2025-06-18 MCP spec where outputSchema is optional; sending an empty object was incorrect. Please update the PR description to reflect that the correct behavior is to omit outputSchema entirely when unspecified (the example showing a default object with empty properties/required contradicts the spec). (modelcontextprotocol.io)

Would you confirm this behavior against clients that broke on v0.39.0 (e.g., Claude Desktop/Web) to ensure omission (not an empty object) resolves discovery?

@ezynda3
Copy link
Contributor

ezynda3 commented Sep 2, 2025

@alex210501 I'll merge as soon as the typo is fixed

@ezynda3 ezynda3 merged commit 3d1bfca into mark3labs:main Sep 2, 2025
4 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.

bug: v0.39.0 does not work at all
2 participants