# Genkit

MillionShort search as tools for a Genkit generate call, in TypeScript.

MCP · TypeScript · Nothing of ours to install · Works with no key · Checked 2026-11-19

> **For agents.** Read the API key from the `MILLIONSHORT_API_KEY` environment variable. Never print it; where a client needs it in a settings file, use a file that is not committed.
> The MCP address is https://mcp.millionshort.com/mcp (streamable HTTP; send `Authorization: Bearer <key>`, or no header for the no-key mode).
> On `INSUFFICIENT_CREDITS` stop and ask a person; on `RATE_LIMITED` or `CAPACITY` wait the `Retry-After` seconds, then retry once.
> Set-up steps written for agents: https://millionshort.com/docs/auth.md. Every integration: https://millionshort.com/docs/integrations.md.

Genkit's MCP plugin connects to the MillionShort MCP server by URL and turns its tools into Genkit tools, so any model Genkit runs can call `search`, `get_domain_info`, `list_sources` and the tools of the other endpoints, such as `extract`, `places`, `map` and `crawl` ([the MCP page](https://millionshort.com/docs/mcp#tools) lists them all). Without MCP, a tool defined with `ai.defineTool` that calls the API does the same job.

Remote MCP servers are a feature of the TypeScript plugin. Genkit's Python MCP plugin is in preview and its docs describe only servers it starts as a local process, so this page is TypeScript only.

## 1. Install

```bash TypeScript
npm install genkit @genkit-ai/mcp @genkit-ai/google-genai
export MILLIONSHORT_API_KEY=ms-YOUR_API_KEY
```

The examples use the Google AI plugin, which reads your Gemini key from GEMINI_API_KEY; any model plugin works. Get a MillionShort key in the [dashboard](https://millionshort.com/app/); an agent can ask for a [trial key](https://millionshort.com/docs/api-reference/agent-key) by itself.

## 2. Connect the server

`createMcpHost` manages one or more MCP servers. The key under `mcpServers` names the server, and the key goes in `requestInit.headers`. Without a key, leave `requestInit` out.

```ts TypeScript
import { googleAI } from '@genkit-ai/google-genai';
import { createMcpHost } from '@genkit-ai/mcp';
import { genkit } from 'genkit';

const mcpHost = createMcpHost({
  name: 'myMcpClients',
  mcpServers: {
    millionshort: {
      url: 'https://mcp.millionshort.com/mcp',
      requestInit: { headers: { Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}` } },
    },
  },
});

const ai = genkit({ plugins: [googleAI()] });
```

## 3. Give the tools to a generate call

`getActiveTools` returns the server's tools as Genkit tools; pass them to `ai.generate`, a prompt or a chat.

```ts TypeScript
import { googleAI } from '@genkit-ai/google-genai';
import { createMcpHost } from '@genkit-ai/mcp';
import { genkit } from 'genkit';

const mcpHost = createMcpHost({
  name: 'myMcpClients',
  mcpServers: {
    millionshort: {
      url: 'https://mcp.millionshort.com/mcp',
      requestInit: { headers: { Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}` } },
    },
  },
});
const ai = genkit({ plugins: [googleAI()] });

try {
  const { text } = await ai.generate({
    model: googleAI.model('gemini-flash-latest'),
    system: 'Use the millionshort search tool for anything recent or niche, and cite the URLs.',
    prompt: 'Find independent blogs about home espresso, without the 1,000 most popular sites.',
    tools: await mcpHost.getActiveTools(ai),
  });
  console.log(text);
} finally {
  await mcpHost.close();
}
```

For one server you can use `createMcpClient` instead. Its `name` becomes the namespace of the tools:

```ts TypeScript
import { createMcpClient } from '@genkit-ai/mcp';

export const millionshort = createMcpClient({
  name: 'millionshort',
  mcpServer: {
    url: 'https://mcp.millionshort.com/mcp',
    requestInit: { headers: { Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}` } },
  },
});
// await millionshort.ready(); then pass await millionshort.getActiveTools(ai) as tools
```

## 4. Check it works

Run the example: the answer should cite pages. To see the tools without a model, list their names. Genkit namespaces them by the server's key, so expect `millionshort/search`, `millionshort/get_domain_info`, `millionshort/list_sources` and the rest of the server's tools under the same prefix:

```ts TypeScript
import { createMcpHost } from '@genkit-ai/mcp';
import { genkit } from 'genkit';

const mcpHost = createMcpHost({
  name: 'myMcpClients',
  mcpServers: {
    millionshort: {
      url: 'https://mcp.millionshort.com/mcp',
      requestInit: { headers: { Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}` } },
    },
  },
});
const ai = genkit({});

const tools = await mcpHost.getActiveTools(ai);
console.log(tools.map((tool) => tool.__action.name));
await mcpHost.close();
```

The Genkit Developer UI also lists the tools once the host is set up. If the model answers from memory, say when to search in its instructions:

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

## Without MCP: a function tool

A tool defined with `ai.defineTool` that calls `POST /v1/search` works with any model Genkit runs:

```ts TypeScript
import { googleAI } from '@genkit-ai/google-genai';
import { genkit, z } from 'genkit';

const ai = genkit({ plugins: [googleAI()], model: googleAI.model('gemini-flash-latest') });

const millionshortSearch = ai.defineTool(
  {
    name: 'millionshortSearch',
    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) }),
    outputSchema: z.array(z.object({ title: z.string(), url: z.string(), snippet: z.string().optional() })),
  },
  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 ai.generate({ prompt: 'Find independent blogs about home espresso.', tools: [millionshortSearch] });
console.log(text);
```

## MCP configuration

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

| 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](https://millionshort.com/docs/mcp#tools) 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](https://millionshort.com/docs/credits-and-limits) has the numbers.

## 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](https://millionshort.com/app/) |
| `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 |
| `getActiveTools` returns no MillionShort tools | The connection failed, or the server entry has `disabled: true` | Check the URL and the header, then list the tools as in step 4 |

## Related

- [Agent tool use](https://millionshort.com/docs/search/guides/agent-tool-use): when to give a model tools, and what to tell it.
- [Vercel AI SDK](https://millionshort.com/docs/integrations/vercel-ai-sdk) and [OpenAI Agents SDK](https://millionshort.com/docs/integrations/openai-agents): the same server in other TypeScript frameworks.
- [MCP server](https://millionshort.com/docs/mcp) and [Filters for agents](https://millionshort.com/docs/search/filters).
- Genkit's own documentation, read on 2026-11-19: [Model Context Protocol](https://genkit.dev/docs/js/model-context-protocol/), [Tool calling](https://genkit.dev/docs/js/tool-calling/), [Google Generative AI plugin](https://genkit.dev/docs/js/integrations/google-genai/).
