Menu

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

TypeScript
npm install ai @ai-sdk/mcp zod
export MILLIONSHORT_API_KEY=ms-YOUR_API_KEY

The 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.

TypeScript
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.

TypeScript
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.

TypeScript
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).

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

Settings

VariableMeaning
MILLIONSHORT_API_KEYYour 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 seeWhyFix
The server does not connect, or no tools are listedThe address or the transport is not the one the server speaksUse 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 upAdd a key: it is free in the dashboard
INSUFFICIENT_CREDITSThe plan's credits are used upStop and add credits; retrying does not help
The agent answers from memory, or uses another searchNothing told it when to use this oneTurn off its own search where it can be (this page says how), and add the line for its instructions
createMCPClient is not found in aiThe MCP client moved to its own packageInstall @ai-sdk/mcp and import createMCPClient from it
The model stops after one step, without an answergenerateText and streamText stop after one step by defaultSet 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.

TypeScript
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:

ToolWhat it doesEndpoint
searchSearch one or more sourcesPOST /v1/search
get_domain_infoPopularity and risk for up to 25 sitesPOST /v1/domain
list_sourcesThe sources, page types and topics search acceptsGET /v1/sources

To give a model search and nothing else, or to name the tool yourself:

TypeScript
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;
}
ExportWhat it is
millionshortTools(options?)All three tools
millionshortSearch(options?)Search
millionshortDomainInfo(options?)Domain info
millionshortSources(options?)The sources list
MillionShortClientThe small HTTP client the tools use
MillionShortErrorThrown by a failed call, with code, status, requestId and retryAfterSeconds
OptionEnvironment variableMeaning
apiKeyMILLIONSHORT_API_KEYYour key
baseUrlMILLIONSHORT_BASE_URLThe API address. Default https://api.millionshort.com
timeoutMsHow long to wait for one call
fetchYour 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:

TypeScript
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.

This page as Markdown ยท llms.txt