Skip to content

Json schema function decl doesn't work for Bigquery MCP #4124

@xuanyang15

Description

@xuanyang15

Thanks to @jnuvola for reporting this issue! Let's track it here.

@xuanyang15 Really appreciate you looking into this! Here's a minimal reproduction:

import asyncio
import os
import google.auth
from google.auth.transport.requests import Request
from google.adk.agents import Agent
from google.adk.tools.mcp_tool.mcp_toolset import McpToolset
from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPConnectionParams
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
from google.genai import types

# Enable the flag
os.environ["ADK_ENABLE_JSON_SCHEMA_FOR_FUNC_DECL"] = "1"

BIGQUERY_MCP_URL = "https://bigquery.googleapis.com/mcp"
BIGQUERY_SCOPE = "https://www.googleapis.com/auth/bigquery"

async def main():
    # Get credentials
    credentials, project = google.auth.default(scopes=[BIGQUERY_SCOPE])
    credentials.refresh(Request())
    
    # Create BigQuery MCP toolset
    bq_toolset = McpToolset(
        connection_params=StreamableHTTPConnectionParams(
            url=BIGQUERY_MCP_URL,
            headers={"Authorization": f"Bearer {credentials.token}"},
            timeout=30.0,
        )
    )
    
    # Create agent with BigQuery MCP tools
    agent = Agent(
        model="gemini-2.5-flash",
        name="bq_agent",
        instruction="You are a BigQuery assistant.",
        tools=[bq_toolset],
    )
    
    runner = Runner(
        agent=agent,
        app_name="test",
        session_service=InMemorySessionService(),
    )
    
    session = await runner.session_service.create_session(
        app_name="test", user_id="test"
    )
    
    user_message = types.Content(
        role="user",
        parts=[types.Part(text="List datasets in my project")]
    )
    
    # This will fail with 400 INVALID_ARGUMENT
    async for event in runner.run_async(
        user_id="test",
        session_id=session.id,
        new_message=user_message,
    ):
        print(event)

if __name__ == "__main__":
    asyncio.run(main())

ADK_ENABLE_JSON_SCHEMA_FOR_FUNC_DECL=1 ->google.genai.errors.ClientError: 400 INVALID_ARGUMENT
ADK_ENABLE_JSON_SCHEMA_FOR_FUNC_DECL=0 -> works correctly

Originally posted by @jnuvola in #3995

Metadata

Metadata

Assignees

Labels

planned[Status] This issue is planned to be work on by ADK eng teamtools[Component] This issue is related to tools

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions