fix: inject stored OAuth token for authorization_code gateway manual refresh#4194
Open
ecthelion77 wants to merge 1 commit intoIBM:mainfrom
Open
fix: inject stored OAuth token for authorization_code gateway manual refresh#4194ecthelion77 wants to merge 1 commit intoIBM:mainfrom
ecthelion77 wants to merge 1 commit intoIBM:mainfrom
Conversation
bc8c9f0 to
46e0eaf
Compare
…manual refresh Signed-off-by: Olivier Gintrand <olivier.gintrand@forterro.com>
46e0eaf to
ed67e4b
Compare
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.
Summary
Fixes #4193
The
POST /gateways/{id}/tools/refreshendpoint silently returns 0 tools for OAuth gateways using theauthorization_codegrant type, becauserefresh_gateway_manually()never retrieves the stored OAuth token fromTokenStorageService.Root Cause
_initialize_gateway()has an early-return at L4065-4074 forauthorization_codegateways whenoauth_auto_fetch_tool_flag=False(the default). Sincerefresh_gateway_manually()only passes HTTP passthrough headers (not the stored OAuth token), the function always takes the early-return path and returns{}, [], [], [].This is inconsistent with:
fetch_tools_after_oauth(), which retrieves the stored token and constructsAuthorization: Bearer {token}Fix
In
refresh_gateway_manually(), when the gateway usesauthorization_codeOAuth and the caller has auser_email:TokenStorageService.get_user_token()pre_auth_headers["Authorization"]This causes
_initialize_gateway()to usepre_auth_headers(L4058-4059), bypassing theauthorization_codeearly-return.Changes
mcpgateway/services/gateway_service.py: Added OAuth token retrieval inrefresh_gateway_manually()(26 lines)Testing
Tested against a live Azure AD Authorization Code OAuth gateway:
POST /gateways/{id}/tools/refresh→ 0 tools in 5msPOST /gateways/{id}/tools/refresh→ 4 tools imported correctly