Skip to content

Commit a9d2c83

Browse files
committed
docs(toolbox-adk): improve README with comprehensive usage examples
1 parent 3516e5e commit a9d2c83

File tree

1 file changed

+129
-7
lines changed

1 file changed

+129
-7
lines changed

packages/toolbox-adk/README.md

Lines changed: 129 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
![MCP Toolbox Logo](https://raw.githubusercontent.com/googleapis/genai-toolbox/main/logo.png)
2+
13
# Toolbox ADK Integration
24

3-
This package allows Google ADK agents to natively use tools from the MCP Toolbox.
5+
This package allows Google ADK (Agent Development Kit) agents to natively use tools from the [MCP Toolbox](https://github.com/googleapis/genai-toolbox).
6+
7+
It provides a seamless bridge between the `toolbox-core` SDK and the ADK's `BaseTool` / `BaseToolset` interfaces, handling authentication propagation, header management, and tool wrapping automatically.
48

59
## Installation
610

@@ -10,18 +14,136 @@ pip install toolbox-adk
1014

1115
## Usage
1216

17+
The primary entry point is the `ToolboxToolset`, which loads tools from a remote Toolbox server and adapts them for use with ADK agents.
18+
1319
```python
1420
from toolbox_adk import ToolboxToolset, CredentialStrategy
21+
from google.adk.agents import Agent
1522

16-
# Configure auth (e.g., Use the agent's identity)
17-
creds = CredentialStrategy.toolbox_identity()
23+
# 1. Configure Authentication Strategy
24+
# Use the agent's own identity (Workload Identity)
25+
creds = CredentialStrategy.workload_identity(target_audience="https://my-toolbox-service-url")
26+
27+
# 2. Create the Toolset
28+
toolset = ToolboxToolset(
29+
server_url="https://my-toolbox-service-url",
30+
toolset_name="my-toolset", # Optional: Load specific toolset
31+
credentials=creds
32+
)
33+
34+
# 3. Use in your ADK Agent
35+
agent = Agent(tools=toolset.get_tools())
36+
```
37+
38+
## Authentication Strategies
39+
40+
The `toolbox-adk` package provides flexible authentication strategies to handle `Client-to-Server` authentication (securing the connection to the Toolbox server) and `User Identity` propagation (authenticating the user for specific tools).
41+
42+
Use the `CredentialStrategy` factory methods to create your configuration.
43+
44+
### Workload Identity (Recommended for Cloud Run / GKE)
45+
46+
Uses the agent's environment credentials (ADC) to generate an OIDC ID token. This is the standard way for one service to authenticate to another on Google Cloud.
47+
48+
```python
49+
# target_audience should match the URL of your Toolbox server
50+
creds = CredentialStrategy.workload_identity(target_audience="https://my-toolbox-service.run.app")
1851

19-
# Create the toolset
2052
toolset = ToolboxToolset(
21-
server_url="http://localhost:5000",
53+
server_url="https://my-toolbox-service.run.app",
2254
credentials=creds
2355
)
56+
```
57+
58+
### User Identity (3-Legged OAuth)
59+
60+
Propagates the end-user's identity to the Toolbox. This is used when the tools themselves need to act on behalf of the user (e.g., accessing the user's Drive or Calendar).
61+
62+
```python
63+
creds = CredentialStrategy.user_identity(
64+
client_id="YOUR_CLIENT_ID",
65+
client_secret="YOUR_CLIENT_SECRET",
66+
scopes=["https://www.googleapis.com/auth/drive"]
67+
)
68+
```
69+
70+
### Manual Token (Development / Testing)
71+
72+
Manually supply a token (e.g., a static API key or a temporary token).
73+
74+
```python
75+
creds = CredentialStrategy.manual_token("my-secret-token")
76+
```
77+
78+
### Toolbox Identity (No Auth)
79+
80+
Use this if your Toolbox server does not require authentication (e.g., local development).
81+
82+
```python
83+
creds = CredentialStrategy.toolbox_identity()
84+
```
85+
86+
### Native ADK Integration
87+
88+
If you are using ADK's configuration system (`AuthConfig` objects), you can create the strategy directly from it.
89+
90+
```python
91+
# auth_config is an instance of google.adk.auth.auth_tool.AuthConfig
92+
creds = CredentialStrategy.from_adk_auth_config(auth_config)
93+
```
94+
95+
## Advanced Configuration
96+
97+
### Additional Headers
98+
99+
You can inject custom headers into every request made to the Toolbox server. This is useful for passing tracing IDs, API keys, or other metadata.
100+
101+
```python
102+
toolset = ToolboxToolset(
103+
server_url="...",
104+
additional_headers={
105+
"X-Trace-ID": "12345",
106+
"X-My-Header": lambda: get_dynamic_header_value() # Can be a callable
107+
}
108+
)
109+
```
110+
111+
### Global Parameter Binding
112+
113+
Bind values to tool parameters globally across all loaded tools. These values will be fixed and hidden from the LLM.
24114

25-
# Use in your agent
26-
# agent = Agent(tools=toolset.get_tools())
115+
```python
116+
toolset = ToolboxToolset(
117+
server_url="...",
118+
bound_params={
119+
"region": "us-central1",
120+
"api_key": lambda: get_api_key() # Can be a callable
121+
}
122+
)
123+
```
124+
125+
### Usage with Hooks
126+
127+
You can attach `pre_hook` and `post_hook` functions to execute logic before and after every tool invocation.
128+
129+
```python
130+
async def log_start(context):
131+
print(f"Starting tool {context.tool_name}")
132+
133+
async def log_end(context):
134+
print(f"Finished tool {context.tool_name}")
135+
136+
toolset = ToolboxToolset(
137+
server_url="...",
138+
pre_hook=log_start,
139+
post_hook=log_end
140+
)
27141
```
142+
143+
## Contributing
144+
145+
Contributions are welcome! Please refer to the `toolbox-core` [DEVELOPER.md](../toolbox-core/DEVELOPER.md) for general guidelines.
146+
147+
## License
148+
149+
This project is licensed under the Apache License 2.0.

0 commit comments

Comments
 (0)