# Pipecat

MillionShort search inside a Pipecat voice bot, through the hosted MCP server or a direct function, in Python.

MCP · Python · 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.

Pipecat's `MCPClient` connects to the MillionShort MCP server, reads its tools and hands them to the LLM service with their handlers attached. The bot then gets the server's tools, `search`, `get_domain_info`, `list_sources` and the tools of the other endpoints ([the MCP page](https://millionshort.com/docs/mcp#tools) lists them all), or only the ones you name. With no MCP at all, a direct function that calls the API does the same job.

Spoken answers work best with few results: ask for `num_results` 3 and `max_highlights` 1, so the model reads short passages rather than long text. Each search also adds a little latency to the turn it runs in.

## 1. Install

```bash Python
pip install "pipecat-ai[mcp]"
export MILLIONSHORT_API_KEY=ms-YOUR_API_KEY
```

`MCPClient` needs version 2.1.1 or later of the MCP Python SDK, which the `mcp` extra installs. Build the rest of the bot (transport, speech-to-text, LLM, text-to-speech) as in Pipecat's quickstart. 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

`tools()` opens the connection on its first call and returns the tools, ready for the context. The connection closes when the pipeline ends. Without a key, leave the headers out.

```python Python
import os

from mcp.client.session_group import StreamableHttpParameters
from pipecat.processors.aggregators.llm_context import LLMContext
from pipecat.processors.aggregators.llm_response_universal import LLMContextAggregatorPair
from pipecat.services.mcp_service import MCPClient


async def millionshort_context():
    mcp = MCPClient(
        server_params=StreamableHttpParameters(
            url="https://mcp.millionshort.com/mcp",
            headers={"Authorization": f"Bearer {os.environ['MILLIONSHORT_API_KEY']}"},
        ),
        tools_filter=["search"],
        tools_arguments={"search": {"num_results": 3, "max_highlights": 1}},
    )
    context = LLMContext(tools=await mcp.tools())
    return context, LLMContextAggregatorPair(context)
```

`tools_filter` offers the model only `search`. `tools_arguments` fixes `num_results` and `max_highlights` on every call and hides them from the model, so it cannot ask for more than a spoken answer needs.

## 3. Give the tools to the bot

Put the two aggregators around the LLM service in the pipeline, as for any Pipecat tool:

```python Python
from pipecat.pipeline.pipeline import Pipeline


def build_pipeline(transport, stt, llm, tts, aggregators):
    user_aggregator, assistant_aggregator = aggregators
    return Pipeline([
        transport.input(),
        stt,
        user_aggregator,
        llm,
        tts,
        transport.output(),
        assistant_aggregator,
    ])
```

Tell the LLM service when to search in its system instruction, and to answer in a few short sentences.

## 4. Check it works

To see the tools without a model, list them from the client:

```python Python
import asyncio
import os

from mcp.client.session_group import StreamableHttpParameters
from pipecat.services.mcp_service import MCPClient


async def main():
    params = StreamableHttpParameters(url="https://mcp.millionshort.com/mcp", headers={"Authorization": f"Bearer {os.environ['MILLIONSHORT_API_KEY']}"})
    async with MCPClient(server_params=params) as mcp:
        print([tool.name for tool in (await mcp.tools()).standard_tools])  # search, get_domain_info, list_sources, ...


asyncio.run(main())
```

Then run the bot and ask a question that needs the web: the answer should name pages it found. 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 direct function

A direct function is both the handler and the schema; Pipecat reads the name, the description and the arguments from its signature and docstring.

```python Python
import os

import aiohttp
from pipecat.processors.aggregators.llm_context import LLMContext
from pipecat.services.llm_service import FunctionCallParams


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

    Args:
        query: What to search for.
    """
    async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=15)) as http:
        async with http.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": 3, "max_highlights": 1},
        ) as response:
            response.raise_for_status()
            results = (await response.json())["data"]["results"]
    await params.result_callback([{"title": r["title"], "url": r["url"], "highlights": r.get("highlights")} for r in results])


context = LLMContext(tools=[millionshort_search])
```

`aiohttp` is installed with Pipecat. Use the context's aggregator pair in the pipeline, as in step 3.

## 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 |
| The bot never calls the tools | The tools were not put in the `LLMContext` the aggregators use | Pass `await mcp.tools()` to `LLMContext(tools=...)` and use that context's aggregator pair |
| Connecting times out | `StreamableHttpParameters` waits 5 seconds by default | Pass a longer `timeout` |
| Long pauses before spoken answers | Many results or long text for the model to read | Fix `num_results` 3 and `max_highlights` 1 with `tools_arguments` |

## Related

- [LiveKit Agents](https://millionshort.com/docs/integrations/livekit-agents), [Vapi](https://millionshort.com/docs/integrations/vapi) and [ElevenLabs Agents](https://millionshort.com/docs/integrations/elevenlabs): the same server in other voice agents.
- [Agent tool use](https://millionshort.com/docs/search/guides/agent-tool-use): when to give a model tools, and what to tell it.
- [MCP server](https://millionshort.com/docs/mcp) and [Filters for agents](https://millionshort.com/docs/search/filters).
- Pipecat's own documentation, read on 2026-11-19: [MCPClient](https://docs.pipecat.ai/api-reference/server/utilities/mcp/mcp), [Function calling](https://docs.pipecat.ai/pipecat/learn/function-calling).
