Skip to content

Commit 3b6243b

Browse files
committed
add langgraph server example
1 parent 69fdc37 commit 3b6243b

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,51 @@ async with MultiServerMCPClient(
138138
math_response = await agent.ainvoke({"messages": "what's (3 + 5) x 12?"})
139139
weather_response = await agent.ainvoke({"messages": "what is the weather in nyc?"})
140140
```
141+
142+
## Using with LangGraph API Server
143+
144+
> [!TIP]
145+
> Check out [this guide](https://langchain-ai.github.io/langgraph/tutorials/langgraph-platform/local-server/) on getting started with LangGraph API server.
146+
147+
If you want to run a LangGraph agent that uses MCP tools in a LangGraph API server, you can use the following setup:
148+
149+
```python
150+
# graph.py
151+
from contextlib import asynccontextmanager
152+
from langchain_mcp_adapters.client import MultiServerMCPClient
153+
from langgraph.prebuilt import create_react_agent
154+
from langchain_anthropic import ChatAnthropic
155+
156+
model = ChatAnthropic(model="claude-3-5-sonnet-latest")
157+
158+
@asynccontextmanager
159+
async def make_graph():
160+
async with MultiServerMCPClient(
161+
{
162+
"math": {
163+
"command": "python",
164+
# Make sure to update to the full absolute path to your math_server.py file
165+
"args": ["/path/to/math_server.py"],
166+
"transport": "stdio",
167+
},
168+
"weather": {
169+
# make sure you start your weather server on port 8000
170+
"url": "http://localhost:8000/sse",
171+
"transport": "sse",
172+
}
173+
}
174+
) as client:
175+
agent = create_react_agent(model, client.get_tools())
176+
yield agent
177+
```
178+
179+
In your [`langgraph.json`](https://langchain-ai.github.io/langgraph/cloud/reference/cli/#configuration-file) make sure to specify `make_graph` as your graph entrypoint:
180+
181+
```json
182+
{
183+
"dependencies": ["."],
184+
"graphs": {
185+
"agent": "./graph.py:make_graph"
186+
}
187+
}
188+
```

0 commit comments

Comments
 (0)