Guide

LangChain MCP Servers: MCPAdapter Setup and Migration

To use MCP servers from LangChain, install langchain[mcp] and pass a server URL to the beta MCPAdapter class. It returns the server's tools, which you hand to create_agent. The older langchain-mcp-adapters package still works, but its own README now calls it no longer actively maintained.

Step by step

  1. Install langchain[mcp]. Run pip install "langchain[mcp]". It requires langchain>=1.4.0 and adds the beta langchain.mcp namespace.
  2. Get an MCPifex API key. Register at portal.mcpifex.com, create an instance from the marketplace, and copy its API key. It starts with mcpx_.
  3. Build the server config. Build an mcpServers config object with one mcpifex entry. Use the URL from the setup example, with your instance key in the path.
  4. Open MCPAdapter and list tools. Run async with MCPAdapter(config) as adapter: tools = await adapter.list_tools() to discover every tool enabled for that key.
  5. Pass the tools to an agent. Call create_agent(model, tools) so the LangChain agent can call the MCP server's tools directly.
  6. Verify with curl if something fails. If something fails, run the raw handshake from the MCPifex quickstart to test authentication and discovery. Then call a harmless enabled tool before diagnosing framework errors.

Connect an agent in a few lines

Say you want a LangChain agent to call a hosted MCP server. Install the package first. It needs langchain>=1.4.0:

pip install "langchain[mcp]"   # requires langchain>=1.4.0

Then build the config, open the adapter and pass the tools to an agent. A single remote server can be a plain URL string. Several servers go in an mcpServers dict:

import asyncio
from langchain.agents import create_agent
from langchain.mcp import MCPAdapter

async def main():
    config = {"mcpServers": {"mcpifex": {"url": "https://mcpifex.com/mcp/<YOUR_MCPX_KEY>"}}}

    async with MCPAdapter(config) as adapter:
        tools = await adapter.list_tools()
        agent = create_agent("claude-sonnet-5", tools)
        result = await agent.ainvoke({"messages": [{"role": "user", "content": "..."}]})

asyncio.run(main())

The key sits in the URL path, so treat that URL like a password. The model provider you pick also needs its own integration installed and its own credentials. MCPAdapter is beta, so importing from langchain.mcp raises a one-time LangChainBetaWarning and the API can still change. The LangChain MCP docs cover it in full.

Send the key as a header instead

To keep the key out of the URL, pass a fastmcp.client.Client to MCPAdapter rather than a config dict:

import asyncio
from fastmcp.client import Client
from langchain.mcp import MCPAdapter

async def main():
    client = Client("https://mcpifex.com/mcp", auth="<YOUR_MCPX_KEY>")
    async with MCPAdapter(client) as adapter:
        tools = await adapter.list_tools()

asyncio.run(main())

MCPifex accepts the same key in a bearer header or in the URL path. See API keys and authentication for both forms.

Migrating from langchain-mcp-adapters

Most older tutorials use the standalone langchain-mcp-adapters package and its MultiServerMCPClient. Its GitHub README says development moved to the built-in langchain.mcp namespace. As of September 2026 it is still on PyPI (0.3.2, dated 2026-08-06) and still installs, so existing code keeps running. New code should start with MCPAdapter.

If you maintain code that uses the old package, this is the shape it takes against a hosted gateway:

pip install langchain-mcp-adapters
import asyncio
from langchain_mcp_adapters.client import MultiServerMCPClient

async def main():
    client = MultiServerMCPClient({
        "mcpifex": {
            "transport": "http",
            "url": "https://mcpifex.com/mcp",
            "headers": {"Authorization": "Bearer <YOUR_MCPX_KEY>"},
        }
    })
    tools = await client.get_tools()

asyncio.run(main())

To move to the new class, change these things:

  • Wrap the old flat server map in an mcpServers object.
  • Remove the per-entry transport key. MCPAdapter infers it.
  • Move custom authentication onto a fastmcp.client.Client, as above.
  • Replace get_tools() with list_tools().

Both packages support stdio for a local subprocess and http (also called streamable_http) for a remote server. The old package also still accepts sse. Check LangChain's migration guide for behavior changes.

The same pattern in the OpenAI Agents SDK

The URL and header aren't LangChain-specific. The OpenAI Agents SDK reaches the same endpoint with its MCPServerStreamableHttp class:

import asyncio
from agents import Agent, Runner
from agents.mcp import MCPServerStreamableHttp

async def main():
    async with MCPServerStreamableHttp(
        name="mcpifex",
        params={
            "url": "https://mcpifex.com/mcp",
            "headers": {"Authorization": "Bearer <YOUR_MCPX_KEY>"},
        },
    ) as server:
        agent = Agent(name="Assistant", mcp_servers=[server])
        result = await Runner.run(agent, "...")

asyncio.run(main())

Which MCP version does the client speak?

Sharing the Streamable HTTP transport name doesn't guarantee the protocol versions line up. The 2026-07-28 revision of the spec removed the initialization handshake and the session header. MCPifex's gateway uses the handshake-based MCP transport, and clients on the current revision interoperate through the spec's backward-compatibility rules.

So check which protocol revisions your client library supports, not only its transport options. After upgrading a dependency, confirm discovery and one harmless call still work.

If it won't connect

  • 401. The key is missing, mistyped or revoked. MCPifex keys start with mcpx_.
  • An empty tool list. Nothing is enabled for that key's instance. Check the enabled tools in the portal.
  • A tool call is refused. The gateway rejects disabled tools and tools outside the server's catalog. Enable the tool in the portal if you want it.
  • Import errors on langchain.mcp. You need langchain>=1.4.0 and the mcp extra.
  • You can't tell whether LangChain or the key is at fault. Run the raw handshake in the quickstart. A tool list there proves the key and endpoint work. It doesn't prove a later tool call, database credential or model request will. Then call a harmless enabled tool from your code and compare URL, auth and timeouts with the curl run.

Use hosted MCP servers with LangChain

MCPifex hosts MCP servers behind one gateway URL. You create an instance of a server, save its config, choose the enabled tools and generate a key at the portal. For example, a PostgreSQL instance works well with a database role limited to the tables the agent needs.

Discovery returns only the tools enabled for the instance your key resolves to. Read instances and tools for the model.

Frequently asked questions

Is langchain-mcp-adapters deprecated?
Its GitHub README says the repository is no longer actively maintained and points to langchain[mcp] instead. It still installs from PyPI and works, but new code should use the langchain.mcp namespace.
Does MCPAdapter replace MultiServerMCPClient one-to-one?
Not exactly. Wrap the old flat server map in an mcpServers object, remove the per-entry transport key, and move custom authentication onto a FastMCP client. Tool discovery also changes from get_tools() to list_tools(). Read LangChain's migration guide for behavior changes.
Can I use a Bearer token with MCPAdapter instead of a key in the URL?
Yes. Pass a fastmcp.client.Client(url, auth="") to MCPAdapter instead of a config dict. The token is sent as an Authorization header, so the key stays out of the URL.
Does this work the same way outside LangChain?
Yes. The pattern is not tied to one framework. The OpenAI Agents SDK's MCPServerStreamableHttp class points at the same Streamable HTTP URL with the same bearer header.

Sources

  1. GitHub: langchain-ai/langchain-mcp-adapters
  2. MCP, LangChain docs
  3. Migrate from langchain-mcp-adapters, LangChain docs
  4. Transports, Model Context Protocol specification
  5. MCP servers, OpenAI Agents SDK docs
  6. langchain-mcp-adapters, PyPI