curl -X POST https://generativelanguage.googleapis.com/v1beta/interactions \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-flash-latest",
"tools": [{
"type": "mcp_server",
"name": "weather_service",
"url": "https://gemini-api-demos.uc.r.appspot.com/mcp"
}],
"input": "Today is 12-05-2025, what is the temperature today in London?"
}'
import os
from google import genai
client = genai.Client()
response = client.interactions.create(
model="gemini-flash-latest",
tools=[{
"type": "mcp_server",
"name": "weather_service",
"url": "https://gemini-api-demos.uc.r.appspot.com/mcp",
}],
input="Today is 12-05-2025, what is the temperature today in London?",
)
print(response.output_text)
import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({});
const interaction = await ai.interactions.create({
model: 'gemini-flash-latest',
tools: [
{
type: 'mcp_server',
name: 'weather_service',
url: 'https://gemini-api-demos.uc.r.appspot.com/mcp',
},
],
input: 'Today is 12-05-2025, what is the temperature today in London?',
});
console.log(interaction.output_text);
import com.google.genai.Client;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import com.google.genai.gaos.models.operations.CreateInteractionResponse;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.MCPServer;
Client client = new Client();
MCPServer mcpTool =
MCPServer.builder()
.name("weather_service")
.url("https://gemini-api-demos.uc.r.appspot.com/mcp")
.build();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model("gemini-flash-latest")
.tools(List.of(mcpTool))
.input(
InteractionsInput.of(
"Today is 12-05-2025, what is the temperature today in London?"))
.build();
CreateInteractionResponse response =
client.interactions.create(CreateInteractionRequestBody.of(params));
Interaction interaction =
response.interaction().orElseThrow(() -> new RuntimeException("No interaction returned"));
System.out.println(interaction.outputText().orElse(""));
package main
import (
"context"
"fmt"
"log"
"os"
"google.golang.org/genai"
gaos_interactions "google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
mcpServer := gaos_interactions.MCPServer{
Name: genai.Ptr("weather_service"),
URL: genai.Ptr("https://gemini-api-demos.uc.r.appspot.com/mcp"),
}
tool := gaos_interactions.NewTool(mcpServer)
body := operations.NewCreateInteractionRequestBody(gaos_interactions.CreateModelInteraction{
Model: gaos_interactions.Model("gemini-flash-latest"),
Input: genai.Ptr(gaos_interactions.NewInteractionsInput("Today is 12-05-2025, what is the temperature today in London?")),
Tools: []gaos_interactions.Tool{tool},
})
req := operations.CreateInteractionRequest{
Body: body,
}
res, err := client.Interactions.Create(ctx, req)
if err != nil {
log.Fatal(err)
}
if res.Interaction != nil && res.Interaction.OutputText != nil {
fmt.Println(*res.Interaction.OutputText)
}
}