fix(resources): skip post-fetch resolution for direct_proxy reads - #6503
Open
Ewertonslv wants to merge 1 commit into
Open
fix(resources): skip post-fetch resolution for direct_proxy reads#6503Ewertonslv wants to merge 1 commit into
Ewertonslv wants to merge 1 commit into
Conversation
In direct_proxy gateway mode, read_resource builds the final TextResourceContents/BlobResourceContents from the live upstream fetch, but execution then fell into the post-fetch "RESOLVE CONTENT" block, which calls getattr(content, "id") unconditionally. Those MCP-compliant models have no `id` field, so every direct_proxy text or blob read raised AttributeError, was swallowed at the transport layer, and returned empty content to the client. Track whether the content was produced by the direct_proxy branch and skip the metadata->content resolution for it, keeping the gateway access and resource access checks and the post-fetch hooks intact. Adds regression tests that exercise the real (id-less) production models instead of the id-bearing test subclasses that previously masked the bug. Closes IBM#5451 Signed-off-by: Ewerton Silva <ewertoncom297@gmail.com>
Ewertonslv
requested review from
Lang-Akshay,
brian-hussey,
crivetimihai,
ja8zyjits and
msureshkumar88
as code owners
August 31, 2026 17:33
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Related Issue
Closes #5451
📝 Summary
In
direct_proxygateway mode,ResourceService.read_resourcefetches theresource live from the upstream and builds the final
TextResourceContents/BlobResourceContents. Execution then falls through into the shared post-fetchRESOLVE CONTENT block, whose first branch runs
getattr(content, "id")unconditionally. Those MCP-compliant models (
mcpgateway/common/models.py) haveno
idfield, so every direct_proxy text or blob read raisesAttributeError: 'TextResourceContents' object has no attribute 'id'. Thetransport layer catches the exception and returns empty content, so the client
silently receives
text=""instead of the fetched payload.Root cause
The direct_proxy branch never marked its content as already-resolved — the
# Skip the rest of the DB lookup logiccomment does not actually skip anything.Fix
Track whether content came from the direct_proxy branch (
direct_proxy_read) andskip the metadata→content resolution for it. The gateway access check, the
resource access check, and the post-fetch plugin hooks all still run — only the
id-based
invoke_resourcere-resolution is bypassed, since the payload is final.Tests (before → after)
The existing happy-path direct_proxy tests masked the bug by monkey-patching
id-bearing subclasses over the real models, so production classes never took the
failing path. This PR adds two regression tests exercising the real
TextResourceContents/BlobResourceContents:AttributeErrorat thegetattr(content, "id")call.image/pngblob read returns itsblob, and
invoke_resourceis asserted not re-awaited.🔄 Rebase notes (2026-08-31)
Rebased onto current
main(ffcc0822). One conflict, resolved by keeping bothsides:
maingrew the_set_gateway_contenthelper immediately above theif isinstance(content, ...)branch. The helper is untouched — thedirect_proxy_readguard simply sits in front of it asif direct_proxy_read: ... elif isinstance(...).Re-verified against today's
main, since a lot landed in the six weeks the PR sat:getattr(content, "id")unconditionally, and the MCP-compliant models still haveno
id.main,both new tests fail with
AttributeError: 'TextResourceContents' object has no attribute 'id'; with thehunk applied, both pass.
pytest tests/unit/mcpgateway/services/test_resource_service.py— 309 passed.ruff check,ruff format --checkandblack --checkclean on both touched files.Also: #5451 is no longer labeled
triage(it isbug/COULDnow), which was theconcern I flagged in my comment on the original PR.
📏 Reviewability
triage🏷️ Type of Change