I recently spent hours debugging a support bot built with LangGraph and MCP, only to realize that the issue wasn't with the model or the graph, but with the transport mechanism. The bot was designed to have a conversation with a user, and it worked perfectly when run locally, but when deployed to a remote server, it would frequently lose context and respond with irrelevant answers. After digging through the logs, I discovered that the problem was due to the way I was using the MCP transport.
By default, MCP uses a local stdio transport, which is great for development and testing, but not suitable for remote deployment. The local stdio transport uses the standard input and output streams to send and receive messages, which works fine when the client and server are running on the same machine. However, when the client and server are running on different machines, a remote transport mechanism is needed.
That's where the Streamable HTTP transport comes in. This transport mechanism allows MCP to send and receive messages over HTTP, making it possible to deploy the support bot to a remote server. To switch to the Streamable HTTP transport, I needed to modify the code to use the mcp.transport.http module instead of the default mcp.transport.stdio module.
Here's an example of how to use the Streamable HTTP transport with LangGraph and MCP:
import langgraph
from mcp import Client
from mcp.transport.http import HttpTransport
# Create a LangGraph model
model = langgraph.Model()
# Create an MCP client with the Streamable HTTP transport
transport = HttpTransport("https://example.com/mcp")
client = Client(transport)
# Create a state graph with a single node
graph = langgraph.StateGraph()
node = graph.add_node("start")
# Add a conditional edge to the node
graph.add_conditional_edges(node, [
("input", "hello", "output", "Hello!"),
])
# Compile the graph and deploy it to the remote server
compiled_graph = graph.compile()
client.deploy(compiled_graph)
# Send a message to the remote server and print the response
response = client.send("hello")
print(response)
In this example, we create a LangGraph model and an MCP client with the Streamable HTTP transport. We then create a state graph with a single node and add a conditional edge to the node. Finally, we compile the graph, deploy it to the remote server, and send a message to the server to test the deployment.
One practical gotcha to watch out for when using the Streamable HTTP transport is that it requires a reliable connection between the client and server. If the connection is lost, the client will need to reconnect to the server before it can send or receive messages. To handle this, you can use a retry mechanism, such as the tenacity library in Python, to automatically reconnect to the server if the connection is lost.
As we continue to build more complex agentic AI systems with LangGraph and MCP, we'll need to consider other factors that can impact the performance and reliability of our systems, such as scalability and fault tolerance. Tomorrow, we'll explore some of the strategies for building more robust and resilient agentic AI systems.
Top comments (1)
Useful distinction. One caveat: switching transport does not itself preserve conversational state. On reconnect, make the session contract explicit: which state lives client-side versus server-side, how a session is resumed, and whether requests can be replayed safely. I’d test dropped connections at three points—before acceptance, after execution but before response, and mid-stream—using operation IDs plus typed completion states. Blind retries can otherwise duplicate a side effect or attach a fresh HTTP session to stale graph state. Transport gets bytes across the boundary; resumability and idempotency keep the conversation correct.