# LlamaIndex

MillionShort search for LlamaIndex agents, through its MCP tool spec or a plain function tool.

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.

LlamaIndex connects to the MillionShort MCP server with the `llama-index-tools-mcp` package: a `BasicMCPClient` holds the address and the key, and an `McpToolSpec` turns 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), into LlamaIndex tools for an agent. With no MCP at all, a plain function tool that calls the API does the same job.

## 1. Install

```bash Python
pip install llama-index-tools-mcp llama-index-llms-openai
export MILLIONSHORT_API_KEY=ms-YOUR_API_KEY
```

The examples use an OpenAI model, as LlamaIndex's starter tutorial does, so they read OPENAI_API_KEY; any LlamaIndex LLM that supports function calling 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.

LlamaIndex's TypeScript packages do not document an MCP client, so this page is Python only.

## 2. Connect the server

`BasicMCPClient` treats an address that does not end in `/sse` as streamable HTTP, and sends `headers` with every request. Without a key, leave the headers out.

```python Python
import asyncio
import os

from llama_index.tools.mcp import BasicMCPClient, McpToolSpec

client = BasicMCPClient(
    "https://mcp.millionshort.com/mcp",
    headers={"Authorization": f"Bearer {os.environ['MILLIONSHORT_API_KEY']}"},
)


async def main():
    tools = await McpToolSpec(client=client).to_tool_list_async()
    print([tool.metadata.name for tool in tools])  # search, get_domain_info, list_sources, ...


asyncio.run(main())
```

## 3. Give the tools to an agent

A `FunctionAgent` takes the tools, an LLM and a system prompt. LlamaIndex agents have no web search of their own, so the MillionShort tools are the only search the agent has.

```python Python
import asyncio
import os

from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI
from llama_index.tools.mcp import BasicMCPClient, McpToolSpec

client = BasicMCPClient("https://mcp.millionshort.com/mcp", headers={"Authorization": f"Bearer {os.environ['MILLIONSHORT_API_KEY']}"})


async def main():
    tools = await McpToolSpec(client=client).to_tool_list_async()
    agent = FunctionAgent(
        tools=tools,
        llm=OpenAI(model="gpt-4o-mini"),
        system_prompt="Use the MillionShort search tool for anything recent or niche, and cite the URLs.",
    )
    response = await agent.run(user_msg="Find independent blogs about home espresso, without the 1,000 most popular sites.")
    print(response)


asyncio.run(main())
```

To give the agent only search, pass `allowed_tools=["search"]` to `McpToolSpec`. `agent.run(..., max_iterations=10)` caps the steps of one run.

A line that works well in the system prompt:

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

## 4. Check it works

The example in step 2 lists the tools with no model involved. To see a call made directly, as the agent would make it:

```python Python
import asyncio
import os

from llama_index.tools.mcp import BasicMCPClient

client = BasicMCPClient("https://mcp.millionshort.com/mcp", headers={"Authorization": f"Bearer {os.environ['MILLIONSHORT_API_KEY']}"})


async def main():
    result = await client.call_tool("search", {"query": "restoring a cast iron skillet", "remove_top_sites": 1000, "num_results": 3})
    print(result.content[0].text[:600])


asyncio.run(main())
```

## Without MCP: a function tool

A `FunctionAgent` takes plain Python functions as tools, described by their name, type hints and docstring.

```python Python
import asyncio
import json
import os
import urllib.request

from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI


def millionshort_search(query: str, remove_top_sites: int = 1000, num_results: int = 5) -> str:
    """Search the web with MillionShort. remove_top_sites leaves out the N most popular sites."""
    request = urllib.request.Request(
        "https://api.millionshort.com/v1/search",
        data=json.dumps({"query": query, "remove_top_sites": remove_top_sites, "num_results": num_results}).encode(),
        headers={"Authorization": "Bearer " + os.environ["MILLIONSHORT_API_KEY"], "Content-Type": "application/json"},
    )
    with urllib.request.urlopen(request, timeout=30) as response:
        results = json.load(response)["data"]["results"]
    return json.dumps([{"title": r["title"], "url": r["url"], "snippet": r.get("snippet")} for r in results])


async def main():
    agent = FunctionAgent(tools=[millionshort_search], llm=OpenAI(model="gpt-4o-mini"))
    print(await agent.run(user_msg="Find independent blogs about home espresso."))


asyncio.run(main())
```

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

`max_iterations` on `agent.run` is the step 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](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 header is not sent | `BasicMCPClient` was given an `http_client` of your own, which replaces its `headers` and `timeout` | Set the header on your own client, or leave `http_client` out |
| The run stops before an answer | The agent reached `max_iterations` | Raise `max_iterations`, or ask for fewer results per search |

## Related

- [Agent tool use](https://millionshort.com/docs/search/guides/agent-tool-use): when to give a model tools, and what to tell it.
- [LangChain](https://millionshort.com/docs/integrations/langchain), [Pydantic AI](https://millionshort.com/docs/integrations/pydantic-ai) and [CrewAI](https://millionshort.com/docs/integrations/crewai).
- [MCP server](https://millionshort.com/docs/mcp) and [Filters for agents](https://millionshort.com/docs/search/filters).
- LlamaIndex's own documentation, read on 2026-11-19: [MCP tools package](https://github.com/run-llama/llama_index/tree/main/llama-index-integrations/tools/llama-index-tools-mcp), [Model Context Protocol](https://developers.llamaindex.ai/python/framework/module_guides/mcp/), [Building an agent](https://developers.llamaindex.ai/python/framework/understanding/agent/).
