Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions docs/development/v3-notes/v3-features.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,38 @@ result = await ctx.sample(
)
```

### Google GenAI Sampling Handler

FastMCP now includes a sampling handler for Google's Gemini models ([#2977](https://github.com/jlowin/fastmcp/pull/2977)). This enables MCP clients to use Google's GenAI models with the sampling protocol, including full tool calling support.

```python
from fastmcp import Client
from fastmcp.client.sampling.handlers import GoogleGenaiSamplingHandler
from google.genai import Client as GoogleGenaiClient

# Initialize the handler
handler = GoogleGenaiSamplingHandler(
default_model="gemini-2.0-flash-exp",
client=GoogleGenaiClient(), # Optional - creates one if not provided
)

# Use with MCP sampling (handler is configured at Client construction)
async with Client("http://server/mcp", sampling_handler=handler) as client:
result = await client.sample(
messages=[...],
tools=[...],
)
```

Key features:
- Converts MCP tool schemas to Google's function calling format
- Supports all Google GenAI models that implement function calling
- Handles nullable types, nested objects, and arrays in tool schemas
- Properly maps tool choices (`auto`, `required`, `none`) to Google's configuration
- Preserves model preferences from MCP sampling parameters

The handler joins the existing Anthropic and OpenAI handlers, providing a consistent interface for model-agnostic sampling across providers.

### Concurrent Tool Execution in Sampling

When an LLM returns multiple tool calls in a single sampling response, they can now be executed concurrently ([#3022](https://github.com/PrefectHQ/fastmcp/pull/3022)). Default behavior remains sequential; opt in with `tool_concurrency`. Tools can declare `sequential=True` to force sequential execution even when concurrency is enabled.
Expand Down
17 changes: 17 additions & 0 deletions docs/python-sdk/fastmcp-client-sampling-handlers-google_genai.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: google_genai
sidebarTitle: google_genai
---
Comment on lines +1 to +4

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Revert manual edits under docs/python-sdk

This commit adds docs/python-sdk/fastmcp-client-sampling-handlers-google_genai.mdx, but /workspace/fastmcp/AGENTS.md explicitly states: “Do not manually modify docs/python-sdk/** — these files are auto-generated … Do not include changes to these files in contributor PRs.” Keeping this file in a regular feature commit will create churn and likely be overwritten by the generator bot, so this generated-doc change should be removed from the commit.

Useful? React with 👍 / 👎.


# `fastmcp.client.sampling.handlers.google_genai`


Google GenAI sampling handler with tool support for FastMCP 3.0.

## Classes

### `GoogleGenaiSamplingHandler` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/client/sampling/handlers/google_genai.py#L54" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>


Sampling handler that uses the Google GenAI API with tool support.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ anthropic = ["anthropic>=0.40.0"]
apps = ["prefab-ui>=0.6.0"]
azure = ["azure-identity>=1.16.0"]
code-mode = ["pydantic-monty>=0.0.7"]
gemini = ["google-genai>=1.18.0"]
openai = ["openai>=1.102.0"]
tasks = ["pydocket>=0.18.0"]

[dependency-groups]
dev = [
"dirty-equals>=0.9.0",
"fastmcp[anthropic,apps,azure,code-mode,openai,tasks]",
"fastmcp[anthropic,apps,azure,code-mode,gemini,openai,tasks]",
# add optional dependencies for fastmcp dev
"fastapi>=0.115.12",
"opentelemetry-sdk>=1.20.0",
Expand Down
Loading
Loading