Integrations / Frameworks & SDKs
LangChain
MillionShort search for LangChain agents, through LangChain's own MCP adapter, 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
LangChain connects to the MillionShort MCP server with its own MCPAdapter: it opens the connection, finds the server's tools, search, get_domain_info, list_sources and the tools of the other endpoints (the MCP page lists them all), and turns them into LangChain tools you pass to create_agent (createAgent in TypeScript). With no MCP at all, a function tool that calls the API does the same job. MillionShort's own LangChain packages are coming soon.
1Install
pip install "langchain[mcp]" langchain-anthropic
export MILLIONSHORT_API_KEY=ms-YOUR_API_KEYnpm install @langchain/mcp-adapters@^2.0.0 @langchain/core @langchain/langgraph langchain @langchain/anthropic zod
export MILLIONSHORT_API_KEY=ms-YOUR_API_KEYIn Python, MCP ships inside LangChain from version 1.4 as langchain.mcp, through the mcp extra. It is in beta: importing it prints a beta warning once, and the API may change. Before 1.4 the same job was done by the standalone langchain-mcp-adapters package and its MultiServerMCPClient; that package still exists, but LangChain's docs now point to langchain.mcp. In TypeScript, the examples need @langchain/mcp-adapters 2.0 or later.
The examples use an Anthropic model, as LangChain's MCP docs do, so they read ANTHROPIC_API_KEY; any chat model that supports tools works. Get a MillionShort key in the dashboard; an agent can ask for a trial key by itself.
2Connect the server
In Python, the key goes on a FastMCP Client as auth, which sends it as a bearer token; in TypeScript, it goes in the server's headers. Without a key, leave auth or the headers out.
import asyncio
import os
from fastmcp.client import Client
from langchain.mcp import MCPAdapter
async def main():
client = Client("https://mcp.millionshort.com/mcp", auth=os.environ["MILLIONSHORT_API_KEY"])
async with MCPAdapter(client) as adapter:
tools = await adapter.list_tools()
print([tool.name for tool in tools]) # search, get_domain_info, list_sources, ...
asyncio.run(main())import { MCPAdapter } from '@langchain/mcp-adapters';
const adapter = new MCPAdapter({
servers: {
millionshort: {
url: 'https://mcp.millionshort.com/mcp',
headers: { Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}` },
},
},
});
try {
const tools = await adapter.listTools();
console.log(tools.map((tool) => tool.name)); // millionshort_search, millionshort_get_domain_info, millionshort_list_sources, ...
} finally {
await adapter.close();
}The TypeScript adapter puts the server's name in front of each tool's name.
3Give the tools to an agent
Pass the tools to create_agent with a system prompt that says when to search. LangChain agents have no web search of their own, so there is nothing to turn off.
import asyncio
import os
from fastmcp.client import Client
from langchain.agents import create_agent
from langchain.mcp import MCPAdapter
async def main():
async with MCPAdapter(Client("https://mcp.millionshort.com/mcp", auth=os.environ["MILLIONSHORT_API_KEY"])) as adapter:
tools = await adapter.list_tools()
agent = create_agent(
"claude-sonnet-5",
tools,
system_prompt="Use the MillionShort search tool for anything recent or niche, and cite the URLs.",
)
question = "Find independent blogs about home espresso, without the 1,000 most popular sites."
result = await agent.ainvoke({"messages": [{"role": "user", "content": question}]}, {"recursion_limit": 10})
print(result["messages"][-1].content)
asyncio.run(main())import { MCPAdapter } from '@langchain/mcp-adapters';
import { createAgent } from 'langchain';
const adapter = new MCPAdapter({
servers: {
millionshort: { url: 'https://mcp.millionshort.com/mcp', headers: { Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}` } },
},
});
try {
const agent = createAgent({
model: 'claude-sonnet-5',
tools: await adapter.listTools(),
systemPrompt: 'Use the MillionShort search tool for anything recent or niche, and cite the URLs.',
});
const result = await agent.invoke(
{ messages: [{ role: 'user', content: 'Find independent blogs about home espresso, without the 1,000 most popular sites.' }] },
{ recursionLimit: 10 },
);
console.log(result.messages.at(-1)?.text);
} finally {
await adapter.close();
}The recursion limit caps the agent's steps. 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
Step 2 lists the tools with no model involved: you should see every tool of the server (fewer without a key). After a run of step 3, result["messages"] (result.messages) holds the model's tool calls; one of them should be to search, and the answer should cite pages.
Without MCP: a function tool
A function with LangChain's tool decorator (or tool() in TypeScript) calls POST /v1/search.
import json
import os
import urllib.request
from langchain.agents import create_agent
from langchain.tools import tool
@tool
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])
agent = create_agent("claude-sonnet-5", [millionshort_search])
result = agent.invoke({"messages": [{"role": "user", "content": "Find independent blogs about home espresso."}]})
print(result["messages"][-1].content)import { createAgent, tool } from 'langchain';
import { z } from 'zod';
const millionshortSearch = tool(
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 JSON.stringify(data.results.map(({ title, url, snippet }) => ({ title, url, snippet })));
},
{
name: 'millionshort_search',
description: 'Search the web with MillionShort. remove_top_sites leaves out the N most popular sites.',
schema: z.object({ query: z.string(), remove_top_sites: z.number().int().default(1000) }),
},
);
const agent = createAgent({ model: 'claude-sonnet-5', tools: [millionshortSearch] });
const result = await agent.invoke({ messages: [{ role: 'user', content: 'Find independent blogs about home espresso.' }] });
console.log(result.messages.at(-1)?.text);MCP configuration
The same address for every client: https://mcp.millionshort.com/mcp, streamable HTTP. Both adapters pick streamable HTTP for an https address, so there is no transport to set.
| 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 auth or 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.
The recursion limit of a run (recursion_limit, recursionLimit) 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 |
Python cannot import langchain.mcp | LangChain is older than 1.4, or was installed without the mcp extra | pip install -U "langchain[mcp]" |
MCPAdapter is not exported in TypeScript | @langchain/mcp-adapters 1.x is installed | Install @langchain/mcp-adapters@^2.0.0 |
| The run stops with a recursion limit message | The agent reached its step limit | Raise the limit, or ask for fewer results per search |
Coming soon: the packages
Coming soon. MillionShort's own LangChain packages are built and tested, and are not on a package registry yet. Their names are placeholders until they are published, and may change. Until then, use the MCP adapter in steps 1 to 4, or the function tool above.
The packages are three LangChain tools that call the public API, with the same fields and limits as the API, returning a reduced result made for a model to read.
| Tool name | What it does | Endpoint |
|---|---|---|
millionshort_search | Search one or more sources | POST /v1/search |
millionshort_get_domain_info | Popularity and risk for up to 25 sites | POST /v1/domain |
millionshort_list_sources | The sources, page types and topics search accepts | GET /v1/sources |
Python: langchain-millionshort
Package (placeholder name): langchain-millionshort. Python 3.10 or later.
Give all three tools to an agent:
from langgraph.prebuilt import create_react_agent
from langchain_millionshort import millionshort_tools
def build_agent(model):
"""`model` is any LangChain chat model that supports tools."""
return create_react_agent(model, millionshort_tools())Or call one tool directly, which is also the quickest way to see what a model will be given:
import json
from langchain_millionshort import MillionShortSearch
search = MillionShortSearch() # reads MILLIONSHORT_API_KEY
answer = json.loads(
search.invoke({"query": "restoring a cast iron skillet", "remove_top_sites": 1000, "num_results": 3})
)
for hit in answer["results"]:
print(hit["position"], hit["title"], hit["url"])| Name | What it is |
|---|---|
millionshort_tools(client=None) | All three tools, as a list |
MillionShortSearch, MillionShortDomainInfo, MillionShortSources | The tools, one class each |
MillionShortClient(api_key=..., base_url=..., timeout=...) | Sets the key, the address and the timeout. Pass it as client |
MillionShortError | Raised by a failed call, with code, status, request_id and retry_after_seconds |
Each tool works with invoke and ainvoke, and returns JSON text.
TypeScript: @millionshort/langchain
Package (placeholder name): @millionshort/langchain. It needs @langchain/core.
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
import { millionshortTools } from '@millionshort/langchain';
/** `llm` is any LangChain chat model that supports tools. */
export function withSearch(llm: BaseChatModel) {
if (!llm.bindTools) throw new Error('this model does not take tools');
return llm.bindTools(millionshortTools());
}The same array goes to an agent constructor as its tools.
One tool, called directly:
import { millionshortSearch } from '@millionshort/langchain';
const search = millionshortSearch(); // reads MILLIONSHORT_API_KEY
const answer = JSON.parse(
await search.invoke({ query: 'restoring a cast iron skillet', remove_top_sites: 1000, num_results: 3 }),
);
for (const hit of answer.results) {
console.log(hit.position, hit.title, hit.url);
}| Export | What it is |
|---|---|
millionshortTools(options?) | All three tools, as an array |
millionshortSearch(options?), millionshortDomainInfo(options?), millionshortSources(options?) | One tool each |
MillionShortError | Thrown by a failed call, with code, status, requestId and retryAfterSeconds |
Options: apiKey, baseUrl, timeoutMs and fetch.
Settings and fields
Both packages read MILLIONSHORT_API_KEY (the api_key argument or apiKey option overrides it) and MILLIONSHORT_BASE_URL, the API address, by default https://api.millionshort.com. The search tool takes the fields of POST /v1/search under the same names. A search answer is reduced to what a model needs: for each result its position, title, URL, site, source, date, snippet, popularity band and risk level, then the counts of removed results, any warnings, the credits charged and the request id.
Related
- Agent tool use: when to give a model tools, and what to tell it.
- Vercel AI SDK, LlamaIndex and CrewAI.
- MCP server and Filters for agents.
- LangChain's own documentation, read on 2026-11-19: MCP (Python), MCP authentication (Python), Migrate from langchain-mcp-adapters, MCP (TypeScript), MCP authentication (TypeScript).