Skip to content

Commit cca8c56

Browse files
DineshThumma9haranrk
authored andcommitted
feat(tools): exposed configurable parameter as property in McpToolset
Merge #4271 **Please ensure you have read the [contribution guide](https://github.com/google/adk-python/blob/main/CONTRIBUTING.md) before creating a pull request.** ### Link to Issue or Description of Change - Closes: #4270 **Problem:** When using MCP tools with McpToolset, configuration information for the object is not exposed as object properties or attributes meaning that 'private' attributes need to be accessed, e.g. toolset._connection_params rather than toolset.connection_params **Solution:** Exposed them as properties ### Testing Plan **Unit Tests:** - [x] I have added or updated unit tests for my change. - [x] All unit tests pass locally. **Manual End-to-End (E2E) Tests:** I have added new test cases also checked locally ### Checklist - [x] I have read the [CONTRIBUTING.md](https://github.com/google/adk-python/blob/main/CONTRIBUTING.md) document. - [x] I have performed a self-review of my own code. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have added tests that prove my fix is effective or that my feature works. - [x] New and existing unit tests pass locally with my changes. - [x] I have manually tested my changes end-to-end. - [x] Any dependent changes have been merged and published in downstream modules. ### Additional context Co-authored-by: Haran Rajkumar <haranrk@google.com> COPYBARA_INTEGRATE_REVIEW=#4271 from DineshThumma9:mcp-missing-attr 3d48401 PiperOrigin-RevId: 943396972
1 parent 1509dcf commit cca8c56

2 files changed

Lines changed: 100 additions & 0 deletions

File tree

src/google/adk/tools/mcp_tool/mcp_toolset.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,41 @@ def _get_auth_headers(
286286

287287
return headers
288288

289+
@property
290+
def connection_params(self) -> Union[
291+
StdioServerParameters,
292+
StdioConnectionParams,
293+
SseConnectionParams,
294+
StreamableHTTPConnectionParams,
295+
]:
296+
return self._connection_params
297+
298+
@property
299+
def auth_scheme(self) -> Optional[AuthScheme]:
300+
return self._auth_scheme
301+
302+
@property
303+
def auth_credential(self) -> Optional[AuthCredential]:
304+
return self._auth_credential
305+
306+
@property
307+
def require_confirmation(self) -> Union[bool, Callable[..., bool]]:
308+
return self._require_confirmation
309+
310+
@property
311+
def header_provider(
312+
self,
313+
) -> Optional[
314+
Callable[
315+
[ReadonlyContext], Union[Dict[str, str], Awaitable[Dict[str, str]]]
316+
]
317+
]:
318+
return self._header_provider
319+
320+
@property
321+
def errlog(self) -> TextIO:
322+
return self._errlog
323+
289324
async def _execute_with_session(
290325
self,
291326
coroutine_func: Callable[[Any], Awaitable[T]],

tests/unittests/tools/mcp_tool/test_mcp_toolset.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from unittest.mock import Mock
2323

2424
from fastapi.openapi.models import OAuth2
25+
from fastapi.openapi.models import OAuthFlowAuthorizationCode
26+
from fastapi.openapi.models import OAuthFlows
2527
from google.adk.agents.readonly_context import ReadonlyContext
2628
from google.adk.auth.auth_credential import AuthCredential
2729
from google.adk.auth.auth_credential import AuthCredentialTypes
@@ -96,6 +98,69 @@ def test_init_with_use_mcp_resources(self):
9698
)
9799
assert toolset._use_mcp_resources is True
98100

101+
def test_connection_params(self):
102+
"""Test getting connection params."""
103+
toolset = McpToolset(connection_params=self.mock_stdio_params)
104+
assert toolset.connection_params == self.mock_stdio_params
105+
106+
def test_auth_scheme(self):
107+
"""Test getting auth scheme."""
108+
toolset = McpToolset(connection_params=self.mock_stdio_params)
109+
assert toolset.auth_scheme is None
110+
111+
def test_auth_credential(self):
112+
"""Test getting auth credential."""
113+
toolset = McpToolset(connection_params=self.mock_stdio_params)
114+
assert toolset.auth_credential is None
115+
116+
def test_error_log(self):
117+
"""Test getting error log."""
118+
toolset = McpToolset(connection_params=self.mock_stdio_params)
119+
assert toolset.errlog == sys.stderr
120+
121+
def test_auth_scheme_with_value(self):
122+
"""Test getting auth scheme when provided at initialization."""
123+
auth_scheme = OAuth2(
124+
flows=OAuthFlows(
125+
authorizationCode=OAuthFlowAuthorizationCode(
126+
authorizationUrl="https://example.com/auth",
127+
tokenUrl="https://example.com/token",
128+
scopes={"read": "Read access"},
129+
)
130+
)
131+
)
132+
toolset = McpToolset(
133+
connection_params=self.mock_stdio_params,
134+
auth_scheme=auth_scheme,
135+
)
136+
assert toolset.auth_scheme == auth_scheme
137+
138+
def test_require_confirmation(self):
139+
"""Test getting require_confirmation flag."""
140+
toolset = McpToolset(
141+
connection_params=self.mock_stdio_params,
142+
require_confirmation=True,
143+
)
144+
assert toolset.require_confirmation is True
145+
146+
def test_header_provider(self):
147+
"""Test getting header_provider."""
148+
mock_header_provider = Mock()
149+
toolset = McpToolset(
150+
connection_params=self.mock_stdio_params,
151+
header_provider=mock_header_provider,
152+
)
153+
assert toolset.header_provider == mock_header_provider
154+
155+
def test_auth_credential_with_value(self):
156+
"""Test getting auth credential when provided at initialization."""
157+
mock_credential = Mock(spec=AuthCredential)
158+
toolset = McpToolset(
159+
connection_params=self.mock_stdio_params,
160+
auth_credential=mock_credential,
161+
)
162+
assert toolset.auth_credential == mock_credential
163+
99164
def test_init_with_stdio_connection_params(self):
100165
"""Test initialization with StdioConnectionParams."""
101166
stdio_params = StdioConnectionParams(

0 commit comments

Comments
 (0)