Integrations / Frameworks & SDKs
Claude Agent SDK
MillionShort search for agents built with the Claude Agent SDK, in Python and TypeScript.
Copy as MarkdownOpen in ChatGPT (opens in a new tab)Open in Claude (opens in a new tab)
MCPPython and TypeScriptNothing of ours to installWorks with no keyChecked 2026-11-19
The Agent SDK runs Claude Code's agent loop inside your application. You add the MillionShort MCP server to the options of query() as an HTTP server, allow its tools by name, and turn off the SDK's own web tools so the agent searches with MillionShort. The agent then has the tools you allow, named mcp__millionshort__search and so on: search, get_domain_info, list_sources and the tools of the other endpoints (the MCP page lists them all).
1Install
pip install claude-agent-sdk
export MILLIONSHORT_API_KEY=ms-YOUR_API_KEYnpm install @anthropic-ai/claude-agent-sdk zod
export MILLIONSHORT_API_KEY=ms-YOUR_API_KEYThe SDK needs Python 3.10 or later, or Node.js 18.14 or later, and reads your Anthropic key from ANTHROPIC_API_KEY. Get a MillionShort key in the dashboard; an agent can ask for a trial key by itself.
The SDK runs Claude Code: each query() starts a Claude Code process and talks to it. Both packages bundle a native Claude Code binary, so most installs need nothing else. Two installs come without it, according to the SDK's docs: pip installing the source distribution instead of a platform wheel (on ARM64 Windows, for example), and npm skipping optional dependencies (npm ci --omit=optional). Then install Claude Code yourself: the Python SDK finds it on your PATH, and in TypeScript you set pathToClaudeCodeExecutable to it.
2Connect the server
Pass the server in mcp_servers (mcpServers in TypeScript) with type http. MCP tools need permission before Claude can call them, so list them in allowed_tools; disallowed_tools takes the built-in WebSearch and WebFetch tools out of the agent's context. Without a key, leave the headers out.
import asyncio
import os
from claude_agent_sdk import ClaudeAgentOptions, ResultMessage, query
async def main():
options = ClaudeAgentOptions(
mcp_servers={
"millionshort": {
"type": "http",
"url": "https://mcp.millionshort.com/mcp",
"headers": {"Authorization": f"Bearer {os.environ['MILLIONSHORT_API_KEY']}"},
}
},
allowed_tools=["mcp__millionshort__search", "mcp__millionshort__get_domain_info", "mcp__millionshort__list_sources"],
disallowed_tools=["WebSearch", "WebFetch"],
)
prompt = "Find independent blogs about home espresso, without the 1,000 most popular sites."
async for message in query(prompt=prompt, options=options):
if isinstance(message, ResultMessage) and message.subtype == "success":
print(message.result)
asyncio.run(main())import { query } from '@anthropic-ai/claude-agent-sdk';
for await (const message of query({
prompt: 'Find independent blogs about home espresso, without the 1,000 most popular sites.',
options: {
mcpServers: {
millionshort: {
type: 'http',
url: 'https://mcp.millionshort.com/mcp',
headers: { Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}` },
},
},
allowedTools: ['mcp__millionshort__search', 'mcp__millionshort__get_domain_info', 'mcp__millionshort__list_sources'],
disallowedTools: ['WebSearch', 'WebFetch'],
},
})) {
if (message.type === 'result' && message.subtype === 'success') {
console.log(message.result);
}
}mcp__millionshort__* allows every tool of the server at once, crawl included, which spends credits. The middle part of each name is the key you give the server in mcp_servers.
3Give the tools to an agent
A research agent needs no files and no shell. tools=[] removes every built-in tool, web tools included, so the MillionShort tools are all the agent has; system_prompt says when to use them and max_turns caps the loop.
import asyncio
import os
from claude_agent_sdk import ClaudeAgentOptions, ResultMessage, query
options = ClaudeAgentOptions(
mcp_servers={
"millionshort": {
"type": "http",
"url": "https://mcp.millionshort.com/mcp",
"headers": {"Authorization": f"Bearer {os.environ['MILLIONSHORT_API_KEY']}"},
}
},
tools=[],
allowed_tools=["mcp__millionshort__*"],
system_prompt="Use the MillionShort search tool for anything recent or niche, and cite the URLs.",
max_turns=8,
)
async def main():
async for message in query(prompt="Find independent blogs about home espresso.", options=options):
if isinstance(message, ResultMessage) and message.subtype == "success":
print(message.result)
asyncio.run(main())import { query } from '@anthropic-ai/claude-agent-sdk';
for await (const message of query({
prompt: 'Find independent blogs about home espresso.',
options: {
mcpServers: {
millionshort: {
type: 'http',
url: 'https://mcp.millionshort.com/mcp',
headers: { Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}` },
},
},
tools: [],
allowedTools: ['mcp__millionshort__*'],
systemPrompt: 'Use the MillionShort search tool for anything recent or niche, and cite the URLs.',
maxTurns: 8,
},
})) {
if (message.type === 'result' && message.subtype === 'success') {
console.log(message.result);
}
}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.
4Check it works
The first message of every run is a system message with subtype init. It gives each MCP server's status and the tools the agent has; millionshort should be connected, with its mcp__millionshort__ tools listed.
import asyncio
import os
from claude_agent_sdk import ClaudeAgentOptions, SystemMessage, query
async def main():
server = {"type": "http", "url": "https://mcp.millionshort.com/mcp", "headers": {"Authorization": f"Bearer {os.environ['MILLIONSHORT_API_KEY']}"}}
options = ClaudeAgentOptions(mcp_servers={"millionshort": server}, allowed_tools=["mcp__millionshort__*"])
async for message in query(prompt="List the sources MillionShort can search.", options=options):
if isinstance(message, SystemMessage) and message.subtype == "init":
print(message.data.get("mcp_servers"))
print([name for name in message.data.get("tools", []) if name.startswith("mcp__")])
asyncio.run(main())import { query } from '@anthropic-ai/claude-agent-sdk';
for await (const message of query({
prompt: 'List the sources MillionShort can search.',
options: {
mcpServers: {
millionshort: { type: 'http', url: 'https://mcp.millionshort.com/mcp', headers: { Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}` } },
},
allowedTools: ['mcp__millionshort__*'],
},
})) {
if (message.type === 'system' && message.subtype === 'init') {
console.log(message.mcp_servers);
console.log(message.tools.filter((name) => name.startsWith('mcp__')));
}
}A status of pending is not a failure on its own: the SDK may still be connecting, or may have the tool list cached from an earlier run and connect on the first call. failed or needs-auth means the agent runs without the tools.
Without the remote server: a custom tool
The SDK's own way to add a function is a custom tool, served from inside your process by an in-process MCP server. This one calls POST /v1/search directly. The Python version uses httpx, as the SDK's docs do:
pip install claude-agent-sdk httpximport asyncio
import json
import os
from typing import Any
import httpx
from claude_agent_sdk import ClaudeAgentOptions, ResultMessage, create_sdk_mcp_server, query, tool
@tool("millionshort_search", "Search the web with MillionShort, without the 1,000 most popular sites.", {"query": str})
async def millionshort_search(args: dict[str, Any]) -> dict[str, Any]:
async with httpx.AsyncClient(timeout=30) as client:
response = await client.post(
"https://api.millionshort.com/v1/search",
json={"query": args["query"], "remove_top_sites": 1000, "num_results": 5},
headers={"Authorization": "Bearer " + os.environ["MILLIONSHORT_API_KEY"]},
)
response.raise_for_status()
results = [{"title": r["title"], "url": r["url"], "snippet": r.get("snippet")} for r in response.json()["data"]["results"]]
return {"content": [{"type": "text", "text": json.dumps(results)}]}
async def main():
server = create_sdk_mcp_server(name="web", version="1.0.0", tools=[millionshort_search])
options = ClaudeAgentOptions(mcp_servers={"web": server}, allowed_tools=["mcp__web__millionshort_search"], tools=[])
async for message in query(prompt="Find independent blogs about home espresso.", options=options):
if isinstance(message, ResultMessage) and message.subtype == "success":
print(message.result)
asyncio.run(main())import { createSdkMcpServer, query, tool } from '@anthropic-ai/claude-agent-sdk';
import { z } from 'zod';
const millionshortSearch = tool(
'millionshort_search',
'Search the web with MillionShort, without the 1,000 most popular sites.',
{ query: z.string() },
async ({ query }) => {
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: 1000, num_results: 5 }),
});
if (!res.ok) return { content: [{ type: 'text', text: `search failed: ${res.status}` }], isError: true };
const { data } = (await res.json()) as { data: { results: { title: string; url: string; snippet?: string }[] } };
const results = data.results.map(({ title, url, snippet }) => ({ title, url, snippet }));
return { content: [{ type: 'text', text: JSON.stringify(results) }] };
},
);
const web = createSdkMcpServer({ name: 'web', version: '1.0.0', tools: [millionshortSearch] });
for await (const message of query({
prompt: 'Find independent blogs about home espresso.',
options: { mcpServers: { web }, allowedTools: ['mcp__web__millionshort_search'], tools: [] },
})) {
if (message.type === 'result' && message.subtype === 'success') console.log(message.result);
}MCP configuration
The same address for every client: https://mcp.millionshort.com/mcp, streamable HTTP. In the SDK that is type http; a .mcp.json file in your project takes the same fields.
| 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 |
The SDK's own options that matter here: allowed_tools (allowedTools) pre-approves the tools, disallowed_tools (disallowedTools) or tools removes the built-in ones, and max_turns (maxTurns) limits the loop.
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 turn the agent takes can call search again, so max_turns is also a spending 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 |
| Claude sees the tools but does not call them | MCP tools need permission, and they are not in allowed_tools | Add mcp__millionshort__* to allowed_tools (allowedTools) |
The server is failed or needs-auth in the init message, and the run goes on without it | The key is missing or wrong, or the address cannot be reached | Check the key and the address; the SDK does not stop the run for a server that fails to connect |
| The agent searches with its own web tools | WebSearch and WebFetch are still in its context | Add them to disallowed_tools, or pass tools=[] |
| "Claude Code not found" | The install has no bundled Claude Code binary | Install Claude Code, then set cli_path (Python) or pathToClaudeCodeExecutable (TypeScript) if it is not on your PATH |
Related
- Agent tool use: when to give a model tools, and what to tell it.
- Anthropic: the same server in the Messages API, with no agent loop.
- Claude Code: the same server in the terminal.
- OpenAI Agents SDK and Pydantic AI.
- MCP server and Filters for agents.
- The SDK's own documentation, read on 2026-11-19: Connect to external tools with MCP, Give Claude custom tools, Quickstart, Python reference, TypeScript reference.