LangChain MCP search tutorial / 2026
How to Add Web Search to a LangChain Agent with MCP in 2026
LangChain’s official MCP adapters convert remote server actions into standard LangChain tools. A stateless client is a sensible default for Webstractor because each search call is independently cacheable and the useful state belongs in the agent conversation or graph.
Quick answer
Load Webstractor with langchain-mcp-adapters.
Configure MultiServerMCPClient with transport=http and the hosted endpoint, await get_tools(), and pass the resulting tools to create_agent. Add a prompt rule that uses search_web for discovery and retains returned URLs.
client = MultiServerMCPClient({
"webstractor": {
"transport": "http",
"url": "https://webstractor.com/mcp",
}
})Before you begin
What you need
- Python 3.10 or newer
- A LangChain project with a tool-capable chat model
- langchain-mcp-adapters installed
- An async application entry point
Step-by-step setup
Connect Webstractor to LangChain
Install the official MCP adapter
Add the adapter beside the LangChain packages and the model integration your application uses.
uv add langchain langchain-mcp-adaptersConfigure Streamable HTTP
LangChain calls the transport http; its documentation notes that this is Streamable HTTP.
from langchain_mcp_adapters.client import MultiServerMCPClient
client = MultiServerMCPClient({
"webstractor": {
"transport": "http",
"url": "https://webstractor.com/mcp",
}
})Load tools and build the agent
Filter the tool list when this agent should only discover sources. Keeping the source URL requirement in the system prompt improves answer reviewability.
from langchain.agents import create_agent
all_tools = await client.get_tools()
search_tools = [tool for tool in all_tools if tool.name.endswith("search_web")]
agent = create_agent(
"anthropic:claude-sonnet-4-6",
search_tools,
system_prompt=(
"Use search_web for public source discovery. "
"Cite returned URLs and do not treat snippets as complete evidence."
),
)Invoke and inspect tool messages
Run a concrete query and retain tool messages in traces or tests.
result = await agent.ainvoke({
"messages": [{
"role": "user",
"content": "Find 5 sources explaining the WebAssembly component model. Include URLs.",
}]
})
print(result["messages"][-1].content)LangGraph pattern
Put search in a dedicated discovery node
For deterministic systems, use a graph node whose only job is to produce candidate sources, followed by a selection node and an extraction node. The state can store URLs separately from synthesized text.
This makes it possible to test query formation, result count, and source selection independently from the final model response.
Structured content
Decide what reaches model context
LangChain’s MCP adapters can preserve structuredContent in ToolMessage artifacts. For ordinary web search, readable content may be sufficient; for programmatic ranking or UI rendering, inspect the artifact instead of reparsing prose.
Do not append large structured values to the conversation automatically unless the model needs them.
Troubleshooting
Handle async and connection lifecycle correctly
get_tools() is async. Call it from an async startup path or inside your framework’s lifespan rather than at arbitrary module import time in an incompatible runtime.
A 404 usually means the URL is wrong; an empty filtered list usually means your tool-name predicate does not match. Print discovered names in development and keep production logs free of credentials.
Available data
What you can extract
- LangChain-compatible MCP tools
- Ordered public search feeds
- Markdown or schema-v1 JSON
- Source URLs suitable for final-answer citations
AI workflows
Where normalized data helps
- LangChain research assistants
- LangGraph discovery nodes
- Public-source fallback for RAG
- Site-restricted documentation lookup
Boundaries
Public data only
- MultiServerMCPClient is stateless by default and creates a fresh session per invocation.
- Search results do not replace reading the selected source.
- Retries should be bounded and reserved for transient transport failures.
webstractor.com does not bypass CAPTCHAs, login walls, paywalls, access controls, or regional restrictions. Review the source’s terms and applicable law before collecting or reusing data.
Common questions
LangChain and Webstractor FAQ
Should I keep a persistent MCP session?
Not for ordinary Webstractor calls. The default stateless client is appropriate because each tool invocation is independent.
Can I use LangGraph?
Yes. MCP tools are LangChain-compatible tools and can be passed to LangGraph prebuilt agents or used in explicit graph nodes.
Why filter the tools?
A smaller tool surface reduces selection ambiguity and makes evaluation easier for a search-only agent.
Ready to try it?