How to Connect LangGraph to MewCP
LangGraph runs MCP tools through LangChain's MCP adapter. The adapter turns MewCP's tools into LangChain tools, and a ToolNode in your graph runs them. Your graph then reaches every app connected to its toolset.
Before you start
-
Python 3.10 or newer
-
A toolset and its key. See Choose a toolset
-
Your environment set as in Set your environment:
Code
Install
Code
langchain.mcp needs langchain[mcp] 1.4.0 or newer. The examples use an Anthropic model; any chat model LangChain supports works the same way.
Connect
Code
auth= sends the key as Authorization: Bearer <key>. The tools stay usable after the async with block ends: each call opens its own connection to MewCP.
The loop between agent and tools lets the model run search, get_schema and call_tool one after another in a single answer.
Serve your users
With a project toolset, send x-mewcp-enduser-id on every request, set to the user the graph is acting for. Build the client per user with a transport that carries the header:
Code
Build the graph from tools_for(user_id) for each user, as in Connect. On a LangGraph server, do it in your graph factory, where the run's authenticated user is available as runtime.user.identity.
Use the same ID you pass as externalUserId when the user connects their accounts through the MewCP Auth API. If they have not connected the app a tool needs, the tool result carries a link for them to connect it, and the model can pass it on.
Check it works
Code
You should see four tools: search, get_schema, list_accounts and call_tool. That is expected. See What your agent sees.
In production
- Build per run on a LangGraph server. Build the graph inside your graph factory, so each run gets its own client and, with a project toolset, its own user.
- Pass the tool list once. Give the same
toolslist to bothbind_toolsandToolNode, so the model can only call tools the node can run.
Troubleshooting
ModuleNotFoundError: No module named 'langchain.mcp'
Install the MCP extra at 1.4.0 or newer: pip install "langchain[mcp]>=1.4.0". Older guides use the separate langchain-mcp-adapters package and MultiServerMCPClient. See LangChain's migration guide.
A LangChainBetaWarning is printed on import
langchain.mcp is in beta and warns once per process. The API may change between LangChain releases, so pin the version you test with.
Listing tools fails with 401 or 403
MewCP rejected the key.
- Check
MEWCP_API_KEYis set where the code runs and holds the whole key. - Check the key matches the toolset in
MEWCP_MCP_URL: your API Key for the personal toolset, the project's key for a project toolset. - A
403that says the billing period is not active means your MewCP plan needs renewing in the dashboard.
A long task stops with GraphRecursionError
The graph hit its step limit before the model finished. Raise it for that run: await graph.ainvoke(inputs, {"recursion_limit": 50}).
Last checked against LangChain's and LangGraph's documentation on 13 October 2026.