Day 26/30: MCP Transport Options

작성자

카테고리:

← 피드로
DEV Community · Kasi Yaswanth · 2026-08-05 개발(SW)

Kasi Yaswanth

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)

Enter fullscreen mode Exit fullscreen mode

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.

원문에서 계속 ↗

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다