|
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from google.adk.agents.llm_agent import LlmAgent |
| 16 | +from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPConnectionParams |
| 17 | +from google.adk.tools.mcp_tool.mcp_toolset import McpToolset |
| 18 | +import google.auth |
| 19 | + |
| 20 | +BIGQUERY_AGENT_NAME = "adk_sample_bigquery_mcp_agent" |
| 21 | +BIGQUERY_MCP_ENDPOINT = "https://bigquery.googleapis.com/mcp" |
| 22 | +BIGQUERY_SCOPE = "https://www.googleapis.com/auth/bigquery" |
| 23 | + |
| 24 | +# Initialize the tools to use the application default credentials. |
| 25 | +# https://cloud.google.com/docs/authentication/provide-credentials-adc |
| 26 | +credentials, project_id = google.auth.default(scopes=[BIGQUERY_SCOPE]) |
| 27 | +credentials.refresh(google.auth.transport.requests.Request()) |
| 28 | +oauth_token = credentials.token |
| 29 | + |
| 30 | +bigquery_mcp_toolset = McpToolset( |
| 31 | + connection_params=StreamableHTTPConnectionParams( |
| 32 | + url=BIGQUERY_MCP_ENDPOINT, |
| 33 | + headers={"Authorization": f"Bearer {oauth_token}"}, |
| 34 | + ) |
| 35 | +) |
| 36 | + |
| 37 | +# The variable name `root_agent` determines what your root agent is for the |
| 38 | +# debug CLI |
| 39 | +root_agent = LlmAgent( |
| 40 | + model="gemini-2.5-flash", |
| 41 | + name=BIGQUERY_AGENT_NAME, |
| 42 | + description=( |
| 43 | + "Agent to answer questions about BigQuery data and models and execute" |
| 44 | + " SQL queries using MCP." |
| 45 | + ), |
| 46 | + instruction="""\ |
| 47 | + You are a data science agent with access to several BigQuery tools provided via MCP. |
| 48 | + Make use of those tools to answer the user's questions. |
| 49 | + """, |
| 50 | + tools=[bigquery_mcp_toolset], |
| 51 | +) |
0 commit comments