Guides
Agent tool use
Give an agent search as a tool, over MCP or as a function, and teach it when to use the parts that matter.
Copy as MarkdownOpen in ChatGPT (opens in a new tab)Open in Claude (opens in a new tab)
There are two ways to hand an agent MillionShort search. Use MCP when the agent runs in a client that speaks it. Use a function tool when you run the model loop yourself.
| MCP server | Function tool | |
|---|---|---|
| You write | Nothing: one address in the client's settings | A tool definition and a small handler |
| Works in | Claude, Claude Code, Cursor, ChatGPT, VS Code and other MCP clients | Any model API that supports tools |
| Key | Your API key in a header, or no key at smaller limits | Your API key, on your server |
| Tools | search, get_domain_info, list_sources | Whatever you define |
MCP
The hosted server is at one address, and needs nothing installed:
https://mcp.millionshort.com/mcpClaude Code
claude mcp add --transport http millionshort https://mcp.millionshort.com/mcp \
--header "Authorization: Bearer $MILLIONSHORT_API_KEY"Cursor
In .cursor/mcp.json:
{
"mcpServers": {
"millionshort": {
"url": "https://mcp.millionshort.com/mcp",
"headers": { "Authorization": "Bearer ms-YOUR_API_KEY" }
}
}
}Claude apps and ChatGPT
Both add the server as a custom connector by its address. Neither can send an API key, so they connect in the server's no-key mode: search and list_sources, one source and up to 5 results per search, 10 free searches a day and at most 5 in a minute. Each answer says how many are left today.
The MCP page has the exact steps for each client, the tools' arguments, and a way to check the connection with curl.
What the agent sees
Three search tools, all read-only and marked so, which lets a client run them without asking each time. The tools of the other endpoints are on the MCP page.
| Tool | What it does | Without a key |
|---|---|---|
search | Searches MillionShort's own independent index: the web, plus news, discussions, podcasts, academic and other specialist sources. Returns ranked results with title, URL, site, date, snippet, a popularity band, how visits to the site are moving, where it is popular and what it is built with. What sets it apart is control over which sites and pages come back: - Popularity: remove the N most popular sites to reach lesser-known ones (remove_top_sites), keep only them (only_top_sites), or pick popularity bands (popularity_buckets). - Domains: only (include_domains), block (exclude_domains), boost or bury. - Page types (formats such as tutorials, documentation, forums, listicles) and topics: keep only, exclude, boost or bury. - Site signals: sites with rising or falling visits (traffic_trend), sites popular in a country (popular_in), sites built with a given technology (site_tech), no risky sites (exclude_risky). - Date (start_date, end_date, time_range), language and country. - More text per result: highlights, the passages that answer the query (max_highlights), and the text of the page itself (include_content). A filter that a source cannot apply is reported in a note, never dropped silently; list_sources says which filters each source applies. | Yes, with smaller limits |
get_domain_info | Returns the popularity rank and band, and the risk level and categories, for up to 25 domains. | No |
list_sources | Lists the sources the search tool accepts, with a one-line description of each, how often new material arrives in it and which search filters it applies. Also lists the page types, topics, traffic trends and popularity bands. | Yes, with smaller limits |
A search result arrives as short numbered text for the model, and as structured content for the client: title, URL, site, date, snippet and a popularity band.
A function tool
When you run the loop yourself, define one tool and call the API in its handler. This definition is plain JSON Schema, which every major model API accepts in some wrapper:
{
"name": "web_search",
"description": "Search the web and specialist sources. Returns ranked results with title, URL, site, date and a snippet. Set remove_top_sites to leave out the most popular sites.",
"input_schema": {
"type": "object",
"properties": {
"query": { "type": "string", "description": "What to search for, in the words a page would use." },
"sources": {
"type": "array",
"items": {
"type": "string",
"enum": ["web", "news", "smallweb", "discussions", "hn", "social", "communities", "podcasts", "academic", "medical", "law", "finance", "contracts"]
},
"maxItems": 5,
"description": "Which sources to ask. Default: web."
},
"remove_top_sites": {
"type": "integer",
"minimum": 0,
"maximum": 1000000,
"description": "Leave out results from the N most popular sites, for example 1000 or 100000."
},
"num_results": { "type": "integer", "minimum": 1, "maximum": 20 }
},
"required": ["query"]
}
}The handler turns the model's arguments into a search and returns compact text. Keep what you return short: the model pays for every character.
import os
from millionshort import MillionShort, MillionShortError
client = MillionShort(api_key=os.environ["MILLIONSHORT_API_KEY"])
ALLOWED = {"sources", "remove_top_sites", "num_results"}
def web_search(arguments):
"""The tool handler: the model's arguments in, text for the model out."""
options = {k: v for k, v in arguments.items() if k in ALLOWED}
try:
r = client.search(arguments["query"], max_chars_per_result=500, **options)
except MillionShortError as error:
return f"Search failed ({error.code}): {error.message}"
if not r.results:
return "No results. Try other words, or another source."
lines = []
for hit in r.results:
date = hit["published_date"] or "undated"
lines.append(
f'{hit["position"]}. {hit["title"]}\n {hit["url"]}\n'
f' {hit["source"]} | {date} | {hit["popularity"]["bucket"]}\n {hit["snippet"]}'
)
return "\n\n".join(lines)
print(web_search({"query": "sourdough starter hydration", "remove_top_sites": 1000, "num_results": 3}))import { MillionShort, MillionShortError } from 'millionshort';
const client = new MillionShort({ apiKey: process.env.MILLIONSHORT_API_KEY });
type Arguments = { query: string; sources?: string[]; remove_top_sites?: number; num_results?: number };
/** The tool handler: the model's arguments in, text for the model out. */
async function webSearch(args: Arguments): Promise<string> {
try {
const r = await client.search(args.query, {
sources: args.sources,
removeTopSites: args.remove_top_sites,
numResults: args.num_results,
maxCharsPerResult: 500,
});
if (r.results.length === 0) return 'No results. Try other words, or another source.';
return r.results
.map(
(hit) =>
`${hit.position}. ${hit.title}\n ${hit.url}\n` +
` ${hit.source} | ${hit.published_date ?? 'undated'} | ${hit.popularity.bucket}\n ${hit.snippet}`,
)
.join('\n\n');
} catch (error) {
if (error instanceof MillionShortError) return `Search failed (${error.code}): ${error.message}`;
throw error;
}
}
console.log(await webSearch({ query: 'sourdough starter hydration', remove_top_sites: 1000, num_results: 3 }));Return errors to the model as text, as above: a model that reads "Search failed (RATE_LIMITED)" can wait or tell the person, and a model that gets an exception cannot.
If you use LangChain or the Vercel AI SDK, the tool is already written: see LangChain and Vercel AI SDK.
Teach the agent to search well
A tool description says what a tool does. It does not say when your agent should reach for it. Put that in the system prompt or the project's rules. Lines that earn their place:
Searching:
- Search before answering anything about current events, prices, versions, or facts you are not sure of.
- Ask the right source: news for this week, academic or medical for research, law for United States
law, finance for company filings, discussions for opinions. Default to web.
- When results are all from very popular sites and you need first-hand or specialist material,
search again with remove_top_sites set to 1000 or 10000.
- Web results have no date. For anything recent, include news or social and check the dates.
- Cite the URL of every result you rely on. Say when a source is a small or little-known site.
- Do not open or cite a result that carries a risk label without saying so.
- One search usually costs one credit per source. Do not repeat a search that returned what you need.For a coding agent, the same guidance ships as a block for AGENTS.md and as a Cursor rule: see Set up for agents.
Keys and limits for agents
- Your agent, your key. Keep the key on your server or in the client's settings. Never put it in a prompt.
- An agent with no person at hand can get a trial key: 25 credits, 24 hours.
- Rate limits are per team, so many agents on one key share one limit.
429 RATE_LIMITEDcarries the seconds to wait. - Cap the tool, not the model. Limit
num_resultsin your tool definition, as above, so one enthusiastic call cannot cost much.
Check that it works
Ask the agent: "Use MillionShort to find three small-site write-ups about restoring a cast iron skillet, and tell me how popular each site is." A working set-up calls search with remove_top_sites, and the answer names a popularity band for each result.