Integrations / Frameworks & SDKs
Pydantic AI
MillionShort search for Pydantic AI agents, as an MCP toolset or a typed function tool.
Copy as MarkdownOpen in ChatGPT (opens in a new tab)Open in Claude (opens in a new tab)
MCPPythonNothing of ours to installWorks with no keyChecked 2026-11-19
Pydantic AI connects to the MillionShort MCP server through an MCPToolset: you give it the address and the key, and register it with an agent in toolsets. The agent then has the server's tools: search, get_domain_info, list_sources and the tools of the other endpoints, such as extract, places, map and crawl (the MCP page lists them all). With no MCP at all, a plain function tool that calls the API does the same job.
1Install
pip install pydantic-ai
export MILLIONSHORT_API_KEY=ms-YOUR_API_KEYThe full pydantic-ai package includes the MCP client and the model providers. The slim install works too: pip install "pydantic-ai-slim[mcp]", plus the extra for your model provider. The examples use an OpenAI model, as Pydantic AI's docs do, so they read OPENAI_API_KEY; any model Pydantic AI supports works. Get a MillionShort key in the dashboard; an agent can ask for a trial key by itself.
2Connect the server
An MCPToolset takes the address as its first argument (streamable HTTP, since the path does not end in /sse) and the key in headers. Without a key, leave the headers out.
import asyncio
import os
from pydantic_ai import Agent
from pydantic_ai.mcp import MCPToolset
millionshort = MCPToolset(
"https://mcp.millionshort.com/mcp",
headers={"Authorization": f"Bearer {os.environ['MILLIONSHORT_API_KEY']}"},
)
agent = Agent("openai:gpt-6.1-sol", toolsets=[millionshort])
async def main():
result = await agent.run("Find independent blogs about home espresso, without the 1,000 most popular sites.")
print(result.output)
asyncio.run(main())The toolset connects when a run needs it. async with agent: holds the connection open across several runs. MCPToolset("https://mcp.millionshort.com/mcp", auth=key) sends the same bearer header.
3Give the tools to an agent
Say when to search in instructions, and cap the tool calls of a run with UsageLimits. Pydantic AI adds no web search of its own unless you add one, so there is nothing to turn off.
import os
from pydantic_ai import Agent, UsageLimits
from pydantic_ai.mcp import MCPToolset
millionshort = MCPToolset("https://mcp.millionshort.com/mcp", headers={"Authorization": f"Bearer {os.environ['MILLIONSHORT_API_KEY']}"})
agent = Agent(
"openai:gpt-6.1-sol",
instructions="Use the MillionShort search tool for anything recent or niche, and cite the URLs.",
toolsets=[millionshort],
)
result = agent.run_sync("Find independent blogs about home espresso.", usage_limits=UsageLimits(tool_calls_limit=5))
print(result.output)If the agent has other toolsets with a tool called search, millionshort.prefixed("millionshort") renames ours to millionshort_search and so on.
A line that works well in the 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.
4Check it works
List the tools without a model:
import asyncio
import os
from pydantic_ai.mcp import MCPToolset
async def main():
millionshort = MCPToolset("https://mcp.millionshort.com/mcp", headers={"Authorization": f"Bearer {os.environ['MILLIONSHORT_API_KEY']}"})
async with millionshort:
print([tool.name for tool in await millionshort.list_tools()]) # search, get_domain_info, list_sources, ...
asyncio.run(main())After a run, result.all_messages() holds the model's tool calls; one of them should be search.
Without MCP: a function tool
A plain function registered with @agent.tool_plain calls POST /v1/search. Pydantic AI builds the tool's schema from the signature and the docstring.
import json
import os
import urllib.request
from pydantic_ai import Agent
agent = Agent("openai:gpt-6.1-sol")
@agent.tool_plain
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])
print(agent.run_sync("Find independent blogs about home espresso.").output)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 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.
UsageLimits(tool_calls_limit=...) on a 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 |
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 run stops with a usage limit message | The run reached its UsageLimits | Raise tool_calls_limit or request_limit, or ask for fewer results per search |
| The model's provider is not installed | The slim install has no extra for that provider | Install pydantic-ai, or add the provider's extra to pydantic-ai-slim |
Related
- Agent tool use: when to give a model tools, and what to tell it.
- OpenAI Agents SDK, LangChain and Claude Agent SDK.
- MCP server and Filters for agents.
- Pydantic AI's own documentation, read on 2026-11-19: MCP client, MCPToolset reference, Function tools.