ADK does not support MCP Sample
Describe the bug When I add the sample to mcp, I can utilize it in other clients, but not in adk. I get the error - ValueError: Client does not support sampling
To Reproduce Steps to reproduce the behavior:
- Install - google-adk[a2a]==1.13.0, fastmcp==2.12.2,
- Run - create the mcp server as https://gofastmcp.com/servers/sampling
mcp = FastMCP("SamplingDemo") @mcp.tool async def analyze_sentiment(text: str, ctx: Context) -> dict: """Analyze the sentiment of text using the client's LLM.""" prompt = f"""Analyze the sentiment of the following text as positive, negative, or neutral. Just output a single word - 'positive', 'negative', or 'neutral'. Text to analyze: {text}""" # Request LLM analysis response = await ctx.sample(prompt) # Process the LLM's response sentiment = response.text.strip().lower() # Map to standard sentiment values if "positive" in sentiment: sentiment = "positive" elif "negative" in sentiment: sentiment = "negative" else: sentiment = "neutral" return {"text": text, "sentiment": sentiment}
- See error Expected behavior google adk should also support fastmcp native features.
Desktop (please complete the following information):
- OS: sles15
- Python version(python -V): 3.11.1
- ADK version(pip show google-adk): 1.13.0
Model Information: openai/gpt4o, claude-sonnet-4
Additional context Created discussion also, but no help. https://github.com/google/adk-python/discussions/2892
Any update on this?
@lizzij will take a look at this issue.
Able to replicate issue with gemini-2.5-flash or openai/gpt-4o as the base model.
Hello world example with FastMCP working-as-intended.
[Workaround]: Use Server-Controlled Mode (using the Server's LLM)
# Set up server's private LLM handler
llm_handler = OpenAISamplingHandler(
default_model="gpt-4o", # Specify the gpt-4o model
client=OpenAI(
api_key=API_KEY,
),
)
# Create the FastMCP Server instance
mcp = FastMCP(
name="SamplingDemo",
# This tells the server to use its own LLM
sampling_handler=llm_handler,
# This forces the server to *always* use its handler
# and never ask the client (your ADK agent)
sampling_handler_behavior="always"
)