Skip to content

Add support in binary tool responses#12

Merged
eyalzh merged 1 commit intomainfrom
support-binary-data
Aug 27, 2025
Merged

Add support in binary tool responses#12
eyalzh merged 1 commit intomainfrom
support-binary-data

Conversation

@eyalzh
Copy link
Owner

@eyalzh eyalzh commented Aug 27, 2025

No description provided.

@eyalzh eyalzh requested a review from Copilot August 27, 2025 11:50
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for handling binary data (images, audio, blobs) in MCP tool and resource responses. The implementation includes saving binary content to files and returning file paths for use in templates.

  • Adds binary data handler module with file saving capabilities
  • Updates MCP tool/resource functions to handle binary content types
  • Includes comprehensive test coverage for the new functionality

Reviewed Changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
mcp_client/binary_data_handler.py New module providing binary data handling and file saving functionality
mcp_client/init.py Exports new binary handling functions
engine/globals.py Updates MCP tool/resource functions to handle binary content
engine/template_engine.py Passes state to global functions for binary handling
prompt/prompt_helper.py Adds binary content handling to variable collection
tests/test_binary_data_handler.py Comprehensive test suite for binary data handling
tests/mcp_test_server.py Adds test tool that returns binary data
tests/templates/spec9.md Updates test template header
tests/templates/spec10.md New test template for binary content
README.md Adds documentation for MCP tool/resource selection

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +69 to +70
# For blob resources, we don't have mime type info, so we'll save as generic file
return save_binary_data_to_file(config_dir, content.blob, "application/octet-stream", "blob")
Copy link

Copilot AI Aug 27, 2025

Choose a reason for hiding this comment

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

The comment is incorrect. BlobResourceContents has a mimeType field that should be used instead of hardcoding 'application/octet-stream'.

Suggested change
# For blob resources, we don't have mime type info, so we'll save as generic file
return save_binary_data_to_file(config_dir, content.blob, "application/octet-stream", "blob")
# For blob resources, use the provided mimeType field
return save_binary_data_to_file(config_dir, content.blob, content.mimeType, "blob")

Copilot uses AI. Check for mistakes.
Comment on lines +69 to +70
# For blob resources, we don't have mime type info, so we'll save as generic file
return save_binary_data_to_file(config_dir, content.blob, "application/octet-stream", "blob")
Copy link

Copilot AI Aug 27, 2025

Choose a reason for hiding this comment

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

Should use content.mimeType instead of hardcoded 'application/octet-stream'. BlobResourceContents has a mimeType field available.

Suggested change
# For blob resources, we don't have mime type info, so we'll save as generic file
return save_binary_data_to_file(config_dir, content.blob, "application/octet-stream", "blob")
# Use the mimeType field from BlobResourceContents if available
return save_binary_data_to_file(config_dir, content.blob, content.mimeType, "blob")

Copilot uses AI. Check for mistakes.
content_parts.append(str(text_content))
# For non-text content, convert to string
# Handle binary content types
if isinstance(item, types.ImageContent | types.AudioContent):
Copy link

Copilot AI Aug 27, 2025

Choose a reason for hiding this comment

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

The isinstance check should include types.BlobResourceContents to handle all binary content types consistently with the binary_data_handler module.

Suggested change
if isinstance(item, types.ImageContent | types.AudioContent):
if isinstance(item, (types.ImageContent, types.AudioContent, types.BlobResourceContents)):

Copilot uses AI. Check for mistakes.
@eyalzh eyalzh changed the title Add supoprt in binary tool responses Add support in binary tool responses Aug 27, 2025
@eyalzh eyalzh merged commit 9e3d906 into main Aug 27, 2025
1 check 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.

1 participant