From 332dba6460e8ed295d8d279afacef9577ed43b86 Mon Sep 17 00:00:00 2001 From: Mason Daugherty Date: Fri, 5 Sep 2025 11:19:08 -0400 Subject: [PATCH 1/2] fix: replace `create_react_agent` with `create_agent` in examples --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4b16f81..130a173 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ from mcp import ClientSession, StdioServerParameters from mcp.client.stdio import stdio_client from langchain_mcp_adapters.tools import load_mcp_tools -from langgraph.prebuilt import create_react_agent +from langgraph.prebuilt import create_agent server_params = StdioServerParameters( command="python", @@ -74,7 +74,7 @@ async with stdio_client(server_params) as (read, write): tools = await load_mcp_tools(session) # Create and run the agent - agent = create_react_agent("openai:gpt-4.1", tools) + agent = create_agent("openai:gpt-4.1", tools) agent_response = await agent.ainvoke({"messages": "what's (3 + 5) x 12?"}) ``` @@ -111,7 +111,7 @@ python weather_server.py ```python from langchain_mcp_adapters.client import MultiServerMCPClient -from langgraph.prebuilt import create_react_agent +from langgraph.prebuilt import create_agent client = MultiServerMCPClient( { @@ -129,7 +129,7 @@ client = MultiServerMCPClient( } ) tools = await client.get_tools() -agent = create_react_agent("openai:gpt-4.1", tools) +agent = create_agent("openai:gpt-4.1", tools) math_response = await agent.ainvoke({"messages": "what's (3 + 5) x 12?"}) weather_response = await agent.ainvoke({"messages": "what is the weather in nyc?"}) ``` @@ -166,7 +166,7 @@ To use it with Python MCP SDK `streamablehttp_client`: from mcp import ClientSession from mcp.client.streamable_http import streamablehttp_client -from langgraph.prebuilt import create_react_agent +from langgraph.prebuilt import create_agent from langchain_mcp_adapters.tools import load_mcp_tools async with streamablehttp_client("http://localhost:3000/mcp/") as (read, write, _): @@ -176,7 +176,7 @@ async with streamablehttp_client("http://localhost:3000/mcp/") as (read, write, # Get tools tools = await load_mcp_tools(session) - agent = create_react_agent("openai:gpt-4.1", tools) + agent = create_agent("openai:gpt-4.1", tools) math_response = await agent.ainvoke({"messages": "what's (3 + 5) x 12?"}) ``` @@ -185,7 +185,7 @@ Use it with `MultiServerMCPClient`: ```python # Use server from examples/servers/streamable-http-stateless/ from langchain_mcp_adapters.client import MultiServerMCPClient -from langgraph.prebuilt import create_react_agent +from langgraph.prebuilt import create_agent client = MultiServerMCPClient( { @@ -196,7 +196,7 @@ client = MultiServerMCPClient( } ) tools = await client.get_tools() -agent = create_react_agent("openai:gpt-4.1", tools) +agent = create_agent("openai:gpt-4.1", tools) math_response = await agent.ainvoke({"messages": "what's (3 + 5) x 12?"}) ``` @@ -211,7 +211,7 @@ When connecting to MCP servers, you can include custom headers (e.g., for authen ```python from langchain_mcp_adapters.client import MultiServerMCPClient -from langgraph.prebuilt import create_react_agent +from langgraph.prebuilt import create_agent client = MultiServerMCPClient( { @@ -226,7 +226,7 @@ client = MultiServerMCPClient( } ) tools = await client.get_tools() -agent = create_react_agent("openai:gpt-4.1", tools) +agent = create_agent("openai:gpt-4.1", tools) response = await agent.ainvoke({"messages": "what is the weather in nyc?"}) ``` @@ -289,7 +289,7 @@ If you want to run a LangGraph agent that uses MCP tools in a LangGraph API serv # graph.py from contextlib import asynccontextmanager from langchain_mcp_adapters.client import MultiServerMCPClient -from langgraph.prebuilt import create_react_agent +from langgraph.prebuilt import create_agent async def make_graph(): client = MultiServerMCPClient( @@ -308,7 +308,7 @@ async def make_graph(): } ) tools = await client.get_tools() - agent = create_react_agent("openai:gpt-4.1", tools) + agent = create_agent("openai:gpt-4.1", tools) return agent ``` From 14f8e82bf050d8c7ebbe5a405b64e97b654579d1 Mon Sep 17 00:00:00 2001 From: Mason Daugherty Date: Fri, 5 Sep 2025 15:24:39 -0400 Subject: [PATCH 2/2] fix: update import statements to use `create_agent` from `langchain.agents` --- README.md | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 130a173..a85a21d 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ from mcp import ClientSession, StdioServerParameters from mcp.client.stdio import stdio_client from langchain_mcp_adapters.tools import load_mcp_tools -from langgraph.prebuilt import create_agent +from langchain.agents import create_agent server_params = StdioServerParameters( command="python", @@ -111,7 +111,7 @@ python weather_server.py ```python from langchain_mcp_adapters.client import MultiServerMCPClient -from langgraph.prebuilt import create_agent +from langchain.agents import create_agent client = MultiServerMCPClient( { @@ -137,12 +137,12 @@ weather_response = await agent.ainvoke({"messages": "what is the weather in nyc? > [!note] > Example above will start a new MCP `ClientSession` for each tool invocation. If you would like to explicitly start a session for a given server, you can do: > -> ```python -> from langchain_mcp_adapters.tools import load_mcp_tools +> ```python +> from langchain_mcp_adapters.tools import load_mcp_tools > -> client = MultiServerMCPClient({...}) -> async with client.session("math") as session: -> tools = await load_mcp_tools(session) +> client = MultiServerMCPClient({...}) +> async with client.session("math") as session: +> tools = await load_mcp_tools(session) > ``` ## Streamable HTTP @@ -166,7 +166,7 @@ To use it with Python MCP SDK `streamablehttp_client`: from mcp import ClientSession from mcp.client.streamable_http import streamablehttp_client -from langgraph.prebuilt import create_agent +from langchain.agents import create_agent from langchain_mcp_adapters.tools import load_mcp_tools async with streamablehttp_client("http://localhost:3000/mcp/") as (read, write, _): @@ -185,7 +185,7 @@ Use it with `MultiServerMCPClient`: ```python # Use server from examples/servers/streamable-http-stateless/ from langchain_mcp_adapters.client import MultiServerMCPClient -from langgraph.prebuilt import create_agent +from langchain.agents import create_agent client = MultiServerMCPClient( { @@ -204,14 +204,14 @@ math_response = await agent.ainvoke({"messages": "what's (3 + 5) x 12?"}) When connecting to MCP servers, you can include custom headers (e.g., for authentication or tracing) using the `headers` field in the connection configuration. This is supported for the following transports: -* `sse` -* `streamable_http` +- `sse` +- `streamable_http` ### Example: passing headers with `MultiServerMCPClient` ```python from langchain_mcp_adapters.client import MultiServerMCPClient -from langgraph.prebuilt import create_agent +from langchain.agents import create_agent client = MultiServerMCPClient( { @@ -232,7 +232,6 @@ response = await agent.ainvoke({"messages": "what is the weather in nyc?"}) > Only `sse` and `streamable_http` transports support runtime headers. These headers are passed with every HTTP request to the MCP server. - ## Using with LangGraph StateGraph ```python @@ -289,7 +288,7 @@ If you want to run a LangGraph agent that uses MCP tools in a LangGraph API serv # graph.py from contextlib import asynccontextmanager from langchain_mcp_adapters.client import MultiServerMCPClient -from langgraph.prebuilt import create_agent +from langchain.agents import create_agent async def make_graph(): client = MultiServerMCPClient(