Skip to content

Commit 8fcd83a

Browse files
committed
feat: add examples using langgraph for stdio and sse mode
1 parent f5be8e2 commit 8fcd83a

3 files changed

Lines changed: 111 additions & 219 deletions

File tree

rust-mcp-server-syncable-cli/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ env_logger = "0.11"
3737
syncable-cli = "0.11.1"
3838
axum = { version = "0.8.4", features = ["json"] }
3939
futures = "0.3.31"
40+
bytes = "1.10.1"
4041

4142
[[bin]]
4243
name = "mcp-stdio"
@@ -46,10 +47,6 @@ path = "src/main.rs"
4647
name = "mcp-sse"
4748
path = "src/main_sse.rs"
4849

49-
[[bin]]
50-
name = "mcp-rest"
51-
path = "src/main_rest.rs"
52-
5350
[dev-dependencies]
5451
assert_cmd = "2"
5552
assert_fs = "1"

rust-mcp-server-syncable-cli/README.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,116 @@ We are planning to add **first-class support for the [LangGraph](https://github.
262262

263263
---
264264

265+
## Python LangGraph Agent Integration
266+
267+
You can use the [LangGraph](https://github.com/langchain-ai/langgraph) framework to connect to this MCP server in both stdio and SSE modes. Below are example Python scripts for each mode.
268+
269+
### Using Stdio Mode
270+
271+
This example launches the `mcp-stdio` binary and connects via stdio:
272+
273+
```python
274+
import asyncio
275+
import os
276+
from dotenv import load_dotenv
277+
from langchain_mcp_adapters.client import MultiServerMCPClient
278+
from langgraph.prebuilt import create_react_agent
279+
import openai
280+
281+
load_dotenv()
282+
openai.api_key = os.getenv("OPENAI_API_KEY")
283+
284+
async def main():
285+
client = MultiServerMCPClient({
286+
"syncable_cli": {
287+
"command": "mcp-stdio", # Ensure mcp-stdio is in your PATH
288+
"args": [],
289+
"transport": "stdio",
290+
}
291+
})
292+
293+
tools = await client.get_tools()
294+
print(f"Fetched {len(tools)} tools:")
295+
for t in tools:
296+
print(f"{t.name}")
297+
298+
agent = create_react_agent("openai:gpt-4o", tools)
299+
300+
tests = [
301+
("about_info", "Call the 'about_info' tool."),
302+
("analysis_scan", "Call 'analysis_scan' on path '../' with display 'matrix'."),
303+
("security_scan", "Call 'security_scan' on path '../'."),
304+
("dependency_scan","Call 'dependency_scan' on path '../'."),
305+
]
306+
307+
for name, prompt in tests:
308+
print(f"\n--- {name}{prompt}")
309+
resp = await agent.ainvoke({
310+
"messages": [{"role": "user", "content": prompt}]
311+
})
312+
print(resp)
313+
314+
if __name__ == "__main__":
315+
asyncio.run(main())
316+
```
317+
318+
### Using SSE Mode
319+
320+
This example connects to a running `mcp-sse` server via HTTP/SSE:
321+
322+
```python
323+
import asyncio
324+
import os
325+
from dotenv import load_dotenv
326+
from langchain_mcp_adapters.client import MultiServerMCPClient
327+
from langgraph.prebuilt import create_react_agent
328+
import openai
329+
330+
load_dotenv()
331+
openai.api_key = os.getenv("OPENAI_API_KEY")
332+
333+
async def main():
334+
client = MultiServerMCPClient({
335+
"demo": {
336+
"url": "http://127.0.0.1:8000/sse",
337+
"transport": "sse",
338+
}
339+
})
340+
341+
tools = await client.get_tools()
342+
print(f"Fetched {len(tools)} tools from MCP server:")
343+
for t in tools:
344+
print(f"{t.name}")
345+
346+
agent = create_react_agent("openai:gpt-4o", tools)
347+
348+
prompts = [
349+
("about_info", "Call the 'about_info' tool."),
350+
("analysis_scan", "Call the 'analysis_scan' tool on path '../' with display 'matrix'."),
351+
("security_scan", "Call the 'security_scan' tool on path '../'."),
352+
("dependency_scan","Call the 'dependency_scan' tool on path '../'."),
353+
]
354+
355+
for name, prompt in prompts:
356+
print(f"\n--- Invoking {name} ---")
357+
resp = await agent.ainvoke({
358+
"messages": [{"role": "user", "content": prompt}]
359+
})
360+
print(resp)
361+
362+
if __name__ == "__main__":
363+
asyncio.run(main())
364+
```
365+
366+
**Requirements:**
367+
- Install the required Python packages:
368+
```bash
369+
pip install langgraph openai python-dotenv langchain_mcp_adapters
370+
```
371+
- For stdio mode, ensure `mcp-stdio` is in your `PATH`.
372+
- For SSE mode, start the server with `mcp-sse` and connect to the correct URL.
373+
374+
---
265375

266376
## License
267377

rust-mcp-server-syncable-cli/src/main_rest.rs

Lines changed: 0 additions & 215 deletions
This file was deleted.

0 commit comments

Comments
 (0)