adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

ADK does not support MCP Sample

Open shivsant opened this issue 1 year ago • 4 comments

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:

  1. Install - google-adk[a2a]==1.13.0, fastmcp==2.12.2,
  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}
  1. See error Expected behavior google adk should also support fastmcp native features.
Image

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

shivsant avatar Sep 09 '25 18:09 shivsant

Any update on this?

shivsant avatar Oct 07 '25 18:10 shivsant

@lizzij will take a look at this issue.

lizzij avatar Oct 27 '25 16:10 lizzij

Able to replicate issue with gemini-2.5-flash or openai/gpt-4o as the base model.

Image

Hello world example with FastMCP working-as-intended.

Image

lizzij avatar Oct 27 '25 21:10 lizzij

[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"
)
Image

lizzij avatar Oct 27 '25 23:10 lizzij