Skip to content

Gemini Server Tools

Edit this page

Server tools are built-in capabilities provided by Gemini that allow the model to perform specific actions without requiring custom tool implementations. These tools run on Google's servers and provide access to external data and execution environments.

Overview

Gemini provides several server-side tools that can be enabled when calling the model:

  • URL Context - Fetches and analyzes content from URLs
  • Google Search - Performs web searches using Google
  • Code Execution - Executes code in a sandboxed environment

Available Server Tools

URL Context

The URL Context tool allows Gemini to fetch and analyze content from web pages. This is useful for:

  • Analyzing current web content
  • Extracting information from specific pages
  • Understanding context from external sources
1
2
3
4
5
6
7
8
9
$messages = new MessageBag(
    Message::ofUser('What was the 12 month Euribor rate a week ago based on https://www.euribor-rates.eu/en/current-euribor-rates/4/euribor-rate-12-months/')
);

$result = $platform->invoke('gemini-2.5-pro-preview-03-25, $messages, [
    'server_tools' => [
        'url_context' => true,
    ]
]);

The Google Search tool enables the model to search the web and incorporate search results into its results:

1
2
3
4
5
6
7
8
9
$messages = new MessageBag(
    Message::ofUser('What are the latest developments in quantum computing?')
);

$result = $platform->invoke('gemini-2.5-pro-preview-03-25', $messages, [
    'server_tools' => [
        'google_search' => true,
    ]
]);

Code Execution

The Code Execution tool provides a sandboxed environment for running code:

1
2
3
4
5
6
7
8
9
$messages = new MessageBag(
    Message::ofUser('Calculate the factorial of 20 and show me the code')
);

$result = $platform->invoke('gemini-2.5-pro-preview-03-25', [
    'server_tools' => [
        'code_execution' => true,
    ]
]);

Using Multiple Server Tools

You can enable multiple server tools simultaneously:

1
2
3
4
5
6
7
8
9
10
11
$messages = new MessageBag(
    Message::ofUser('Calculate the factorial of 20 and show me the code')
);

$result = $platform->invoke('gemini-2.5-pro-preview-03-25', [
    'server_tools' => [
        'url_context' => true,
        'google_search' => true,
        'code_execution' => true,
    ]
]);

Example

See examples/gemini/server-tools.php for a complete working example.

Limitations

  • API key must have appropriate permissions
  • Server tools may have usage quotas
  • Response times may vary based on the complexity of server tool operations
  • Not all Gemini model versions support all server tools
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version