Menu

Integrations / Model APIs

Gemini

MillionShort search for Gemini models, as a function tool in the Google Gen AI SDK, in Python and TypeScript.

Copy as MarkdownOpen in ChatGPT (opens in a new tab)Open in Claude (opens in a new tab)

RecipePython and TypeScriptNothing of ours to installWorks with no keyChecked 2026-11-19

The Gemini API has no remote MCP tool of its own: your code runs the search. In Python, pass a plain function as a tool and the SDK calls it for the model (automatic function calling). In TypeScript, declare the function and run the loop yourself. The SDKs can also take an MCP session you open to our server; Google marks that support experimental.

1Install

Choose one
Shell
pip install google-genai requests mcp httpx2
export MILLIONSHORT_API_KEY=ms-YOUR_API_KEY

The SDK reads your Gemini key from GEMINI_API_KEY (or GOOGLE_API_KEY). Get a MillionShort key in the dashboard; an agent can ask for a trial key by itself. The MCP packages (mcp and httpx2, @modelcontextprotocol/sdk and zod) are only for the MCP section further down.

2Minimal example

Choose one
Python
import json
import os

import requests
from google import genai
from google.genai import types


def millionshort_search(query: str) -> str:
    """Search the web with MillionShort, leaving out the 1,000 most popular sites.

    Args:
        query: What to search for.
    """
    r = requests.post(
        "https://api.millionshort.com/v1/search",
        headers={"Authorization": f"Bearer {os.environ['MILLIONSHORT_API_KEY']}"},
        json={"query": query, "remove_top_sites": 1000, "num_results": 5},
        timeout=30,
    )
    r.raise_for_status()
    return json.dumps([{"title": x["title"], "url": x["url"], "snippet": x.get("snippet")} for x in r.json()["data"]["results"]])


client = genai.Client()
response = client.models.generate_content(
    model="gemini-4-hydrogen",
    contents="Find independent blogs about home espresso.",
    config=types.GenerateContentConfig(tools=[millionshort_search]),
)
print(response.text)

The Python SDK builds the tool's schema from the type hints and the docstring, so keep both.

Google Search is a separate tool that runs only when you add it to tools, so leave it out. Then put a line like this in the system instruction (system_instruction in GenerateContentConfig, systemInstruction in the TypeScript config):

Use the MillionShort search tool for anything recent, niche, or that needs a source. To reach lesser-known sites, set remove_top_sites (for example 1000). Cite the URLs it returns.

4Check it works

Run the example, then ask:

Search MillionShort for forum threads about restoring a cast iron skillet, with the 1,000 most popular sites removed. List the five most useful with their links.

In TypeScript, response.functionCalls on the first turn names millionshort_search with a query. In Python, response.automatic_function_calling_history holds the calls the SDK made for the model.

With MCP: the hosted server

Open an MCP session to our server and pass it in tools; the SDK lists the tools and calls them for the model. Google marks this experimental. With MCP Python SDK 2.x, the headers go on the httpx2 client. Without a key, leave the headers out.

Choose one
Python
import asyncio
import os

import httpx2
from google import genai
from google.genai import types
from mcp import ClientSession
from mcp.client.streamable_http import streamable_http_client


async def main():
    headers = {"Authorization": f"Bearer {os.environ['MILLIONSHORT_API_KEY']}"}
    async with httpx2.AsyncClient(headers=headers, timeout=httpx2.Timeout(30.0, read=300.0)) as http:
        async with streamable_http_client("https://mcp.millionshort.com/mcp", http_client=http) as (read, write):
            async with ClientSession(read, write) as session:
                await session.initialize()
                response = await genai.Client().aio.models.generate_content(
                    model="gemini-4-hydrogen",
                    contents="Find independent blogs about home espresso.",
                    config=types.GenerateContentConfig(tools=[session]),
                )
                print(response.text)


asyncio.run(main())

The TypeScript SDK's README says automatic function calling from generateContent will move to its Chats module in a future major version; if this stops calling tools after an upgrade, use ai.chats.create with the same config.

MCP configuration

The same address for every client: https://mcp.millionshort.com/mcp, streamable HTTP.

ModeHowWhat the agent gets
API keySend Authorization: Bearer ms-YOUR_API_KEYEvery tool, at your plan's limits; calls use your credits
No keySend no Authorization headersearch, list_sources and a few more; one source and up to 5 results a search, 10 free searches a day

Tools

ToolWhat it doesWithout a keyCost
searchSearches the web and the specialist sources, with the popularity, domain, page-type, topic, site and date filtersYes: one source, up to 5 results1 credit per source searched, first 10 results
get_domain_infoPopularity and risk for up to 25 sitesNo1 credit
list_sourcesThe sources, page types and topics search acceptsYes: source namesFree
The tools of the other endpointsextract, map, crawl, places and more: the MCP page lists themA few, such as placesWhat the API call behind each costs

The function tool in step 2 is search alone; the MCP session gives the model every tool of the server.

Settings

VariableMeaning
MILLIONSHORT_API_KEYYour key, read by the examples above
GEMINI_API_KEYYour Gemini key, read by the SDK

Costs and limits

A tool call costs what the API call behind it costs: 1 credit per source searched for the first 10 results, 1 credit for a domain lookup, nothing for the list of sources, the price of the endpoint for the other tools, and nothing at all in the no-key mode. An agent that loops can make many calls: give it a step limit, and ask for fewer results when a few will do. Credits and limits has the numbers.

When it fails

What you seeWhyFix
401 AUTH_MISSING_KEY or AUTH_INVALID_KEYThe key is missing or wrongSet MILLIONSHORT_API_KEY; keys start with ms-
400 INVALID_PARAMA field name or value the API does not takeThe message names the field; the search reference lists them all
429 RATE_LIMITED or CAPACITYToo many calls a minute, or no free capacity right nowWait the Retry-After seconds, then retry
429 INSUFFICIENT_CREDITSThe plan's credits are used upStop and add credits; do not retry
The model answers without calling the toolNothing told it when to search, or the function has no docstring for the Python SDK to readAdd the line from step 3, and keep the docstring
streamable_http_client() rejects headersMCP Python SDK 2.x moved headers to the httpx2 clientPass http_client= as in the MCP example

This page as Markdown ยท llms.txt