Skip to content

Conversation

@dugenkui03
Copy link
Collaborator

@dugenkui03 dugenkui03 commented May 6, 2025

Summary by CodeRabbit

  • New Features

    • Added support for audio content in prompts and tool call results, allowing audio data (base64-encoded with MIME type) to be included alongside text and images.
  • Bug Fixes

    • Updated tests to validate the presence of both text and audio content in relevant responses.
  • Documentation

    • Improved comments to reflect that audio content is now a supported type in various structures.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 6, 2025

Walkthrough

Support for audio content was added throughout the codebase. A new AudioContent struct was introduced, along with helper and factory functions, updates to content parsing, and enhancements to test cases. Comments on relevant structs were updated to reflect audio content as a valid type, and test logic was adjusted to expect and validate audio data.

Changes

Files/Paths Change Summary
mcp/types.go Introduced new exported struct AudioContent for audio data, implemented isContent() method, and updated comments to include AudioContent as a valid content type.
mcp/utils.go Added AsAudioContent, NewAudioContent, and NewToolResultAudio functions. Extended ParseContent to handle "audio" type and validate required fields.
client/inprocess_test.go Enhanced test setup and validation to include and expect audio content in tool call and prompt responses. Updated request arguments and expected content/message counts.
mcp/prompts.go, mcp/tools.go Updated comments on PromptMessage.Content and CallToolResult.Content fields to document support for AudioContent.

Possibly related PRs

  • change to strong content type #26: Modifies the content model by changing the Content field to a strongly typed interface, which is related to this PR's extension of content types to include audio.

Suggested reviewers

  • ezynda3
✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

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

Documentation and Community

  • 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: 1

🧹 Nitpick comments (2)
client/inprocess_test.go (1)

208-208: Update test error message to match new expectation.

The error message still refers to expecting 1 content item, but the test now checks for 2 content items (text and audio).

-			t.Errorf("Expected 1 content item, got %d", len(result.Content))
+			t.Errorf("Expected 2 content items, got %d", len(result.Content))
mcp/utils.go (1)

80-83: Fix incorrect comment for AsAudioContent function.

The function comment incorrectly states "AsImageContent" instead of "AsAudioContent". This should be updated to match the actual function name and purpose.

-// AsImageContent attempts to cast the given interface to AudioContent
+// AsAudioContent attempts to cast the given interface to AudioContent
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f47e2bc and 099f5fb.

📒 Files selected for processing (5)
  • client/inprocess_test.go (4 hunks)
  • mcp/prompts.go (1 hunks)
  • mcp/tools.go (1 hunks)
  • mcp/types.go (2 hunks)
  • mcp/utils.go (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
mcp/prompts.go (1)
mcp/types.go (1)
  • Content (684-686)
mcp/tools.go (1)
mcp/types.go (1)
  • Content (684-686)
client/inprocess_test.go (2)
mcp/types.go (4)
  • AudioContent (714-721)
  • AudioContent (723-723)
  • Content (684-686)
  • Params (118-118)
mcp/prompts.go (2)
  • Role (68-68)
  • RoleUser (71-71)
mcp/utils.go (2)
mcp/types.go (5)
  • AudioContent (714-721)
  • AudioContent (723-723)
  • Content (684-686)
  • TextContent (690-695)
  • TextContent (697-697)
mcp/tools.go (1)
  • CallToolResult (34-41)
🔇 Additional comments (10)
mcp/prompts.go (1)

81-81: Correctly updated comment to include AudioContent as a valid content type.

The comment has been appropriately updated to include AudioContent as a possible value for the Content field, which aligns with the new audio content support being added to the codebase.

mcp/tools.go (1)

36-36: Correctly updated comment to include AudioContent as a valid content type.

The comment has been appropriately updated to include AudioContent as a possible value for the Content field in CallToolResult, which aligns with the new audio content support being added to the codebase.

client/inprocess_test.go (4)

39-43: Good implementation of the AudioContent test case.

The addition of AudioContent to the test tool response correctly tests the tool's ability to return audio content alongside text content. The implementation includes all required fields (Type, Data, and MIMEType).


85-92: Well-structured test for PromptMessage with AudioContent.

This implementation properly tests the ability of prompt messages to include audio content. The Role is set correctly, and the AudioContent is well-formed with all required fields.


375-377: Good addition of arguments to the test prompt request.

Adding arguments to the test prompt request ensures that the prompt handler's usage of arguments is properly tested, which provides more thorough test coverage.


384-385: Correctly updated test assertion for multiple messages.

The test assertion has been properly updated to expect 2 messages instead of 1, reflecting the new prompt handler implementation that returns both text and audio content messages.

mcp/types.go (2)

659-659: Correctly updated comment to include AudioContent in SamplingMessage.

This comment update properly documents that the Content field in SamplingMessage can now include AudioContent alongside the existing TextContent and ImageContent types.


712-724: Well-implemented AudioContent struct following established patterns.

The new AudioContent struct is well-designed and follows the same pattern as existing content types:

  1. It embeds the Annotated type like other content types
  2. It has a Type field that must be "audio"
  3. It includes fields for the base64-encoded audio data and its MIME type
  4. It properly implements the isContent() method to satisfy the Content interface

This implementation maintains consistency with the codebase's design patterns and will integrate seamlessly with existing code.

mcp/utils.go (2)

210-217: LGTM! Good implementation of NewAudioContent.

The implementation correctly follows the pattern established by other content type constructor functions, properly setting the type, data, and MIME type fields.


449-456: LGTM! Proper handling of audio content in ParseContent function.

The implementation correctly follows the pattern established for other content types, properly extracting and validating the data and MIME type fields for audio content.

Comment on lines +256 to +271
// NewToolResultAudio creates a new CallToolResult with both text and audio content
func NewToolResultAudio(text, imageData, mimeType string) *CallToolResult {
return &CallToolResult{
Content: []Content{
TextContent{
Type: "text",
Text: text,
},
AudioContent{
Type: "audio",
Data: imageData,
MIMEType: mimeType,
},
},
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Fix parameter name in NewToolResultAudio function.

The parameter is named imageData but is being used for audio data, which is confusing and misleading. This should be renamed to match its actual purpose.

-func NewToolResultAudio(text, imageData, mimeType string) *CallToolResult {
+func NewToolResultAudio(text, audioData, mimeType string) *CallToolResult {
    return &CallToolResult{
        Content: []Content{
            TextContent{
                Type: "text",
                Text: text,
            },
            AudioContent{
                Type:     "audio",
-               Data:     imageData,
+               Data:     audioData,
                MIMEType: mimeType,
            },
        },
    }
}
📝 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
// NewToolResultAudio creates a new CallToolResult with both text and audio content
func NewToolResultAudio(text, imageData, mimeType string) *CallToolResult {
return &CallToolResult{
Content: []Content{
TextContent{
Type: "text",
Text: text,
},
AudioContent{
Type: "audio",
Data: imageData,
MIMEType: mimeType,
},
},
}
}
// NewToolResultAudio creates a new CallToolResult with both text and audio content
func NewToolResultAudio(text, audioData, mimeType string) *CallToolResult {
return &CallToolResult{
Content: []Content{
TextContent{
Type: "text",
Text: text,
},
AudioContent{
Type: "audio",
Data: audioData,
MIMEType: mimeType,
},
},
}
}

@dugenkui03 dugenkui03 changed the title support audio content type support audio content type in tools/call and prompts/get May 6, 2025
@dugenkui03 dugenkui03 closed this May 6, 2025
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