Add MCP_DISABLE_EMBEDDED_RESOURCES feature flag for client compatibility#1956
Add MCP_DISABLE_EMBEDDED_RESOURCES feature flag for client compatibility#1956
Conversation
- Added FeatureFlagDisableEmbeddedResources constant to feature_flags.go - Implemented NewToolResultResourceWithFlag in utils/result.go - When flag is enabled, returns TextContent for text files - Returns ImageContent with base64 data for binary files - Maintains backward compatibility when flag is disabled - Updated get_file_contents tool to check feature flag and use new function - Added comprehensive tests for both utils function and integration with get_file_contents Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
- Added Feature Flags section to server-configuration.md - Added troubleshooting note to Antigravity installation guide - Fixed linter issue in result_test.go - Generated updated documentation Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
The MCP SDK handles base64 encoding during JSON marshaling, so the Data field should contain raw binary data, not pre-encoded base64 strings. This prevents double-encoding where base64 strings were being encoded again. - Updated NewToolResultResourceWithFlag to pass raw binary data - Updated test to verify raw binary data instead of base64 string - Removed unused encoding/base64 imports Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
- Updated test to verify raw binary data matches expected value - Fixed comment to accurately describe what is being verified - Ensures test properly validates SDK's base64 encoding behavior Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds the MCP_DISABLE_EMBEDDED_RESOURCES feature flag to improve compatibility with MCP clients that have limited embedded resource support. When enabled, the get_file_contents tool returns file contents as standard MCP content types (TextContent for text files, ImageContent for binary files) instead of EmbeddedResource.
Changes:
- Added runtime feature flag
MCP_DISABLE_EMBEDDED_RESOURCESto control content serialization format - Created
NewToolResultResourceWithFlag()utility function with conditional logic based on flag state - Updated
get_file_contentstool to check flag and use new utility function at all return sites - Added comprehensive test coverage for flag-enabled and flag-disabled scenarios
- Documented feature flag usage and added troubleshooting guidance for Antigravity client
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/github/feature_flags.go | Defines the new MCP_DISABLE_EMBEDDED_RESOURCES feature flag constant with documentation |
| pkg/utils/result.go | Implements NewToolResultResourceWithFlag() to return TextContent/ImageContent when flag is enabled, with fallback to EmbeddedResource |
| pkg/utils/result_test.go | Comprehensive unit tests covering all branches: flag disabled, text content with flag, binary content with flag, and empty content fallback |
| pkg/github/repositories.go | Updates get_file_contents to check feature flag at 4 return sites (text/binary with/without SHA) |
| pkg/github/repositories_test.go | Integration tests verifying flag behavior with mocked HTTP client for text and binary files |
| docs/server-configuration.md | Adds Feature Flags section documenting flag purpose, usage, and configuration for local/remote servers |
| docs/installation-guides/install-antigravity.md | Adds troubleshooting guidance for file content display issues with note about upcoming remote server support |
pkg/utils/result.go
Outdated
| }, | ||
| } | ||
| case len(contents.Blob) > 0: | ||
| // Binary content - use ImageContent with base64 data |
There was a problem hiding this comment.
This comment mentions "base64 data" which could be misleading. ImageContent stores raw binary data in the Data field, not base64-encoded data. The SDK handles the base64 encoding only during JSON marshaling (as noted in the comment below), so this comment should say "Binary content - use ImageContent with raw binary data" to be more accurate.
| // Binary content - use ImageContent with base64 data | |
| // Binary content - use ImageContent with raw binary data |
There was a problem hiding this comment.
Fixed in 916c71b - updated comment to say "Binary content - use ImageContent with raw binary data".
pkg/utils/result.go
Outdated
| var content mcp.Content | ||
| switch { | ||
| case contents.Text != "": | ||
| // Text content - use TextContent with mime type in annotations |
There was a problem hiding this comment.
The comment incorrectly states "mime type in annotations" but the MIME type is actually stored in Meta, not Annotations. The comment should be corrected to say "mime type in metadata" or "mime type in Meta" for accuracy.
| // Text content - use TextContent with mime type in annotations | |
| // Text content - use TextContent with mime type in metadata (Meta) |
There was a problem hiding this comment.
Fixed in 916c71b - updated comment to say "Text content - use TextContent with MIME type in metadata".
SamMorrowDrums
left a comment
There was a problem hiding this comment.
@copilot I left a bunch of cleanup suggestions amounting to:
- no trailers in documentation
- ignore remote server, just document the ENV and arg methods for STDIO server feature flag configuration
- no pointless function rename
|
|
||
| If you experience issues with the `get_file_contents` tool not displaying file contents correctly, this may be due to limited embedded resource support in some versions of Antigravity. | ||
|
|
||
| **Solution:** The remote GitHub MCP Server will soon support the `MCP_DISABLE_EMBEDDED_RESOURCES` feature flag to improve compatibility. This flag makes file contents return as standard MCP content types that work better across different clients. |
There was a problem hiding this comment.
@copilot the spoiler soon support is not good. Neither is for updates on this feature you should just document. We can ignore the remote server entirely for now, and update that once it's shipped.
There was a problem hiding this comment.
Updated in 916c71b - removed "soon support" and "for updates" references, simplified to just document the known limitation.
docs/server-configuration.md
Outdated
| **Coming soon:** Remote server support for this flag will be available in the next release. | ||
|
|
||
| </td> | ||
| <td> | ||
|
|
||
| Feature flags are checked at runtime via the feature flag checker. Configuration method depends on your deployment: | ||
|
|
||
| **For custom integrations:** | ||
| ```go | ||
| featureChecker := func(ctx context.Context, flagName string) (bool, error) { | ||
| if flagName == "MCP_DISABLE_EMBEDDED_RESOURCES" { | ||
| return true, nil // Enable the flag | ||
| } | ||
| return false, nil | ||
| } | ||
| ``` | ||
|
|
||
| </td> | ||
| </tr> | ||
| </table> | ||
|
|
||
| > **Note:** This feature flag does not affect other tools, only `get_file_contents`. The default behavior (embedded resources) is maintained when the flag is not enabled, ensuring backward compatibility. |
There was a problem hiding this comment.
All of the selection is redundant. We don't need to add trailers or describe what tools it does or doesn't do or mention the remote server yet.
There was a problem hiding this comment.
Removed in 916c71b - simplified to just explain what the flag does and that it's configured via feature flag checker, removed remote server references and extra notes.
pkg/github/repositories.go
Outdated
| // Include SHA in the result metadata | ||
| if fileSHA != "" { | ||
| return utils.NewToolResultResource(fmt.Sprintf("successfully downloaded text file (SHA: %s)", fileSHA)+successNote, result), nil, nil | ||
| return utils.NewToolResultResourceWithFlag(fmt.Sprintf("successfully downloaded text file (SHA: %s)", fileSHA)+successNote, result, disableEmbedded), nil, nil |
There was a problem hiding this comment.
Did we need to rename this function at all? I don't think so, the flag is not material to the naming of the function, it's just a new argument. @copilot
There was a problem hiding this comment.
Fixed in 916c71b - reverted to using NewToolResultResource with the flag as a new parameter instead of creating a separate function.
pkg/github/repositories.go
Outdated
| MIMEType: contentType, | ||
| } | ||
| // Check if embedded resources should be disabled | ||
| disableEmbedded := deps.IsFeatureEnabled(ctx, FeatureFlagDisableEmbeddedResources) |
There was a problem hiding this comment.
Are we checking this twice in same function?
There was a problem hiding this comment.
Fixed in 916c71b - moved flag check before the if/else block so it's only checked once and reused for both text and binary content paths.
- Reverted function rename: NewToolResultResource now takes flag parameter directly - Fixed duplicate flag checks: check once and reuse variable - Fixed comments: "base64 data" → "raw binary data", "annotations" → "metadata" - Simplified Antigravity docs: removed "soon support" and update references - Simplified server-configuration.md: removed remote server mentions and redundant notes Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
All addressed in 916c71b:
|
Summary
Adds
MCP_DISABLE_EMBEDDED_RESOURCESfeature flag to return file contents as standard MCP content types (TextContent/ImageContent) instead of EmbeddedResource, improving compatibility with clients like Antigravity.Why
Some MCP clients have limited embedded resource support, causing
get_file_contentsto fail or display incorrectly.What changed
FeatureFlagDisableEmbeddedResourcesconstant topkg/github/feature_flags.goNewToolResultResource()inpkg/utils/result.goto accept flag parameter:TextContentwith MIME type in metadataImageContentwith raw binary dataEmbeddedResource(backward compatible)get_file_contentsto check flag once and pass to utility function (simplified from duplicate checks)docs/server-configuration.mdwith simplified configuration guidanceMCP impact
get_file_contentsbehavior changes when feature flag is enabled. Schema unchanged. Default behavior (flag disabled) preserves existing EmbeddedResource format.Prompts tested (tool changes only)
Security / limits
Feature flag only changes content serialization format. No auth, data exposure, or rate limit implications.
Tool renaming
Lint & tests
./script/lint./script/testDocs
Added Feature Flags section to server configuration guide and troubleshooting note to Antigravity installation guide. Documentation simplified to remove remote server references and focus on local server configuration.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.