Loomal

Context7 MCP server in LangChain docs lookups as agent tools.

Load Context7's documentation tools into a LangChain agent with langchain-mcp-adapters — about ten lines of Python, no config file involved.

Unlike an IDE, LangChain has no settings file for MCP — servers are declared in code. The official bridge is the langchain-mcp-adapters package, which spawns or connects to MCP servers and converts their tools into native LangChain tools your agent can call.

Context7 (Upstash, 57.1k GitHub stars) is a strong first server to wire in: it gives any code-generating agent access to current, version-specific library documentation instead of whatever the base model memorized. Here's the full setup.

What you get in a LangChain agent

Once loaded, Context7's tools sit alongside your other agent tools. When a task involves a library — generating an integration, reviewing code, answering an internal docs question — the agent can resolve the library's ID and fetch its live documentation before producing an answer. As of mid-2026 those two operations are the server's core tools; the repo at github.com/upstash/context7 is the source of truth.

This matters most for autonomous chains where no human will catch a stale API call before the code runs.

Install the adapter and declare the server

Install langchain-mcp-adapters (plus langgraph if you want the prebuilt agent). MultiServerMCPClient takes a dict of server definitions; for Context7 that's a stdio command pointing at the real npm package, @upstash/context7-mcp. Node must be available wherever this Python process runs.

agent.py
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent

client = MultiServerMCPClient({
    "context7": {
        "transport": "stdio",
        "command": "npx",
        "args": ["-y", "@upstash/context7-mcp"],
    }
})

tools = await client.get_tools()
agent = create_react_agent("anthropic:claude-sonnet-4-5", tools)

Run it and check the tool calls

Invoke the agent with a question that forces a lookup — "how do I configure auth middleware in the current version of X" — and inspect the returned messages for Context7 tool calls. If the agent answers without calling the tool, tighten the system prompt to instruct documentation lookups for library questions.

To see what tools the server exposes before writing any prompt logic, Context7's live listing on the Loomal marketplace at https://loomal.ai/marketplace/context7 shows the probed tool list.

Troubleshooting in LangChain

get_tools() is async — calling it outside an event loop raises immediately, and wrapping everything in asyncio.run() at the top level is the usual fix for scripts. If the call hangs instead, the stdio subprocess probably failed to start: confirm npx works in the same environment (a Docker image without Node is the classic failure for deployed agents).

There's no restart step here in the IDE sense — the server is spawned per client instance — but stale processes can linger if you create clients in a loop without closing them. Create one client per process and reuse it.

FAQ

How do I connect Context7 to LangChain?

Install langchain-mcp-adapters, create a MultiServerMCPClient with a stdio entry running npx -y @upstash/context7-mcp, and call get_tools() to load its tools into your agent. No config file is involved — it's all code.

Where is the MCP configuration in LangChain?

There isn't a file. Server definitions live in the dict you pass to MultiServerMCPClient, so they version with your codebase like any other Python. The only dependency is the langchain-mcp-adapters package.

The tools never load — what's wrong?

Most often the Node subprocess can't start: check that npx is installed and on PATH in the exact environment running Python, especially inside containers. Second most often, get_tools() was called without awaiting it inside a running event loop.

Does this work in JavaScript LangChain too?

Yes — LangChain.js has equivalent MCP adapter support, and the server definition is the same command and package name. The Python adapter is the more commonly documented path as of mid-2026.

More MCP servers for LangChain agents.

Find tools your agents can discover, call, and pay for.

Browse the marketplace