Skip to content
Back to search

langgraph-mcp

LangGraph solution template for MCP

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/esxr--langgraph-mcp/badge.svg)](/listings/esxr--langgraph-mcp)

HTML

<a href="/listings/esxr--langgraph-mcp"><img src="/api/listings/esxr--langgraph-mcp/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

1. Create and activate a virtual environment ```bash git clone https://github.com/esxr/langgraph-mcp.git cd langgraph-mcp python3 -m venv .venv source .venv/bin/activate ```

2. Install Langgraph CLI ```bash pip install -U "langgraph-cli[inmem]" ``` Note: "inmem" extra(s) are needed to run LangGraph API server in development mode (without requiring Docker installation)

3. Install the dependencies ```bash pip install -e . ```

4. Configure environment variables ```bash cp env.example .env ```

Add your `OPENAI_API_KEY`, `GITHUB_PERSONAL_ACCESS_TOKEN` etc. to the `.env`

**Note**: We have added support for *Milvus Lite Retriever* (support file based URI). Milvus Lite won't work on Windows. For Windows you may need to use Milvus Server (Easy to start using Docker), and change the `MILVUS_DB` config to the server based URI. You may also enhance the [retriever.py](src/langgraph_mcp/retriever.py) to add retrievers for your choice of vector databases!

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 111 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # Universal Assistant built with LangGraph and Model Context Protocol (MCP)
  2. ![langgraph-mcp-openapi-usecases mp4](https://github.com/user-attachments/assets/73d44e87-e77c-4dae-a602-72261b2f6a47)
  3. [Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) is an open protocol that enables seamless integration between LLM applications and external data sources and tools. Whether you're building an AI-powered IDE, enhancing a chat interface, or creating custom AI workflows, MCP provides a standardized way to connect LLMs with the context they need. Think of MCP like a USB-C port for AI applications. Just as USB-C provides a standardized way to connect your devices to various peripherals and accessories, MCP provides a standardized way to connect AI models to different data sources and tools.
  4. [LangGraph](https://langchain-ai.github.io/langgraph/) is a framework designed to enable seamless integration of language models into complex workflows and applications. It emphasizes modularity and flexibility. Workflows are represented as graphs. Nodes correspond to actions, tools, or model queries. Edges define the flow of information between them. LangGraph provides a structured yet dynamic way to execute tasks, making it ideal for writing AI applications involving natural language understanding, automation, and decision-making.
  5. In [this earlier article](https://medium.com/@pranavdhoolia/building-and-deploying-a-virtual-assistant-with-langgraph-5c68dabd82db) we enhanced LangGraph's retrieval agent template to develop and deploy an AI solution.
  6. In this project, we combine LangGraph with MCP to build our own Universal Assistant. For our universal assistant we implement a multi-agent pattern as follows:
  7. ![Basic assistant flow](media/assistant-flow.excalidraw.png)
  8. Assistant receives the user message and decides the agent to use. The agent node decides the right tool to use, and calls the tool on the MCP server. Since all our agents are based on MCP, a single MCP-Agent node is sufficient for LLM based orchestraion, and another single node is sufficient to work with MCP servers to invoke their tools.
  9. ## Development Setup
  10. 1. Create and activate a virtual environment
  11. ```bash
  12. git clone https://github.com/esxr/langgraph-mcp.git
  13. cd langgraph-mcp
  14. python3 -m venv .venv
  15. source .venv/bin/activate
  16. ```
  17. 2. Install Langgraph CLI
  18. ```bash
  19. pip install -U "langgraph-cli[inmem]"
  20. ```
  21. Note: "inmem" extra(s) are needed to run LangGraph API server in development mode (without requiring Docker installation)
  22. 3. Install the dependencies
  23. ```bash
  24. pip install -e .
  25. ```
  26. 4. Configure environment variables
  27. ```bash
  28. cp env.example .env
  29. ```
  30. Add your `OPENAI_API_KEY`, `GITHUB_PERSONAL_ACCESS_TOKEN` etc. to the `.env`
  31. **Note**: We have added support for *Milvus Lite Retriever* (support file based URI). Milvus Lite won't work on Windows. For Windows you may need to use Milvus Server (Easy to start using Docker), and change the `MILVUS_DB` config to the server based URI. You may also enhance the [retriever.py](src/langgraph_mcp/retriever.py) to add retrievers for your choice of vector databases!
  32. ## Implementation Details
  33. There are 3 main parts to our implementation:
  34. 1. Building the Router
  35. 2. The Assistant
  36. 3. A generic MCP wrapper
  37. ### Building the Router
  38. Our graph to build the router is implemented in [`build_router_graph.py`](src/langgraph_mcp/build_router_graph.py). It collects routing information based on tools, prompts, and resources offered by each MCP server using our [`mcp_wrapper.py`](src/langgraph_mcp/mcp_wrapper.py). It indexes this routing information for each server in a vector database.
  39. <!--
  40. ```mermaid
  41. sequenceDiagram
  42. participant G as Build-Router<br/>Graph
  43. participant MW as MCP Wrapper
  44. participant MS as MCP Servers
  45. participant V as Vector Index
  46. loop for all mcp-servers in config
  47. G ->> MW: Get Routing Information (server-config)
  48. MW ->> MS: list_tools
  49. MS --) MW: tools
  50. MW ->> MS: list_resources
  51. MS --) MW: resources
  52. MW ->> MS: list_prompts
  53. MS --) MW: prompts
  54. MW --) G: routing_information 𝒇(tools, resources, prompts)
  55. end
  56. G ->> V: Build Vector Index (list(Document(page_content=routing_information, metadata{id: mcp_server_name})))
  57. ```
  58. -->
  59. ![Build Router Sequence Diagram](media/build-router-sequence.excalidraw.png)
  60. ### The Assistant
  61. The assistant graph is implemented in [`assistant_graph.py`](src/langgraph_mcp/assistant_graph.py). The following animation describes the role of various nodes and the flow of control thru it, with the help of an example
  62. ![Assistant workflow explained with example](media/langgraph-assistant-mcp.gif)
  63. ### A Generic MCP Wrapper
  64. [`mcp_wrapper.py`](src/langgraph_mcp/mcp_wrapper.py) employs a Strategy Pattern using an abstract base class (`MCPSessionFunction`) to define a common interface for executing various operations on MCP servers. The pattern includes:
  65. 1. Abstract Interface:
  66. - `MCPSessionFunction` defines an async `__call__` method as a contract for all session functions.
  67. 2. Concrete Implementations:
  68. - `RoutingDescription` class implements fetching routing information based on tools, prompts, and resources.
  69. - `GetTools` class implements fetching tools for the MCP server and transforming them to the format consumable by LangGraph.
  70. - `RunTool` class implements invoking a tool on MCP server and returning its output.
  71. 3. Processor Function:
  72. - `apply` serves as a unified executor. It:
  73. - Initializes a session using `stdio_client` from `mcp` library.
  74. - Delegates the actual operation to the provided `MCPSessionFunction` instance via `await fn(server_name, session)`.
  75. 4. Extensibility:
  76. - New operations can be added by subclassing `MCPSessionFunction` without modifying the cor e processor logic. for e.g. we should be able to add support for getting tools and executing tools using this pattern.
  77. ## A Demonstration!
  78. Here's an end to end video!
  79. https://github.com/user-attachments/assets/cf5b9932-33a0-4627-98ca-022979bfb2e7

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.