Integrations / Frameworks & SDKs
Vercel AI SDK
MillionShort search as tools for the AI SDK's generateText and streamText, through its MCP client.
Copy as MarkdownOpen in ChatGPT (opens in a new tab)Open in Claude (opens in a new tab)
MCPTypeScriptNothing of ours to installWorks with no keyChecked 2026-11-19
The AI SDK's MCP client connects to the MillionShort MCP server and turns its tools (search, get_domain_info, list_sources and the tools of the other endpoints; the MCP page lists them all) into AI SDK tools for generateText and streamText. With no MCP at all, a tool() that calls the API does the same job. MillionShort's own AI SDK package is coming soon.
1Install
npm install ai @ai-sdk/mcp zod
export MILLIONSHORT_API_KEY=ms-YOUR_API_KEYThe MCP client lives in its own package, @ai-sdk/mcp. The examples use a model string, as the AI SDK's docs do; a string in the creator/model-name form goes through the AI Gateway, which reads its key from AI_GATEWAY_API_KEY. A provider package's model works the same way. Get a MillionShort key in the dashboard; an agent can ask for a trial key by itself.
Run this on a server. The key must not reach a browser.
2Connect the server
createMCPClient with an http transport speaks streamable HTTP, and sends headers with every request. Without a key, leave the headers out.
import { createMCPClient } from '@ai-sdk/mcp';
const mcpClient = await createMCPClient({
transport: {
type: 'http',
url: 'https://mcp.millionshort.com/mcp',
headers: { Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}` },
},
});
try {
const tools = await mcpClient.tools();
console.log(Object.keys(tools)); // search, get_domain_info, list_sources, ...
} finally {
await mcpClient.close();
}3Give the tools to a model
Pass the tools to generateText or streamText. stopWhen: isStepCount(5) lets the model search, read the results and search again, and stops it after five steps. The AI SDK adds no web search of its own unless you pass a provider's search tool, so leave those out.
import { createMCPClient } from '@ai-sdk/mcp';
import { generateText, isStepCount } from 'ai';
const mcpClient = await createMCPClient({
transport: {
type: 'http',
url: 'https://mcp.millionshort.com/mcp',
headers: { Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}` },
},
});
try {
const { text } = await generateText({
model: 'anthropic/claude-sonnet-5.5',
system: 'Use the MillionShort search tool for anything recent or niche, and cite the URLs.',
tools: await mcpClient.tools(),
stopWhen: isStepCount(5),
prompt: 'Find independent blogs about home espresso, without the 1,000 most popular sites.',
});
console.log(text);
} finally {
await mcpClient.close();
}With streamText, close the client in the onEnd callback instead, once the response has finished. A line that works well in system:
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
Step 2 lists the tools with no model involved: you should see every tool of the server (fewer without a key; the MCP page lists them). After a generateText run, steps in its result holds each step's tool calls; one of them should be to search, and the answer should cite pages.
Without MCP: a function tool
A tool() with an inputSchema and an execute function calls POST /v1/search.
import { generateText, isStepCount, tool } from 'ai';
import { z } from 'zod';
const millionshortSearch = tool({
description: 'Search the web with MillionShort. remove_top_sites leaves out the N most popular sites.',
inputSchema: z.object({ query: z.string(), remove_top_sites: z.number().int().default(1000) }),
execute: async ({ query, remove_top_sites }) => {
const res = await fetch('https://api.millionshort.com/v1/search', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ query, remove_top_sites, num_results: 5 }),
});
if (!res.ok) throw new Error(`search failed: ${res.status}`);
const { data } = (await res.json()) as { data: { results: { title: string; url: string; snippet?: string }[] } };
return data.results.map(({ title, url, snippet }) => ({ title, url, snippet }));
},
});
const { text } = await generateText({
model: 'anthropic/claude-sonnet-5.5',
tools: { millionshort_search: millionshortSearch },
stopWhen: isStepCount(5),
prompt: 'Find independent blogs about home espresso.',
});
console.log(text);MCP configuration
The same address for every client: https://mcp.millionshort.com/mcp, streamable HTTP (transport type http in the AI SDK).
| Mode | How | What the agent gets |
|---|---|---|
| API key | Send Authorization: Bearer ms-YOUR_API_KEY | Every tool, at your plan's limits; calls use your credits |
| No key | Send no Authorization header | search, list_sources and a few more; one source and up to 5 results a search, 10 free searches a day |
Tools
| Tool | What it does | Without a key | Cost |
|---|---|---|---|
search | Searches the web and the specialist sources, with the popularity, domain, page-type, topic, site and date filters | Yes: one source, up to 5 results | 1 credit per source searched, first 10 results |
get_domain_info | Popularity and risk for up to 25 sites | No | 1 credit |
list_sources | The sources, page types and topics search accepts | Yes: source names | Free |
| The tools of the other endpoints | extract, map, crawl, places and more: the MCP page lists them | A few, such as places | What the API call behind each costs |
Settings
| Variable | Meaning |
|---|---|
MILLIONSHORT_API_KEY | Your key, read by the examples above. Leave the header out for the no-key mode |
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.
Each step of a multi-step generation can search again, so stopWhen is also your spending limit.
When it fails
| What you see | Why | Fix |
|---|---|---|
| The server does not connect, or no tools are listed | The address or the transport is not the one the server speaks | Use exactly https://mcp.millionshort.com/mcp and the streamable HTTP transport (often called http), not SSE |
401 or "unauthorized" | The key is wrong, or it was sent without Bearer | Send Authorization: Bearer ms-..., or leave the header out to use the no-key mode |
| "10 free searches a day without a key" | The no-key mode's daily searches are used up | Add a key: it is free in the dashboard |
INSUFFICIENT_CREDITS | The plan's credits are used up | Stop and add credits; retrying does not help |
| The agent answers from memory, or uses another search | Nothing told it when to use this one | Turn off its own search where it can be (this page says how), and add the line for its instructions |
createMCPClient is not found in ai | The MCP client moved to its own package | Install @ai-sdk/mcp and import createMCPClient from it |
| The model stops after one step, without an answer | generateText and streamText stop after one step by default | Set stopWhen: isStepCount(5) or similar |
Coming soon: the package
Coming soon. MillionShort's own AI SDK package is built and tested, and is not on a package registry yet. Its name is a placeholder until it is published, and may change. Until then, use the MCP client in steps 1 to 4, or the function tool above.
Package (placeholder name): @millionshort/ai-sdk. Three tools for the AI SDK, version 5 or later. They call the public API, have the same fields and limits as it, and return a reduced result made for a model to read.
import { generateText, stepCountIs, type LanguageModel } from 'ai';
import { millionshortTools } from '@millionshort/ai-sdk';
/** `model` is any AI SDK language model that supports tools. */
export async function research(model: LanguageModel, question: string) {
const { text } = await generateText({
model,
prompt: question,
tools: millionshortTools(), // reads MILLIONSHORT_API_KEY
stopWhen: stepCountIs(5),
});
return text;
}millionshortTools() returns an object with three tools, under the names the MCP server uses:
| Tool | What it does | Endpoint |
|---|---|---|
search | Search one or more sources | POST /v1/search |
get_domain_info | Popularity and risk for up to 25 sites | POST /v1/domain |
list_sources | The sources, page types and topics search accepts | GET /v1/sources |
To give a model search and nothing else, or to name the tool yourself:
import { generateText, stepCountIs, type LanguageModel } from 'ai';
import { millionshortSearch } from '@millionshort/ai-sdk';
export async function answer(model: LanguageModel, question: string) {
const { text } = await generateText({
model,
prompt: question,
tools: { web_search: millionshortSearch({ timeoutMs: 20000 }) },
stopWhen: stepCountIs(3),
});
return text;
}| Export | What it is |
|---|---|
millionshortTools(options?) | All three tools |
millionshortSearch(options?) | Search |
millionshortDomainInfo(options?) | Domain info |
millionshortSources(options?) | The sources list |
MillionShortClient | The small HTTP client the tools use |
MillionShortError | Thrown by a failed call, with code, status, requestId and retryAfterSeconds |
| Option | Environment variable | Meaning |
|---|---|---|
apiKey | MILLIONSHORT_API_KEY | Your key |
baseUrl | MILLIONSHORT_BASE_URL | The API address. Default https://api.millionshort.com |
timeoutMs | How long to wait for one call | |
fetch | Your own fetch, for a proxy or a test |
The package's own client makes the same call the search tool makes, and returns the same reduced result, with no model involved:
import { MillionShortClient } from '@millionshort/ai-sdk';
const client = new MillionShortClient(); // reads MILLIONSHORT_API_KEY
const result = await client.search({
query: 'restoring a cast iron skillet',
remove_top_sites: 1000,
num_results: 3,
});
console.log(JSON.stringify(result, null, 2).slice(0, 600));The search tool takes the fields of POST /v1/search under the same names. A search answer is reduced to what a model needs: for each result its position, title, URL, site, source, date, snippet, popularity band and risk level, then the counts of removed results, any warnings, the credits charged and the request id.
Related
- Agent tool use: when to use tools, and what to tell the model.
- LangChain, with the same server through LangChain's MCP adapter.
- OpenAI Agents SDK and Claude Agent SDK.
- MCP server and Filters for agents.
- The AI SDK's own documentation, read on 2026-11-19: MCP tools, Tool calling, AI Gateway.