Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/toolbox-adk/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ classifiers = [
requires-python = ">=3.10"
dependencies = [
"toolbox-core==0.6.0",
"google-auth>=2.43.0,<3.0.0",
"google-auth>=2.47.0,<3.0.0",
"google-auth-oauthlib>=1.2.0,<2.0.0",
"google-adk>=1.20.0,<3.0.0",
"google-adk>=1.26.0,<3.0.0",
"typing-extensions>=4.0.0"
]

Expand Down
4 changes: 2 additions & 2 deletions packages/toolbox-adk/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-e ../toolbox-core
google-adk==1.20.0
google-auth==2.45.0
google-adk==1.27.2
google-auth==2.47.0
google-auth-oauthlib==1.2.1
typing-extensions==4.14.1
opentelemetry-exporter-otlp-proto-http==1.37.0
Expand Down
30 changes: 1 addition & 29 deletions packages/toolbox-adk/src/toolbox_adk/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import logging
from typing import Any, Awaitable, Callable, Dict, Mapping, Optional

import google.adk.auth.exchanger.oauth2_credential_exchanger as oauth2_credential_exchanger
import google.adk.auth.oauth2_credential_util as oauth2_credential_util
import toolbox_core
from fastapi.openapi.models import (
OAuth2,
Expand All @@ -40,26 +38,6 @@
from .client import USER_TOKEN_CONTEXT_VAR
from .credentials import CredentialConfig, CredentialType

# --- Monkey Patch ADK OAuth2 Exchange to Retain ID Tokens ---
# Google's ID Token is required by MCP Toolbox but ADK's `update_credential_with_tokens` natively drops the `id_token`.
# TODO(id_token): Remove this monkey patch once the PR https://github.com/google/adk-python/pull/4402 is merged.
_orig_update_cred = oauth2_credential_util.update_credential_with_tokens


def _patched_update_credential_with_tokens(auth_credential, tokens):
_orig_update_cred(auth_credential, tokens)
if tokens and "id_token" in tokens and auth_credential and auth_credential.oauth2:
setattr(auth_credential.oauth2, "id_token", tokens["id_token"])


oauth2_credential_util.update_credential_with_tokens = (
_patched_update_credential_with_tokens
)
oauth2_credential_exchanger.update_credential_with_tokens = (
_patched_update_credential_with_tokens
)
# -------------------------------------------------------------


class ToolboxTool(BaseTool):
"""
Expand Down Expand Up @@ -256,15 +234,9 @@ async def run_async(
not hasattr(self._core_tool, "_auth_token_getters")
or s not in self._core_tool._auth_token_getters
):
# TODO(id_token): Uncomment this line and remove the `getattr` fallback below once PR https://github.com/google/adk-python/pull/4402 is merged.
# self._core_tool = self._core_tool.add_auth_token_getter(s, lambda t=creds.oauth2.id_token or creds.oauth2.access_token: t)
self._core_tool = self._core_tool.add_auth_token_getter(
s,
lambda t=getattr(
creds.oauth2,
"id_token",
creds.oauth2.access_token,
): t,
lambda t=creds.oauth2.id_token or creds.oauth2.access_token: t,
)
# Once we use it from get_auth_response, save it to the auth service for future use
try:
Expand Down
Loading