Skip to content

AsyncModels.generate_content crashes with cannot pickle '_asyncio.Future' when config is a GenerateContentConfig object containing an MCP ClientSession tool #2669

Description

@SagarTubr

Environment

  • google-genai: 2.9.0
  • mcp: 1.28.1
  • Python: 3.12.13

The issue

Passing a live MCP ClientSession as a tool works when config is a dict, but the same settings passed as a GenerateContentConfig object raise TypeError: cannot pickle '_asyncio.Future' object.

In AsyncModels.generate_content, the config is deep-copied before MCP sessions are extracted — google/genai/models.py (2.9.0)

Steps to reproduce

  1. Create a live MCP ClientSession and pass it as a tool to aio.models.generate_content, with config as a GenerateContentConfig object:
    config=types.GenerateContentConfig(tools=[session]).
  2. The call raises TypeError: cannot pickle '_asyncio.Future' object before any network request.
  3. Pass the same settings as a dict instead — config={"tools": [session]} — and it works (session is extracted, request proceeds normally).

Metadata

Metadata

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions