feat: allowlisting MCP tools for generate_content sessions - #2814
Conversation
Add google.genai.mcp.with_allowed_tools so callers can expose a subset of MCP session tools to the model and AFC map without changing bare ClientSession behavior. Fixes googleapis#1089.
|
@Venkaiahbabuneelam hey — opened this for #1089. Passing an MCP session in Went with an opt-in wrapper instead so bare sessions stay the same: from google.genai import mcp as genai_mcp
tools=[genai_mcp.with_allowed_tools(session, ["tool_a", "tool_b"])]Filters in |
Make is_mcp_client_session a TypeGuard and accept allowlist wrappers in McpToGenAiToolAdapter so list_tools calls type-check under mypy.
|
@Venkaiahbabuneelam quick follow-up — mypy was failing because |
|
@Venkaiahbabuneelam sorry about the mypy noise on this one — that was on me. I missed that the session check wasnt narrowing the type, so CI blew up on Just pushed a fix for it. If you get a sec, could you re-approve / re-run the checks? Appreciate it. |
Summary
tools=[mcp_session]does not always expand every tool fromlist_tools().google.genai.mcp.with_allowed_tools(session, [...]), which wraps the session, filterslist_tools(), and rejects disallowedcall_tool()names.ClientSessionbehavior is unchanged. Filtering happens before adapter conversion so function declarations and the AFC map stay aligned for bothgenerate_contentand Live.Usage
Test plan
pytest google/genai/tests/mcp/ -qcall_toolrejectionmcp.with_allowed_tools(session, [...])look clear in review