Skip to content

fix: avoid pickling MCP sessions when copying GenerateContentConfig - #2811

Open
a2105z wants to merge 1 commit into
googleapis:mainfrom
a2105z:fix/async-mcp-generate-content-config-copy
Open

fix: avoid pickling MCP sessions when copying GenerateContentConfig#2811
a2105z wants to merge 1 commit into
googleapis:mainfrom
a2105z:fix/async-mcp-generate-content-config-copy

Conversation

@a2105z

@a2105z a2105z commented Aug 4, 2026

Copy link
Copy Markdown

Summary

  • Fixes #2669: AsyncModels.generate_content / generate_content_stream crashed with TypeError: cannot pickle '_asyncio.Future' when config was a GenerateContentConfig containing an MCP ClientSession tool (dict configs already worked).
  • Adds copy_generate_content_config that clears tools before deep copy (Pydantic deep-copies before applying update), then reattaches tools by reference—same approach as the existing MCP parse helpers.
  • Uses the helper for async generate/stream entry points and AFC loop copies; adds unit/regression tests.

Test plan

  • pytest google/genai/tests/mcp/test_copy_generate_content_config.py google/genai/tests/mcp/test_parse_config_for_mcp_sessions.py
  • Covers deepcopy/pickle path with MCP ClientSession tools without TypeError
  • CI green
  • Manual (optional): await client.aio.models.generate_content(..., config=GenerateContentConfig(tools=[mcp_session]))

Async generate_content deep-copied config objects and crashed when tools
included an MCP ClientSession holding an asyncio.Future. Clear tools
before deep copy and reattach by reference, matching the existing MCP
parse helpers. Fixes googleapis#2669.
@a2105z

a2105z commented Aug 4, 2026

Copy link
Copy Markdown
Author

@Venkaiahbabuneelam this PR fixes the async generate_content pickle crash when GenerateContentConfig includes an MCP ClientSession tool; whenever you have a moment, I would really appreciate your review — thank you for your time.

@Venkaiahbabuneelam Venkaiahbabuneelam self-assigned this Aug 4, 2026
@Venkaiahbabuneelam Venkaiahbabuneelam added the size:XL Code changes > 100 lines label Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL Code changes > 100 lines

Projects

None yet

2 participants